Reputation: 363
I have started a new project with symfony 6 and api-platform 2.6.8, in a very simple way and I have added some entities to test.
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
I had created an entity called feriado and then I have manually tested with curl and swagger witout any errors.
The problem is when I execute a test
Seems like when phpunit is executed, no routes are available.
May be a problem of test environment?
I am lost at this point
<?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);
}
}
this is the answer no matter what
{
"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": "/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": "/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": "/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": "/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": "/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": "/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": "/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": "/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": "/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": "/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": "/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": "/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": "/tests/functional/FeriadoTest.php",
"line": 25,
"args": []
},
{
"namespace": "App\\Tests\\functional",
"short_class": "FeriadoTest",
"class": "App\\Tests\\functional\\FeriadoTest",
"type": "->",
"function": "testprueba",
"file": "/vendor/phpunit/phpunit/src/Framework/TestCase.php",
"line": 1545,
"args": []
},
{
"namespace": "PHPUnit\\Framework",
"short_class": "TestCase",
"class": "PHPUnit\\Framework\\TestCase",
"type": "->",
"function": "runTest",
"file": "/vendor/phpunit/phpunit/src/Framework/TestCase.php",
"line": 1151,
"args": []
},
{
"namespace": "PHPUnit\\Framework",
"short_class": "TestCase",
"class": "PHPUnit\\Framework\\TestCase",
"type": "->",
"function": "runBare",
"file": "/vendor/phpunit/phpunit/src/Framework/TestResult.php",
"line": 726,
"args": []
},
{
"namespace": "PHPUnit\\Framework",
"short_class": "TestResult",
"class": "PHPUnit\\Framework\\TestResult",
"type": "->",
"function": "run",
"file": "/vendor/phpunit/phpunit/src/Framework/TestCase.php",
"line": 903,
"args": []
},
{
"namespace": "PHPUnit\\Framework",
"short_class": "TestCase",
"class": "PHPUnit\\Framework\\TestCase",
"type": "->",
"function": "run",
"file": "/vendor/phpunit/phpunit/src/Framework/TestSuite.php",
"line": 677,
"args": []
},
{
"namespace": "PHPUnit\\Framework",
"short_class": "TestSuite",
"class": "PHPUnit\\Framework\\TestSuite",
"type": "->",
"function": "run",
"file": "/vendor/phpunit/phpunit/src/Framework/TestSuite.php",
"line": 677,
"args": []
},
{
"namespace": "PHPUnit\\Framework",
"short_class": "TestSuite",
"class": "PHPUnit\\Framework\\TestSuite",
"type": "->",
"function": "run",
"file": "/vendor/phpunit/phpunit/src/Framework/TestSuite.php",
"line": 677,
"args": []
},
{
"namespace": "PHPUnit\\Framework",
"short_class": "TestSuite",
"class": "PHPUnit\\Framework\\TestSuite",
"type": "->",
"function": "run",
"file": "/vendor/phpunit/phpunit/src/TextUI/TestRunner.php",
"line": 670,
"args": []
},
{
"namespace": "PHPUnit\\TextUI",
"short_class": "TestRunner",
"class": "PHPUnit\\TextUI\\TestRunner",
"type": "->",
"function": "run",
"file": "/vendor/phpunit/phpunit/src/TextUI/Command.php",
"line": 143,
"args": []
},
{
"namespace": "PHPUnit\\TextUI",
"short_class": "Command",
"class": "PHPUnit\\TextUI\\Command",
"type": "->",
"function": "run",
"file": "/vendor/phpunit/phpunit/src/TextUI/Command.php",
"line": 96,
"args": []
},
{
"namespace": "PHPUnit\\TextUI",
"short_class": "Command",
"class": "PHPUnit\\TextUI\\Command",
"type": "::",
"function": "main",
"file": "/bin/phpunit",
"line": 11,
"args": []
}
]
}
Upvotes: 1
Views: 1584
Reputation: 363
Finally I could solve it, but it took me more time and work than what I tought.
Fast anwer: Apache Configuration. (as @Ahmed Ghiloubi said in his comment)
The solution I post it's relative to ubuntu (the one I'm using right now) or debian based distros. On any other OS running apache, you will have to check how...
I have follow this guide
cd /etc/apache2/sites-available/
sudo cp example.com.conf mysite.com.conf
sudo nano mysite.com.conf
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/html/mysite
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite qapip.test
sudo a2dissite 000-default.conf
sudo systemctl restart apache2
Also I had to define a new entry in my hosts configuration
sudo nano /etc/hosts
127.0.0.1 mysite.com
After all that... php bin/phpunit
pointing the GET
request to mysite.com
is working as expected
Upvotes: 2