The WebTestCase class is a special class that is designed to run in a test environment (PHPUnit), and you cannot use it in your controller.
But you can create an HTTPKernel client as follows:
use Symfony\Component\HttpKernel\Client; ... public function testAction() { $client = new Client($this->get('kernel')); $crawler = $client->request('GET', '/category/index'); }
Please note that you can only use this client to view your Symfony application. If you want to view an external server, you will need to use another client, for example goutte.
The crawler created here is the same crawler that WebTestCase returns, so you can follow the same examples as found in the symfony testing documentation
If you need more information, here is the documentation for the crawler component and here is a class reference
source share