When checking php bin/console debug:wiring
, I get the following errors:
In FileLoader.php line 168:
Class Symfony\Bundle\FrameworkBundle\Test\WebTestCase not found in /vagrant/mysymfony/app/config/services.yml (whic
h is being imported from "/vagrant/mysymfony/app/config/config.yml").
In WebTestCase.php line 17:
Class Symfony\Bundle\FrameworkBundle\Test\WebTestCase not found
In WebTestCase.php line 21:
Class Symfony\Bundle\FrameworkBundle\Test\KernelTestCase not found
In KernelTestCase.php line 24:
Class PHPUnit\Framework\TestCase not found
The error is due to the following file:
<?php
/**
* This file is part of the RestExtraBundle package [1].
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this[1] source code.
*
* @license MIT License
* [1] http://ift.tt/2E2p6HC
*/
namespace AppBundle\Test;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
/**
* @author William Durand <william.durand1@gmail.com>
*/
abstract class WebTestCase extends BaseWebTestCase
{
protected function assertJsonResponse($response, $statusCode = 200)
{
$this->assertEquals(
$statusCode, $response->getStatusCode(),
$response->getContent()
);
$this->assertTrue(
$response->headers->contains('Content-Type', 'application/json'),
$response->headers
);
}
protected function jsonRequest($verb, $endpoint, array $data = array())
{
$data = empty($data) ? null : json_encode($data);
return $this->client->request($verb, $endpoint,
array(),
array(),
array(
'HTTP_ACCEPT' => 'application/json',
'CONTENT_TYPE' => 'application/json'
),
$data
);
}
}
The file is in the following directory structure:
.
├── AppBundle.php
├── Controller
│ ├── DefaultController.php
│ └── FooController.php
└── Test
└── WebTestCase.php
And that WebTestCase
class is used in the following file:
<?php
namespace Tests\AppBundle\Controller;
use AppBundle\Test\WebTestCase;
class FooControllerTest extends WebTestCase
{
public function testFooAction()
{
$client = static::createClient();
$crawler = $client->request('GET', '/foo');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertJsonResponse($client->getResponse());
}
}
Which is in the following path inside the tests
directory:
.
└── AppBundle
└── Controller
├── DefaultControllerTest.php
└── FooControllerTest.php
The tests run without any kind of problem, and I actually discovered this error by chance. If I remove that file and any references to it from the tests then I can check debug:autowiring
without any hassle. However I can't figure out what I am missing here. I guess it has something to do with file placement or something, but I don't really know. Can you lend me a hand please?
Also, if I didn't check that command, I wouldn't have noticed these errors. In order to avoid committing code to a repository which generates this kind of errors in the future, does Symfony log these errors somewhere? Or do I have to manually check every debug
command?
Thank you in advance for your help.
Aucun commentaire:
Enregistrer un commentaire