diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index c5e3baeb..745cf16a 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -31,7 +31,6 @@ use Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Finder\Finder; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector; use Symfony\Component\HttpKernel\Kernel; @@ -149,6 +148,11 @@ class Symfony extends Framework implements DoctrineProvider, PartedModule */ public $kernel; + /** + * @var SymfonyConnector + */ + public $client; + public $config = [ 'app_path' => 'app', 'kernel_class' => 'App\Kernel', @@ -279,6 +283,11 @@ public function _getContainer(): ContainerInterface return $container; } + protected function getClient(): SymfonyConnector + { + return $this->client ?: $this->fail('Client is not initialized'); + } + /** * Attempts to guess the kernel location. * When the Kernel is located, the file is required. @@ -340,8 +349,7 @@ protected function getProfile(): ?Profile return null; } try { - /** @var Response $response */ - $response = $this->client->getResponse(); + $response = $this->getClient()->getResponse(); return $profiler->loadProfileFromResponse($response); } catch (BadMethodCallException $e) { $this->fail('You must perform a request before using this method.'); diff --git a/src/Codeception/Module/Symfony/BrowserAssertionsTrait.php b/src/Codeception/Module/Symfony/BrowserAssertionsTrait.php index b2a79180..f0c53237 100644 --- a/src/Codeception/Module/Symfony/BrowserAssertionsTrait.php +++ b/src/Codeception/Module/Symfony/BrowserAssertionsTrait.php @@ -4,8 +4,7 @@ namespace Codeception\Module\Symfony; -use Codeception\Lib\Connector\Symfony as SymfonyConnector; -use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Test\Constraint\ResponseIsSuccessful; use function sprintf; trait BrowserAssertionsTrait @@ -28,9 +27,7 @@ trait BrowserAssertionsTrait */ public function rebootClientKernel(): void { - if ($this->client instanceof SymfonyConnector) { - $this->client->rebootKernel(); - } + $this->getClient()->rebootKernel(); } /** @@ -53,7 +50,7 @@ public function seePageIsAvailable(string $url = null): void $this->amOnPage($url); $this->seeInCurrentUrl($url); } - $this->seeResponseCodeIsSuccessful(); + $this->assertThat($this->getClient()->getResponse(), new ResponseIsSuccessful()); } /** @@ -69,14 +66,13 @@ public function seePageIsAvailable(string $url = null): void */ public function seePageRedirectsTo(string $page, string $redirectsTo): void { - $this->client->followRedirects(false); + $this->getClient()->followRedirects(false); $this->amOnPage($page); - /** @var Response $response */ - $response = $this->client->getResponse(); + $response = $this->getClient()->getResponse(); $this->assertTrue( $response->isRedirection() ); - $this->client->followRedirect(); + $this->getClient()->followRedirect(); $this->seeInCurrentUrl($redirectsTo); } diff --git a/src/Codeception/Module/Symfony/RouterAssertionsTrait.php b/src/Codeception/Module/Symfony/RouterAssertionsTrait.php index 97c39736..043d4b57 100644 --- a/src/Codeception/Module/Symfony/RouterAssertionsTrait.php +++ b/src/Codeception/Module/Symfony/RouterAssertionsTrait.php @@ -4,7 +4,6 @@ namespace Codeception\Module\Symfony; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; @@ -101,8 +100,7 @@ public function seeCurrentActionIs(string $action): void foreach ($routes as $route) { $controller = $route->getDefault('_controller'); if (substr_compare($controller, $action, -strlen($action)) === 0) { - /** @var Request $request */ - $request = $this->client->getRequest(); + $request = $this->getClient()->getRequest(); $currentActionFqcn = $request->attributes->get('_controller'); $this->assertStringEndsWith($action, $currentActionFqcn, "Current action is '{$currentActionFqcn}'.");