You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
| <?php
 | |
| namespace App\Tests\Controller;
 | |
| 
 | |
| use Doctrine\ORM\EntityManagerInterface;
 | |
| use Symfony\Bundle\FrameworkBundle\Console\Application;
 | |
| use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
 | |
| use Symfony\Component\Console\Input\StringInput;
 | |
| use Symfony\Component\Console\Output\NullOutput;
 | |
| use Symfony\Bundle\FrameworkBundle\KernelBrowser;
 | |
| 
 | |
| class RestTestBase extends WebTestCase
 | |
| {
 | |
| 
 | |
|     protected KernelBrowser $client;
 | |
| 
 | |
|     protected function setUp()
 | |
|     {
 | |
|         parent::setUp();
 | |
|         $this->client = static::createClient();
 | |
|         // $this->client->disableReboot(); // uncomment when using prophecy to mock services
 | |
|         self::reloadDoctrineFixtures();
 | |
|     }
 | |
| 
 | |
|     protected function reloadDoctrineFixtures()
 | |
|     {
 | |
|         // we need our fixtures to be stateless, so remove everything and recreate to get the same
 | |
|         // index values all along the tests
 | |
|         self::runCommand('doctrine:schema:drop --force -n');
 | |
|         self::runCommand('doctrine:schema:create -n');
 | |
|         self::runCommand('doctrine:fixtures:load --purge-with-truncate -n');
 | |
|     }
 | |
| 
 | |
|     protected function runCommand($command)
 | |
|     {
 | |
|         $application = new Application($this->client->getKernel());
 | |
|         $application->setAutoExit(false);
 | |
|         return $application->run(new StringInput($command), new NullOutput());
 | |
|     }
 | |
| 
 | |
|     protected function createRequestBuilder(string $acceptType = 'application/json'): ClientRequestBuilder
 | |
|     {
 | |
|         $builder = new ClientRequestBuilder($this->client);
 | |
|         $builder->setAcceptType($acceptType);
 | |
|         return $builder;
 | |
|     }
 | |
| 
 | |
|     protected function retrieveEntityManager(): EntityManagerInterface
 | |
|     {
 | |
|         return $this->client->getContainer()->get('doctrine.orm.entity_manager');
 | |
|     }
 | |
| } |