Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.');
Expand Down
16 changes: 6 additions & 10 deletions src/Codeception/Module/Symfony/BrowserAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,9 +27,7 @@ trait BrowserAssertionsTrait
*/
public function rebootClientKernel(): void
{
if ($this->client instanceof SymfonyConnector) {
$this->client->rebootKernel();
}
$this->getClient()->rebootKernel();
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Codeception/Module/Symfony/RouterAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}'.");
Expand Down