0

我以一种非常简单的方式使用 symfony 6 和 api-platform 2.6.8 开始了一个新项目,并添加了一些实体进行测试。

symfony new testapi
cd testapi
composer req api
composer req symfony/apache-pack
composer req --dev symfony/maker-bundle
composer req --dev test
composer req --dev symfony/browser-kit symfony/http-client
composer req --dev symfony/profiler-pack

我创建了一个名为 feriado 的实体,然后我用 curl 和 swagger 手动测试,没有任何错误。
在此处输入图像描述

问题是当我执行测试时似乎执行 phpunit 时,没有可用的路由。
可能是测试环境的问题?
我在这一点上迷路了

<?php
namespace App\Tests\functional;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;

class FeriadoTest extends ApiTestCase
{

    public function testFeriado() : void
    {
        $response = self::createClient()->request(
            'GET',
            'http://localhost/qapip/api/feriados', [
            'headers' => [
                'accept' => 'application/json'
                ],
            ]);

            $this->assertResponseStatusCodeSame(200);
    }

}

无论如何,这就是答案

{
  "type": "https://tools.ietf.org/html/rfc2616#section-10",
  "title": "Anerroroccurred",
  "status": 404,
  "detail": "No route found for \"GET http://localhost/qapip/api/feriado\"",
  "class": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/http-kernel/EventListener/RouterListener.php",
      "line": 130,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel\\EventListener",
      "short_class": "RouterListener",
      "class": "Symfony\\Component\\HttpKernel\\EventListener\\RouterListener",
      "type": "->",
      "function": "onKernelRequest",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/event-dispatcher/Debug/WrappedListener.php",
      "line": 111,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\EventDispatcher\\Debug",
      "short_class": "WrappedListener",
      "class": "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener",
      "type": "->",
      "function": "__invoke",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/event-dispatcher/EventDispatcher.php",
      "line": 230,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\EventDispatcher",
      "short_class": "EventDispatcher",
      "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
      "type": "->",
      "function": "callListeners",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/event-dispatcher/EventDispatcher.php",
      "line": 59,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\EventDispatcher",
      "short_class": "EventDispatcher",
      "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
      "type": "->",
      "function": "dispatch",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php",
      "line": 152,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\EventDispatcher\\Debug",
      "short_class": "TraceableEventDispatcher",
      "class": "Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher",
      "type": "->",
      "function": "dispatch",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 128,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel",
      "short_class": "HttpKernel",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
      "type": "->",
      "function": "handleRaw",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 74,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel",
      "short_class": "HttpKernel",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
      "type": "->",
      "function": "handle",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/http-kernel/Kernel.php",
      "line": 202,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel",
      "short_class": "Kernel",
      "class": "Symfony\\Component\\HttpKernel\\Kernel",
      "type": "->",
      "function": "handle",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/http-kernel/HttpKernelBrowser.php",
      "line": 65,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel",
      "short_class": "HttpKernelBrowser",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernelBrowser",
      "type": "->",
      "function": "doRequest",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/framework-bundle/KernelBrowser.php",
      "line": 171,
      "args": []
    },
    {
      "namespace": "Symfony\\Bundle\\FrameworkBundle",
      "short_class": "KernelBrowser",
      "class": "Symfony\\Bundle\\FrameworkBundle\\KernelBrowser",
      "type": "->",
      "function": "doRequest",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/symfony/browser-kit/AbstractBrowser.php",
      "line": 370,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\BrowserKit",
      "short_class": "AbstractBrowser",
      "class": "Symfony\\Component\\BrowserKit\\AbstractBrowser",
      "type": "->",
      "function": "request",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/api-platform/core/src/Bridge/Symfony/Bundle/Test/Client.php",
      "line": 123,
      "args": []
    },
    {
      "namespace": "ApiPlatform\\Core\\Bridge\\Symfony\\Bundle\\Test",
      "short_class": "Client",
      "class": "ApiPlatform\\Core\\Bridge\\Symfony\\Bundle\\Test\\Client",
      "type": "->",
      "function": "request",
      "file": "/home/martin/Work/qltc/symfony/qapip/tests/functional/FeriadoTest.php",
      "line": 25,
      "args": []
    },
    {
      "namespace": "App\\Tests\\functional",
      "short_class": "FeriadoTest",
      "class": "App\\Tests\\functional\\FeriadoTest",
      "type": "->",
      "function": "testprueba",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/Framework/TestCase.php",
      "line": 1545,
      "args": []
    },
    {
      "namespace": "PHPUnit\\Framework",
      "short_class": "TestCase",
      "class": "PHPUnit\\Framework\\TestCase",
      "type": "->",
      "function": "runTest",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/Framework/TestCase.php",
      "line": 1151,
      "args": []
    },
    {
      "namespace": "PHPUnit\\Framework",
      "short_class": "TestCase",
      "class": "PHPUnit\\Framework\\TestCase",
      "type": "->",
      "function": "runBare",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/Framework/TestResult.php",
      "line": 726,
      "args": []
    },
    {
      "namespace": "PHPUnit\\Framework",
      "short_class": "TestResult",
      "class": "PHPUnit\\Framework\\TestResult",
      "type": "->",
      "function": "run",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/Framework/TestCase.php",
      "line": 903,
      "args": []
    },
    {
      "namespace": "PHPUnit\\Framework",
      "short_class": "TestCase",
      "class": "PHPUnit\\Framework\\TestCase",
      "type": "->",
      "function": "run",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/Framework/TestSuite.php",
      "line": 677,
      "args": []
    },
    {
      "namespace": "PHPUnit\\Framework",
      "short_class": "TestSuite",
      "class": "PHPUnit\\Framework\\TestSuite",
      "type": "->",
      "function": "run",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/Framework/TestSuite.php",
      "line": 677,
      "args": []
    },
    {
      "namespace": "PHPUnit\\Framework",
      "short_class": "TestSuite",
      "class": "PHPUnit\\Framework\\TestSuite",
      "type": "->",
      "function": "run",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/Framework/TestSuite.php",
      "line": 677,
      "args": []
    },
    {
      "namespace": "PHPUnit\\Framework",
      "short_class": "TestSuite",
      "class": "PHPUnit\\Framework\\TestSuite",
      "type": "->",
      "function": "run",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/TextUI/TestRunner.php",
      "line": 670,
      "args": []
    },
    {
      "namespace": "PHPUnit\\TextUI",
      "short_class": "TestRunner",
      "class": "PHPUnit\\TextUI\\TestRunner",
      "type": "->",
      "function": "run",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/TextUI/Command.php",
      "line": 143,
      "args": []
    },
    {
      "namespace": "PHPUnit\\TextUI",
      "short_class": "Command",
      "class": "PHPUnit\\TextUI\\Command",
      "type": "->",
      "function": "run",
      "file": "/home/martin/Work/qltc/symfony/qapip/vendor/phpunit/phpunit/src/TextUI/Command.php",
      "line": 96,
      "args": []
    },
    {
      "namespace": "PHPUnit\\TextUI",
      "short_class": "Command",
      "class": "PHPUnit\\TextUI\\Command",
      "type": "::",
      "function": "main",
      "file": "/home/martin/Work/qltc/symfony/qapip/bin/phpunit",
      "line": 11,
      "args": []
    }
  ]
}
4

0 回答 0