Skip to content

Commit f775652

Browse files
SamMousaDavertMik
authored andcommitted
Yii2: Move implementations to connector (#5173)
* Refactor functions from module to connector, keeping the module interface the same but moving implementations to the connector. * Fixed nitpick CS * Attempt to use Guzzle MockHandler instead of external service * Fixed issues with test & phpbrowser configurability
1 parent e09404c commit f775652

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Codeception/Module/PhpBrowser.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ public function amHttpAuthenticated($username, $password)
172172
public function amOnUrl($url)
173173
{
174174
$host = Uri::retrieveHost($url);
175-
$this->_reconfigure(['url' => $host]);
175+
$config = $this->config;
176+
$config['url'] = $host;
177+
$this->_reconfigure($config);
176178
$page = substr($url, strlen($host));
177179
if ($page === '') {
178180
$page = '/';
@@ -186,7 +188,9 @@ public function amOnSubdomain($subdomain)
186188
$url = $this->config['url'];
187189
$url = preg_replace('~(https?:\/\/)(.*\.)(.*\.)~', "$1$3", $url); // removing current subdomain
188190
$url = preg_replace('~(https?:\/\/)(.*)~', "$1$subdomain.$2", $url); // inserting new
189-
$this->_reconfigure(['url' => $url]);
191+
$config = $this->config;
192+
$config['url'] = $url;
193+
$this->_reconfigure($config);
190194
}
191195

192196
protected function onReconfigure()

tests/unit/Codeception/Module/PhpBrowserTest.php

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

55
require_once 'tests/data/app/data.php';
66
require_once __DIR__ . '/TestsForBrowsers.php';
7+
8+
use GuzzleHttp\Handler\MockHandler;
79
use GuzzleHttp\Psr7\Response;
810

911
class PhpBrowserTest extends TestsForBrowsers
@@ -19,7 +21,7 @@ protected function setUp()
1921
{
2022
$this->module = new \Codeception\Module\PhpBrowser(make_container());
2123
$url = 'http://localhost:8000';
22-
$this->module->_setConfig(array('url' => $url));
24+
$this->module->_setConfig(['url' => $url]);
2325
$this->module->_initialize();
2426
$this->module->_before($this->makeTest());
2527
if (class_exists('GuzzleHttp\Url')) {
@@ -280,7 +282,15 @@ public function testLocationHeaderDoesNotRedirectWhenStatusCodeIs201()
280282

281283
public function testRedirectToAnotherDomainUsingSchemalessUrl()
282284
{
283-
$this->module->amOnUrl('http://httpbin.org/redirect-to?url=//example.org/');
285+
286+
$this->module->_reconfigure([
287+
'handler' => new MockHandler([
288+
new Response(302, ['Location' => '//example.org/']),
289+
new Response(200, [], 'Cool stuff')
290+
])
291+
]);
292+
/** @var \GuzzleHttp\HandlerStack $handlerStack */
293+
$this->module->amOnUrl('http://fictional.redirector/redirect-to?url=//example.org/');
284294
$currentUrl = $this->module->client->getHistory()->current()->getUri();
285295
$this->assertSame('http://example.org/', $currentUrl);
286296
}
@@ -481,7 +491,7 @@ public function testCookiesForDomain()
481491
{
482492
$this->skipForOldGuzzle();
483493

484-
$mock = new \GuzzleHttp\Handler\MockHandler([
494+
$mock = new MockHandler([
485495
new Response(200, ['X-Foo' => 'Bar']),
486496
]);
487497
$handler = \GuzzleHttp\HandlerStack::create($mock);

0 commit comments

Comments
 (0)