Skip to content

Commit 145490d

Browse files
committed
Added more typehints
1 parent 186e85e commit 145490d

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

src/Codeception/Lib/InnerBrowser.php

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,15 @@ public function _after(TestInterface $test)
127127
$this->headers = [];
128128
}
129129

130-
public function _conflicts()
130+
/**
131+
* @return class-string
132+
*/
133+
public function _conflicts(): string
131134
{
132135
return \Codeception\Lib\Interfaces\Web::class;
133136
}
134137

135-
public function _findElements($locator)
138+
public function _findElements(array $locator)
136139
{
137140
return $this->match($locator);
138141
}
@@ -339,7 +342,7 @@ private function getRunningClient(): AbstractBrowser
339342
return $this->client;
340343
}
341344

342-
public function _savePageSource($filename)
345+
public function _savePageSource(string $filename): void
343346
{
344347
file_put_contents($filename, $this->_getResponseContent());
345348
}
@@ -409,12 +412,12 @@ public function deleteHeader(string $name): void
409412
unset($this->headers[$name]);
410413
}
411414

412-
public function amOnPage($page)
415+
public function amOnPage(string $page): void
413416
{
414417
$this->_loadPage('GET', $page);
415418
}
416419

417-
public function click($link, $context = null)
420+
public function click($link, $context = null): void
418421
{
419422
if ($context) {
420423
$this->crawler = $this->match($context);
@@ -548,7 +551,7 @@ private function retrieveBaseUrl(): string
548551
return $this->getAbsoluteUrlFor($baseUrl);
549552
}
550553

551-
public function see($text, $selector = null)
554+
public function see(string $text, $selector = null): void
552555
{
553556
if (!$selector) {
554557
$this->assertPageContains($text);
@@ -559,7 +562,7 @@ public function see($text, $selector = null)
559562
$this->assertDomContains($nodes, $this->stringifySelector($selector), $text);
560563
}
561564

562-
public function dontSee($text, $selector = null)
565+
public function dontSee(string $text, $selector = null): void
563566
{
564567
if (!$selector) {
565568
$this->assertPageNotContains($text);
@@ -570,17 +573,17 @@ public function dontSee($text, $selector = null)
570573
$this->assertDomNotContains($nodes, $this->stringifySelector($selector), $text);
571574
}
572575

573-
public function seeInSource($raw)
576+
public function seeInSource(string $raw): void
574577
{
575578
$this->assertPageSourceContains($raw);
576579
}
577580

578-
public function dontSeeInSource($raw)
581+
public function dontSeeInSource(string $raw): void
579582
{
580583
$this->assertPageSourceNotContains($raw);
581584
}
582585

583-
public function seeLink($text, $url = null)
586+
public function seeLink(string $text, string $url = null): void
584587
{
585588
$crawler = $this->getCrawler()->selectLink($text);
586589
if ($crawler->count() === 0) {
@@ -595,16 +598,15 @@ public function seeLink($text, $url = null)
595598
$this->assertTrue(true);
596599
}
597600

598-
public function dontSeeLink($text, $url = null)
601+
public function dontSeeLink(string $text, string $url = null): void
599602
{
600-
$url = (string) $url;
601603
$crawler = $this->getCrawler()->selectLink($text);
602604
if (!$url && $crawler->count() > 0) {
603605
$this->fail("Link containing text '$text' was found in page " . $this->_getCurrentUri());
604606
}
605607
$crawler = $crawler->filterXPath(
606608
sprintf('.//a[substring(@href, string-length(@href) - string-length(%1$s) + 1)=%1$s]',
607-
SymfonyCrawler::xpathLiteral($url))
609+
SymfonyCrawler::xpathLiteral((string) $url))
608610
);
609611
if ($crawler->count() > 0) {
610612
$this->fail("Link containing text '$text' and URL '$url' was found in page " . $this->_getCurrentUri());
@@ -620,37 +622,37 @@ public function _getCurrentUri(): string
620622
return Uri::retrieveUri($this->getRunningClient()->getHistory()->current()->getUri());
621623
}
622624

623-
public function seeInCurrentUrl($uri)
625+
public function seeInCurrentUrl(string $uri): void
624626
{
625627
$this->assertStringContainsString($uri, $this->_getCurrentUri());
626628
}
627629

628-
public function dontSeeInCurrentUrl($uri)
630+
public function dontSeeInCurrentUrl(string $uri): void
629631
{
630632
$this->assertStringNotContainsString($uri, $this->_getCurrentUri());
631633
}
632634

633-
public function seeCurrentUrlEquals($uri)
635+
public function seeCurrentUrlEquals(string $uri): void
634636
{
635637
$this->assertEquals(rtrim($uri, '/'), rtrim($this->_getCurrentUri(), '/'));
636638
}
637639

638-
public function dontSeeCurrentUrlEquals($uri)
640+
public function dontSeeCurrentUrlEquals(string $uri): void
639641
{
640642
$this->assertNotEquals(rtrim($uri, '/'), rtrim($this->_getCurrentUri(), '/'));
641643
}
642644

643-
public function seeCurrentUrlMatches($uri)
645+
public function seeCurrentUrlMatches(string $uri): void
644646
{
645647
$this->assertRegExp($uri, $this->_getCurrentUri());
646648
}
647649

648-
public function dontSeeCurrentUrlMatches($uri)
650+
public function dontSeeCurrentUrlMatches(string $uri): void
649651
{
650652
$this->assertNotRegExp($uri, $this->_getCurrentUri());
651653
}
652654

653-
public function grabFromCurrentUrl($uri = null)
655+
public function grabFromCurrentUrl(string $uri = null)
654656
{
655657
if (!$uri) {
656658
return $this->_getCurrentUri();
@@ -666,36 +668,36 @@ public function grabFromCurrentUrl($uri = null)
666668
return $matches[1];
667669
}
668670

669-
public function seeCheckboxIsChecked($checkbox)
671+
public function seeCheckboxIsChecked($checkbox): void
670672
{
671673
$checkboxes = $this->getFieldsByLabelOrCss($checkbox);
672674
$this->assertDomContains($checkboxes->filter('input[checked=checked]'), 'checkbox');
673675
}
674676

675-
public function dontSeeCheckboxIsChecked($checkbox)
677+
public function dontSeeCheckboxIsChecked($checkbox): void
676678
{
677679
$checkboxes = $this->getFieldsByLabelOrCss($checkbox);
678680
$this->assertEquals(0, $checkboxes->filter('input[checked=checked]')->count());
679681
}
680682

681-
public function seeInField($field, $value)
683+
public function seeInField($field, $value): void
682684
{
683685
$nodes = $this->getFieldsByLabelOrCss($field);
684686
$this->assert($this->proceedSeeInField($nodes, $value));
685687
}
686688

687-
public function dontSeeInField($field, $value)
689+
public function dontSeeInField($field, $value): void
688690
{
689691
$nodes = $this->getFieldsByLabelOrCss($field);
690692
$this->assertNot($this->proceedSeeInField($nodes, $value));
691693
}
692694

693-
public function seeInFormFields($formSelector, array $params)
695+
public function seeInFormFields($formSelector, array $params): void
694696
{
695697
$this->proceedSeeInFormFields($formSelector, $params, false);
696698
}
697699

698-
public function dontSeeInFormFields($formSelector, array $params)
700+
public function dontSeeInFormFields($formSelector, array $params): void
699701
{
700702
$this->proceedSeeInFormFields($formSelector, $params, true);
701703
}
@@ -954,7 +956,7 @@ protected function proceedSubmitForm(Crawler $frmCrawl, array $params, string $b
954956
$this->forms = [];
955957
}
956958

957-
public function submitForm($selector, array $params, $button = null)
959+
public function submitForm($selector, array $params, $button = null): void
958960
{
959961
$form = $this->match($selector)->first();
960962
if (count($form) === 0) {
@@ -1112,7 +1114,7 @@ protected function getFormValuesFor(SymfonyForm $form): array
11121114
return $values;
11131115
}
11141116

1115-
public function fillField($field, $value)
1117+
public function fillField($field, $value = ''): void
11161118
{
11171119
$input = $this->getFieldByLabelOrCss($field);
11181120
$form = $this->getFormFor($input);
@@ -1174,7 +1176,7 @@ protected function getFieldByLabelOrCss($field): SymfonyCrawler
11741176
return $input->first();
11751177
}
11761178

1177-
public function selectOption($select, $option)
1179+
public function selectOption($select, $option): void
11781180
{
11791181
$field = $this->getFieldByLabelOrCss($select);
11801182
$form = $this->getFormFor($field);
@@ -1244,12 +1246,12 @@ protected function matchOption(Crawler $field, $option)
12441246
return $option;
12451247
}
12461248

1247-
public function checkOption($option)
1249+
public function checkOption($option): void
12481250
{
12491251
$this->proceedCheckOption($option)->tick();
12501252
}
12511253

1252-
public function uncheckOption($option)
1254+
public function uncheckOption($option): void
12531255
{
12541256
$this->proceedCheckOption($option)->untick();
12551257
}
@@ -1275,7 +1277,7 @@ protected function proceedCheckOption($option): ChoiceFormField
12751277
return $formField;
12761278
}
12771279

1278-
public function attachFile($field, $filename)
1280+
public function attachFile($field, string $filename): void
12791281
{
12801282
$form = $this->getFormFor($field = $this->getFieldByLabelOrCss($field));
12811283
$filePath = codecept_data_dir() . $filename;
@@ -1364,7 +1366,7 @@ protected function debugResponse($url)
13641366
$this->debugSection('Response Headers', $this->getRunningClient()->getInternalResponse()->getHeaders());
13651367
}
13661368

1367-
public function makeHtmlSnapshot($name = null)
1369+
public function makeHtmlSnapshot(string $name = null): void
13681370
{
13691371
if (empty($name)) {
13701372
$name = uniqid(date("Y-m-d_H-i-s_"), true);
@@ -1468,7 +1470,7 @@ public function grabTextFrom($cssOrXPathOrRegex)
14681470
throw new ElementNotFound($cssOrXPathOrRegex, 'Element that matches CSS or XPath or Regex');
14691471
}
14701472

1471-
public function grabAttributeFrom($cssOrXpath, $attribute)
1473+
public function grabAttributeFrom($cssOrXpath, string $attribute)
14721474
{
14731475
$nodes = $this->match($cssOrXpath);
14741476
if ($nodes->count() === 0) {
@@ -1477,7 +1479,7 @@ public function grabAttributeFrom($cssOrXpath, $attribute)
14771479
return $nodes->first()->attr($attribute);
14781480
}
14791481

1480-
public function grabMultiple($cssOrXpath, $attribute = null)
1482+
public function grabMultiple($cssOrXpath, string $attribute = null): array
14811483
{
14821484
$result = [];
14831485
$nodes = $this->match($cssOrXpath);
@@ -1528,7 +1530,7 @@ public function grabValueFrom($field)
15281530
$this->fail("Element {$nodes} is not a form field or does not contain a form field");
15291531
}
15301532

1531-
public function setCookie($name, $val, array $params = [])
1533+
public function setCookie(string $name, ?string $val, array $params = [])
15321534
{
15331535
$cookies = $this->client->getCookieJar();
15341536
$params = array_merge($this->defaultCookieParameters, $params);
@@ -1548,7 +1550,7 @@ public function setCookie($name, $val, array $params = [])
15481550
$this->debugCookieJar();
15491551
}
15501552

1551-
public function grabCookie($cookie, array $params = [])
1553+
public function grabCookie(string $cookie, array $params = [])
15521554
{
15531555
$params = array_merge($this->defaultCookieParameters, $params);
15541556
$this->debugCookieJar();
@@ -1565,26 +1567,26 @@ public function grabCookie($cookie, array $params = [])
15651567
* @throws ModuleException if no page was opened.
15661568
* @return string Current page source code.
15671569
*/
1568-
public function grabPageSource()
1570+
public function grabPageSource(): string
15691571
{
15701572
return $this->_getResponseContent();
15711573
}
15721574

1573-
public function seeCookie($cookie, array $params = [])
1575+
public function seeCookie(string $cookie, array $params = [])
15741576
{
15751577
$params = array_merge($this->defaultCookieParameters, $params);
15761578
$this->debugCookieJar();
15771579
$this->assertNotNull($this->client->getCookieJar()->get($cookie, $params['path'], $params['domain']));
15781580
}
15791581

1580-
public function dontSeeCookie($cookie, array $params = [])
1582+
public function dontSeeCookie(string $cookie, array $params = [])
15811583
{
15821584
$params = array_merge($this->defaultCookieParameters, $params);
15831585
$this->debugCookieJar();
15841586
$this->assertNull($this->client->getCookieJar()->get($cookie, $params['path'], $params['domain']));
15851587
}
15861588

1587-
public function resetCookie($cookie, array $params = [])
1589+
public function resetCookie(string $cookie, array $params = [])
15881590
{
15891591
$params = array_merge($this->defaultCookieParameters, $params);
15901592
$this->client->getCookieJar()->expire($cookie, $params['path'], $params['domain']);
@@ -1599,7 +1601,7 @@ private function stringifySelector($selector): string
15991601
return $selector;
16001602
}
16011603

1602-
public function seeElement($selector, $attributes = [])
1604+
public function seeElement($selector, array $attributes = []): void
16031605
{
16041606
$nodes = $this->match($selector);
16051607
$selector = $this->stringifySelector($selector);
@@ -1610,7 +1612,7 @@ public function seeElement($selector, $attributes = [])
16101612
$this->assertDomContains($nodes, $selector);
16111613
}
16121614

1613-
public function dontSeeElement($selector, $attributes = [])
1615+
public function dontSeeElement($selector, array $attributes = []): void
16141616
{
16151617
$nodes = $this->match($selector);
16161618
$selector = $this->stringifySelector($selector);
@@ -1621,7 +1623,7 @@ public function dontSeeElement($selector, $attributes = [])
16211623
$this->assertDomNotContains($nodes, $selector);
16221624
}
16231625

1624-
public function seeNumberOfElements($selector, $expected)
1626+
public function seeNumberOfElements($selector, $expected): void
16251627
{
16261628
$counted = count($this->match($selector));
16271629
if (is_array($expected)) {
@@ -1639,7 +1641,7 @@ public function seeNumberOfElements($selector, $expected)
16391641
}
16401642
}
16411643

1642-
public function seeOptionIsSelected($selector, $optionText)
1644+
public function seeOptionIsSelected($selector, string $optionText)
16431645
{
16441646
$selected = $this->matchSelectedOption($selector);
16451647
$this->assertDomContains($selected, 'selected option');
@@ -1650,7 +1652,7 @@ public function seeOptionIsSelected($selector, $optionText)
16501652
$this->assertEquals($optionText, $value);
16511653
}
16521654

1653-
public function dontSeeOptionIsSelected($selector, $optionText)
1655+
public function dontSeeOptionIsSelected($selector, string $optionText)
16541656
{
16551657
$selected = $this->matchSelectedOption($selector);
16561658
if ($selected->count() === 0) {
@@ -1776,7 +1778,7 @@ public function seeResponseCodeIsServerError()
17761778
$this->seeResponseCodeIsBetween(500, 599);
17771779
}
17781780

1779-
public function seeInTitle($title)
1781+
public function seeInTitle(string $title)
17801782
{
17811783
$nodes = $this->getCrawler()->filter('title');
17821784
if ($nodes->count() === 0) {
@@ -1785,7 +1787,7 @@ public function seeInTitle($title)
17851787
$this->assertStringContainsString($title, $nodes->first()->text(), "page title contains $title");
17861788
}
17871789

1788-
public function dontSeeInTitle($title)
1790+
public function dontSeeInTitle(string $title)
17891791
{
17901792
$nodes = $this->getCrawler()->filter('title');
17911793
if ($nodes->count() === 0) {

0 commit comments

Comments
 (0)