Skip to content

Commit 85af96e

Browse files
committed
Removed deprecated setExpectedException method
1 parent d7b17b2 commit 85af96e

File tree

4 files changed

+35
-50
lines changed

4 files changed

+35
-50
lines changed

tests/unit/Codeception/Module/PhpBrowserRestTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testValidJson()
7171

7272
public function testInvalidJson()
7373
{
74-
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
74+
$this->expectException('PHPUnit\Framework\ExpectationFailedException');
7575
$this->setStubResponse('{xxx = yyy}');
7676
$this->module->seeResponseIsJson();
7777
}
@@ -87,7 +87,7 @@ public function testValidXml()
8787

8888
public function testInvalidXml()
8989
{
90-
$this->setExpectedException('PHPUnit\Framework\ExpectationFailedException');
90+
$this->expectException('PHPUnit\Framework\ExpectationFailedException');
9191
$this->setStubResponse('<xml><name>John</surname></xml>');
9292
$this->module->seeResponseIsXml();
9393
}
@@ -294,7 +294,7 @@ public function testSessionHeaderBackup()
294294

295295
protected function shouldFail()
296296
{
297-
$this->setExpectedException('PHPUnit\Framework\AssertionFailedError');
297+
$this->expectException('PHPUnit\Framework\AssertionFailedError');
298298
}
299299

300300
public function testGrabFromCurrentUrl()

tests/unit/Codeception/Module/PhpBrowserTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ public function testDoubleSlash()
452452

453453
public function testFillFieldWithoutPage()
454454
{
455-
$this->setExpectedException("\\Codeception\\Exception\\ModuleException");
455+
$this->expectException("\\Codeception\\Exception\\ModuleException");
456456
$this->module->fillField('#name', 'Nothing special');
457457
}
458458

@@ -530,7 +530,7 @@ public function testEmptyValueOfCookie()
530530

531531
public function testRequestApi()
532532
{
533-
$this->setExpectedException('Codeception\Exception\ModuleException');
533+
$this->expectException('Codeception\Exception\ModuleException');
534534
$response = $this->module->_request('POST', '/form/try', ['user' => 'davert']);
535535
$data = data::get('form');
536536
$this->assertEquals('davert', $data['user']);
@@ -555,10 +555,8 @@ public function testLoadPageApi()
555555
public function testClickFailure()
556556
{
557557
$this->module->amOnPage('/info');
558-
$this->setExpectedException(
559-
'Codeception\Exception\ElementNotFound',
560-
"'Sign In!' is invalid CSS and XPath selector and Link or Button element with 'name=Sign In!' was not found"
561-
);
558+
$this->expectException('Codeception\Exception\ElementNotFound');
559+
$this->expectExceptionMessage("'Sign In!' is invalid CSS and XPath selector and Link or Button element with 'name=Sign In!' was not found");
562560
$this->module->click('Sign In!');
563561
}
564562

@@ -625,10 +623,8 @@ public function testFillFieldInGetFormWithoutId()
625623

626624
public function testGrabPageSourceWhenNotOnPage()
627625
{
628-
$this->setExpectedException(
629-
'\Codeception\Exception\ModuleException',
630-
'Page not loaded. Use `$I->amOnPage` (or hidden API methods `_request` and `_loadPage`) to open it'
631-
);
626+
$this->expectException('\Codeception\Exception\ModuleException');
627+
$this->expectExceptionMessage('Page not loaded. Use `$I->amOnPage` (or hidden API methods `_request` and `_loadPage`) to open it');
632628
$this->module->grabPageSource();
633629
}
634630

tests/unit/Codeception/Module/TestsForBrowsers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testSiteRootRelativePathsForBasePathWithSubdir()
5959

6060
public function testOpenPageException()
6161
{
62-
$this->setExpectedException('Codeception\Exception\ModuleException');
62+
$this->expectException('Codeception\Exception\ModuleException');
6363
$this->module->see('Hello');
6464
}
6565
}

tests/unit/Codeception/Module/TestsForWeb.php

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testSeeIsCaseInsensitiveForUnicodeText()
9292

9393
public function testDontSeeIsCaseInsensitiveForUnicodeText()
9494
{
95-
$this->setExpectedException("PHPUnit\Framework\AssertionFailedError");
95+
$this->expectException("PHPUnit\Framework\AssertionFailedError");
9696
$this->module->amOnPage('/info');
9797
$this->module->dontSee('ссылочка');
9898
}
@@ -129,50 +129,40 @@ public function testDontSeeLink()
129129

130130
public function testSeeLinkFailsIfTextDoesNotMatch()
131131
{
132-
$this->setExpectedException(
133-
'PHPUnit\Framework\AssertionFailedError',
134-
"No links containing text 'Codeception' were found in page /external_url"
135-
);
132+
$this->expectException('PHPUnit\Framework\AssertionFailedError');
133+
$this->expectExceptionMessage("No links containing text 'Codeception' were found in page /external_url");
136134
$this->module->amOnPage('/external_url');
137135
$this->module->seeLink('Codeception');
138136
}
139137

140138
public function testSeeLinkFailsIfHrefDoesNotMatch()
141139
{
142-
$this->setExpectedException(
143-
'PHPUnit\Framework\AssertionFailedError',
144-
"No links containing text 'Next' and URL '/fsdfsdf/' were found in page /external_url"
145-
);
140+
$this->expectException('PHPUnit\Framework\AssertionFailedError');
141+
$this->expectExceptionMessage("No links containing text 'Next' and URL '/fsdfsdf/' were found in page /external_url");
146142
$this->module->amOnPage('/external_url');
147143
$this->module->seeLink('Next', '/fsdfsdf/');
148144
}
149145

150146
public function testSeeLinkFailsIfHrefDoesNotMatchExactly()
151147
{
152-
$this->setExpectedException(
153-
'PHPUnit\Framework\AssertionFailedError',
154-
"No links containing text 'Next' and URL 'http://codeception' were found in page /external_url"
155-
);
148+
$this->expectException('PHPUnit\Framework\AssertionFailedError');
149+
$this->expectExceptionMessage("No links containing text 'Next' and URL 'http://codeception' were found in page /external_url");
156150
$this->module->amOnPage('/external_url');
157151
$this->module->seeLink('Next', 'http://codeception');
158152
}
159153

160154
public function testDontSeeLinkFailsIfTextMatches()
161155
{
162-
$this->setExpectedException(
163-
'PHPUnit\Framework\AssertionFailedError',
164-
"Link containing text 'Next' was found in page /external_url"
165-
);
156+
$this->expectException('PHPUnit\Framework\AssertionFailedError');
157+
$this->expectExceptionMessage("Link containing text 'Next' was found in page /external_url");
166158
$this->module->amOnPage('/external_url');
167159
$this->module->dontSeeLink('Next');
168160
}
169161

170162
public function testDontSeeLinkFailsIfTextAndUrlMatches()
171163
{
172-
$this->setExpectedException(
173-
'PHPUnit\Framework\AssertionFailedError',
174-
"Link containing text 'Next' and URL 'http://codeception.com/' was found in page /external_url"
175-
);
164+
$this->expectException('PHPUnit\Framework\AssertionFailedError');
165+
$this->expectExceptionMessage("Link containing text 'Next' and URL 'http://codeception.com/' was found in page /external_url");
176166
$this->module->amOnPage('/external_url');
177167
$this->module->dontSeeLink('Next', 'http://codeception.com/');
178168
}
@@ -186,10 +176,8 @@ public function testSeeLinkMatchesRelativeLink()
186176

187177
public function testDontSeeLinkMatchesRelativeLink()
188178
{
189-
$this->setExpectedException(
190-
'PHPUnit\Framework\AssertionFailedError',
191-
"Link containing text 'Sign in!' and URL '/login' was found in page /info"
192-
);
179+
$this->expectException('PHPUnit\Framework\AssertionFailedError');
180+
$this->expectExceptionMessage("Link containing text 'Sign in!' and URL '/login' was found in page /info");
193181
$this->module->amOnPage('/info');
194182
$this->module->dontSeeLink('Sign in!', '/login');
195183
}
@@ -624,7 +612,7 @@ public function testSeeInFormFields()
624612
public function testSeeInFormFieldsFails()
625613
{
626614
$this->module->amOnPage('/form/field_values');
627-
$this->setExpectedException("PHPUnit\Framework\AssertionFailedError");
615+
$this->expectException("PHPUnit\Framework\AssertionFailedError");
628616
$params = [
629617
'radio1' => 'something I should not see',
630618
'checkbox1' => true,
@@ -662,7 +650,7 @@ public function testDontSeeInFormFields()
662650
public function testDontSeeInFormFieldsFails()
663651
{
664652
$this->module->amOnPage('/form/field_values');
665-
$this->setExpectedException("PHPUnit\Framework\AssertionFailedError");
653+
$this->expectException("PHPUnit\Framework\AssertionFailedError");
666654
$params = [
667655
'checkbox[]' => [
668656
'wont see this anyway',
@@ -790,7 +778,7 @@ public function testSeeElementOnPage()
790778
// regression test. https://github.com/Codeception/Codeception/issues/587
791779
public function testSeeElementOnPageFails()
792780
{
793-
$this->setExpectedException("PHPUnit\Framework\AssertionFailedError");
781+
$this->expectException("PHPUnit\Framework\AssertionFailedError");
794782
$this->module->amOnPage('/form/field');
795783
$this->module->dontSeeElement('input[name=name]');
796784
}
@@ -1210,7 +1198,7 @@ public function testSelectTwoSubmitsByCSS()
12101198

12111199
protected function shouldFail()
12121200
{
1213-
$this->setExpectedException('PHPUnit\Framework\AssertionFailedError');
1201+
$this->expectException('PHPUnit\Framework\AssertionFailedError');
12141202
}
12151203

12161204
/**
@@ -1354,28 +1342,28 @@ public function testSubmitFormWithButtons()
13541342
*/
13551343
public function testWrongXpath()
13561344
{
1357-
$this->setExpectedException('Codeception\Exception\MalformedLocatorException');
1345+
$this->expectException('Codeception\Exception\MalformedLocatorException');
13581346
$this->module->amOnPage('/');
13591347
$this->module->seeElement('//aas[asd}[sd]a[/[');
13601348
}
13611349

13621350
public function testWrongCSS()
13631351
{
1364-
$this->setExpectedException('Codeception\Exception\MalformedLocatorException');
1352+
$this->expectException('Codeception\Exception\MalformedLocatorException');
13651353
$this->module->amOnPage('/');
13661354
$this->module->seeElement('.user#iasos<here');
13671355
}
13681356

13691357
public function testWrongStrictCSSLocator()
13701358
{
1371-
$this->setExpectedException('Codeception\Exception\MalformedLocatorException');
1359+
$this->expectException('Codeception\Exception\MalformedLocatorException');
13721360
$this->module->amOnPage('/');
13731361
$this->module->seeElement(['css' => 'hel!1$<world']);
13741362
}
13751363

13761364
public function testWrongStrictXPathLocator()
13771365
{
1378-
$this->setExpectedException('Codeception\Exception\MalformedLocatorException');
1366+
$this->expectException('Codeception\Exception\MalformedLocatorException');
13791367
$this->module->amOnPage('/');
13801368
$this->module->seeElement(['xpath' => 'hello<wo>rld']);
13811369
}
@@ -1585,8 +1573,8 @@ public function testClickMultiByteLink()
15851573
*/
15861574
public function testClickThrowsElementNotFoundExceptionWhenTextContainsNumber()
15871575
{
1588-
$this->setExpectedException('Codeception\Exception\ElementNotFound',
1589-
"'Link 2' is invalid CSS and XPath selector and Link or Button element with 'name=Link 2' was not found.");
1576+
$this->expectException('Codeception\Exception\ElementNotFound');
1577+
$this->expectExceptionMessage("'Link 2' is invalid CSS and XPath selector and Link or Button element with 'name=Link 2' was not found.");
15901578
$this->module->amOnPage('/info');
15911579
$this->module->click('Link 2');
15921580
}
@@ -1707,7 +1695,8 @@ public function testAttachFileThrowsCorrectMessageWhenFileDoesNotExist()
17071695
{
17081696
$filename = 'does-not-exist.jpg';
17091697
$expectedMessage = 'File does not exist: ' . codecept_data_dir($filename);
1710-
$this->setExpectedException('InvalidArgumentException', $expectedMessage);
1698+
$this->expectException('InvalidArgumentException');
1699+
$this->expectExceptionMessage($expectedMessage);
17111700

17121701
$this->module->amOnPage('/form/file');
17131702
$this->module->attachFile('Avatar', $filename);

0 commit comments

Comments
 (0)