Skip to content

Commit

Permalink
Remove derprecaed phpunit code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Jan 18, 2021
1 parent b1dcb28 commit baa9848
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
13 changes: 7 additions & 6 deletions tests/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public function testAssert($method, $args, $success, $multibyte = false, $minVer
}

if (!$success) {
$this->setExpectedException('\InvalidArgumentException');
$this->expectException('\InvalidArgumentException');
}

call_user_func_array(array('Webmozart\Assert\Assert', $method), $args);
Expand All @@ -620,7 +620,7 @@ public function testNullOr($method, $args, $success, $multibyte = false, $minVer
}

if (!$success && null !== reset($args)) {
$this->setExpectedException('\InvalidArgumentException');
$this->expectException('\InvalidArgumentException');
}

call_user_func_array(array('Webmozart\Assert\Assert', 'nullOr'.ucfirst($method)), $args);
Expand Down Expand Up @@ -651,7 +651,7 @@ public function testAllArray($method, $args, $success, $multibyte = false, $minV
}

if (!$success) {
$this->setExpectedException('\InvalidArgumentException');
$this->expectException('\InvalidArgumentException');
}

$arg = array_shift($args);
Expand All @@ -676,7 +676,7 @@ public function testAllTraversable($method, $args, $success, $multibyte = false,
}

if (!$success) {
$this->setExpectedException('\InvalidArgumentException');
$this->expectException('\InvalidArgumentException');
}

$arg = array_shift($args);
Expand Down Expand Up @@ -716,14 +716,15 @@ public function getStringConversions()
*/
public function testConvertValuesToStrings($method, $args, $exceptionMessage)
{
$this->setExpectedException('\InvalidArgumentException', $exceptionMessage);
$this->expectException('\InvalidArgumentException', $exceptionMessage);
$this->expectExceptionMessage($exceptionMessage);

call_user_func_array(array('Webmozart\Assert\Assert', $method), $args);
}

public function testAnUnknownMethodThrowsABadMethodCall()
{
$this->setExpectedException('\BadMethodCallException');
$this->expectException('\BadMethodCallException');

Assert::nonExistentMethod();
}
Expand Down
26 changes: 0 additions & 26 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,4 @@
*/
class BaseTestCase extends TestCase
{
/**
* The setExpectedException got removed in later phpunit versions,
* and instead it got split up into three functions.
*
* So if the newer functions exist we call those where needed, and otherwise
* we just use the original function.
*
* @param string $exceptionName
* @param string $exceptionMessage
* @param int $exceptionCode
*/
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
$this->expectException($exceptionName);
if ($exceptionMessage) {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode) {
$this->expectExceptionCode($exceptionCode);
}

return;
}
parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode);
}
}
2 changes: 1 addition & 1 deletion tests/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testHasThrowsAnnotation($method)
)
);

$this->assertContains(
$this->assertStringContainsString(
'@throws InvalidArgumentException',
$doc,
sprintf(
Expand Down

0 comments on commit baa9848

Please sign in to comment.