Skip to content

Commit 4901a7d

Browse files
authored
Restore InnerBrowser navigation state for Codeception runs (#231)
1 parent a798e89 commit 4901a7d

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/Codeception/Module/Symfony/BrowserAssertionsTrait.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Codeception\Module\Symfony;
66

7+
use Codeception\Lib\InnerBrowser;
78
use PHPUnit\Framework\Constraint\Constraint;
89
use PHPUnit\Framework\Constraint\LogicalAnd;
910
use PHPUnit\Framework\Constraint\LogicalNot;
@@ -319,7 +320,13 @@ public function seePageIsAvailable(?string $url = null): void
319320
{
320321
if ($url !== null) {
321322
$client = $this->getClient();
322-
$client->request('GET', $url);
323+
324+
if ($this instanceof InnerBrowser) {
325+
$this->amOnPage($url);
326+
} else {
327+
$client->request('GET', $url);
328+
}
329+
323330
$this->assertStringContainsString($url, $client->getRequest()->getRequestUri());
324331
}
325332

@@ -338,7 +345,12 @@ public function seePageRedirectsTo(string $page, string $redirectsTo): void
338345
{
339346
$client = $this->getClient();
340347
$client->followRedirects(false);
341-
$client->request('GET', $page);
348+
349+
if ($this instanceof InnerBrowser) {
350+
$this->amOnPage($page);
351+
} else {
352+
$client->request('GET', $page);
353+
}
342354

343355
$this->assertThatForResponse(new ResponseIsRedirected(), 'The response is not a redirection.');
344356

@@ -365,14 +377,20 @@ public function seePageRedirectsTo(string $page, string $redirectsTo): void
365377
*/
366378
public function submitSymfonyForm(string $name, array $fields): void
367379
{
380+
$client = $this->getClient();
368381
$selector = sprintf('form[name=%s]', $name);
369382

370383
$params = [];
371384
foreach ($fields as $key => $value) {
372385
$params[$name . $key] = $value;
373386
}
374387

375-
$client = $this->getClient();
388+
if ($this instanceof InnerBrowser) {
389+
$this->submitForm($selector, $params, sprintf('%s_submit', $name));
390+
391+
return;
392+
}
393+
376394
$node = $client->getCrawler()->filter($selector);
377395
$this->assertGreaterThan(0, $node->count(), sprintf('Form "%s" not found.', $selector));
378396
$form = $node->form();

src/Codeception/Module/Symfony/RouterAssertionsTrait.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Codeception\Module\Symfony;
66

7+
use Codeception\Lib\InnerBrowser;
78
use PHPUnit\Framework\Assert;
89
use Stringable;
910
use Symfony\Component\Routing\RouterInterface;
@@ -161,7 +162,16 @@ private function assertRouteExists(string $routeName): void
161162
/** @param array<string, scalar|Stringable|array<mixed>|null> $params */
162163
private function openRoute(string $routeName, array $params = []): void
163164
{
164-
$this->getClient()->request('GET', $this->grabRouterService()->generate($routeName, $params));
165+
$client = $this->getClient();
166+
$url = $this->grabRouterService()->generate($routeName, $params);
167+
168+
if ($this instanceof InnerBrowser) {
169+
$this->amOnPage($url);
170+
171+
return;
172+
}
173+
174+
$client->request('GET', $url);
165175
}
166176

167177
protected function grabRouterService(): RouterInterface

0 commit comments

Comments
 (0)