From 53d3066230d950aa06ac24e746217b799c801b16 Mon Sep 17 00:00:00 2001 From: hecht Date: Fri, 16 Nov 2018 08:21:29 +0100 Subject: [PATCH] Added some helper functions to the RestTestBase (use statements missing). --- tests/Controller/RestTestBase.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/Controller/RestTestBase.php b/tests/Controller/RestTestBase.php index 2a70164..16b6ee0 100644 --- a/tests/Controller/RestTestBase.php +++ b/tests/Controller/RestTestBase.php @@ -9,7 +9,27 @@ class RestTestBase extends WebTestCase /** * @var Client */ - private $client; + protected $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() + { + 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 { @@ -17,4 +37,9 @@ class RestTestBase extends WebTestCase $builder->setAcceptType($acceptType); return $builder; } + + protected function retrieveEntityManager(): EntityManagerInterface + { + return $this->client->getContainer()->get('doctrine.orm.entity_manager'); + } } \ No newline at end of file