From b083649ad5918ffc3b58cb91e759cd3b6414bda3 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 21 Nov 2019 09:22:12 +0100 Subject: [PATCH] Closes #3333 --- src/Framework/TestCase.php | 32 ----- src/Util/Annotation/DocBlock.php | 57 --------- src/Util/Test.php | 14 --- tests/_files/ExceptionNamespaceTest.php | 45 ------- tests/_files/ExceptionTest.php | 149 ------------------------ 5 files changed, 297 deletions(-) delete mode 100644 tests/_files/ExceptionNamespaceTest.php delete mode 100644 tests/_files/ExceptionTest.php diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index d1aaeb2814d..704d8781d1f 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -1017,7 +1017,6 @@ public function runBare(): void } } - $this->setExpectedExceptionFromAnnotation(); $this->setDoesNotPerformAssertionsFromAnnotation(); foreach ($hookMethods['before'] as $method) { @@ -1903,37 +1902,6 @@ protected function onNotSuccessfulTest(\Throwable $t): void throw $t; } - private function setExpectedExceptionFromAnnotation(): void - { - if ($this->name === null) { - return; - } - - try { - $expectedException = TestUtil::getExpectedException( - \get_class($this), - $this->name - ); - - if ($expectedException !== false) { - $this->addWarning('The @expectedException, @expectedExceptionCode, @expectedExceptionMessage, and @expectedExceptionMessageRegExp annotations are deprecated. They will be removed in PHPUnit 9. Refactor your test to use expectException(), expectExceptionCode(), expectExceptionMessage(), or expectExceptionMessageRegExp() instead.'); - - $this->expectException($expectedException['class']); - - if ($expectedException['code'] !== null) { - $this->expectExceptionCode($expectedException['code']); - } - - if ($expectedException['message'] !== '') { - $this->expectExceptionMessage($expectedException['message']); - } elseif ($expectedException['message_regex'] !== '') { - $this->expectExceptionMessageRegExp($expectedException['message_regex']); - } - } - } catch (UtilException $e) { - } - } - /** * @throws Warning * @throws SkippedTestError diff --git a/src/Util/Annotation/DocBlock.php b/src/Util/Annotation/DocBlock.php index e1cc4847bb0..e4c51e7dcee 100644 --- a/src/Util/Annotation/DocBlock.php +++ b/src/Util/Annotation/DocBlock.php @@ -42,8 +42,6 @@ final class DocBlock private const REGEX_TEST_WITH = '/@testWith\s+/'; - private const REGEX_EXPECTED_EXCEPTION = '(@expectedException\s+([:.\w\\\\x7f-\xff]+)(?:[\t ]+(\S*))?(?:[\t ]+(\S*))?\s*$)m'; - /** @var string */ private $docComment; @@ -238,61 +236,6 @@ public function requirements(): array ); } - /** - * @return array|bool - * - * @psalm-return false|array{ - * class: class-string, - * code: int|string|null, - * message: string, - * message_regex: string - * } - */ - public function expectedException() - { - $docComment = (string) \substr($this->docComment, 3, -2); - - if (1 !== \preg_match(self::REGEX_EXPECTED_EXCEPTION, $docComment, $matches)) { - return false; - } - - /** @psalm-var class-string $class */ - $class = $matches[1]; - $annotations = $this->symbolAnnotations(); - $code = null; - $message = ''; - $messageRegExp = ''; - - if (isset($matches[2])) { - $message = \trim($matches[2]); - } elseif (isset($annotations['expectedExceptionMessage'])) { - $message = $this->parseAnnotationContent($annotations['expectedExceptionMessage'][0]); - } - - if (isset($annotations['expectedExceptionMessageRegExp'])) { - $messageRegExp = $this->parseAnnotationContent($annotations['expectedExceptionMessageRegExp'][0]); - } - - if (isset($matches[3])) { - $code = $matches[3]; - } elseif (isset($annotations['expectedExceptionCode'])) { - $code = $this->parseAnnotationContent($annotations['expectedExceptionCode'][0]); - } - - if (\is_numeric($code)) { - $code = (int) $code; - } elseif (\is_string($code) && \defined($code)) { - $code = (int) \constant($code); - } - - return [ - 'class' => $class, - 'code' => $code, - 'message' => $message, - 'message_regex' => $messageRegExp, - ]; - } - /** * Returns the provided data for a method. * diff --git a/src/Util/Test.php b/src/Util/Test.php index f16ebf7fdb9..9169652c54a 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -279,20 +279,6 @@ public static function getMissingRequirements(string $className, string $methodN return $missing; } - /** - * Returns the expected exception for a test. - * - * @return array|false - * - * @deprecated - * @codeCoverageIgnore - * @psalm-param class-string $className - */ - public static function getExpectedException(string $className, string $methodName) - { - return Registry::getInstance()->forMethod($className, $methodName)->expectedException(); - } - /** * Returns the provided data for a method. * diff --git a/tests/_files/ExceptionNamespaceTest.php b/tests/_files/ExceptionNamespaceTest.php deleted file mode 100644 index 5b03394fbc8..00000000000 --- a/tests/_files/ExceptionNamespaceTest.php +++ /dev/null @@ -1,45 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace My\Space; - -class ExceptionNamespaceTest extends \PHPUnit\Framework\TestCase -{ - /** - * Exception message - * - * @var string - */ - public const ERROR_MESSAGE = 'Exception namespace message'; - - /** - * Exception code - * - * @var int - */ - public const ERROR_CODE = 200; - - /** - * @expectedException Class - * @expectedExceptionMessage My\Space\ExceptionNamespaceTest::ERROR_MESSAGE - * @expectedExceptionCode My\Space\ExceptionNamespaceTest::ERROR_CODE - */ - public function testConstants(): void - { - } - - /** - * @expectedException Class - * @expectedExceptionCode My\Space\ExceptionNamespaceTest::UNKNOWN_CODE_CONSTANT - * @expectedExceptionMessage My\Space\ExceptionNamespaceTest::UNKNOWN_MESSAGE_CONSTANT - */ - public function testUnknownConstants(): void - { - } -} diff --git a/tests/_files/ExceptionTest.php b/tests/_files/ExceptionTest.php deleted file mode 100644 index 2d9fbcfb98c..00000000000 --- a/tests/_files/ExceptionTest.php +++ /dev/null @@ -1,149 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -use PHPUnit\Framework\TestCase; - -class ExceptionTest extends TestCase -{ - /** - * Exception message - * - * @var string - */ - public const ERROR_MESSAGE = 'Exception message'; - - /** - * Exception message - * - * @var string - */ - public const ERROR_MESSAGE_REGEX = '#regex#'; - - /** - * Exception code - * - * @var int - */ - public const ERROR_CODE = 500; - - /** - * @expectedException FooBarBaz - */ - public function testOne(): void - { - } - - /** - * @expectedException Foo_Bar_Baz - */ - public function testTwo(): void - { - } - - /** - * @expectedException Foo\Bar\Baz - */ - public function testThree(): void - { - } - - /** - * @expectedException ほげ - */ - public function testFour(): void - { - } - - /** - * @expectedException Class Message 1234 - */ - public function testFive(): void - { - } - - /** - * @expectedException Class - * @expectedExceptionMessage Message - * @expectedExceptionCode 1234 - */ - public function testSix(): void - { - } - - /** - * @expectedException Class - * @expectedExceptionMessage Message - * @expectedExceptionCode ExceptionCode - */ - public function testSeven(): void - { - } - - /** - * @expectedException Class - * @expectedExceptionMessage Message - * @expectedExceptionCode 0 - */ - public function testEight(): void - { - } - - /** - * @expectedException Class - * @expectedExceptionMessage ExceptionTest::ERROR_MESSAGE - * @expectedExceptionCode ExceptionTest::ERROR_CODE - */ - public function testNine(): void - { - } - - /** @expectedException Class */ - public function testSingleLine(): void - { - } - - /** - * @expectedException Class - * @expectedExceptionCode ExceptionTest::UNKNOWN_CODE_CONSTANT - * @expectedExceptionMessage ExceptionTest::UNKNOWN_MESSAGE_CONSTANT - */ - public function testUnknownConstants(): void - { - } - - /** - * @expectedException Class - * @expectedExceptionCode 1234 - * @expectedExceptionMessage Message - * @expectedExceptionMessageRegExp #regex# - */ - public function testWithRegexMessage(): void - { - } - - /** - * @expectedException Class - * @expectedExceptionCode 1234 - * @expectedExceptionMessage Message - * @expectedExceptionMessageRegExp ExceptionTest::ERROR_MESSAGE_REGEX - */ - public function testWithRegexMessageFromClassConstant(): void - { - } - - /** - * @expectedException Class - * @expectedExceptionCode 1234 - * @expectedExceptionMessage Message - * @expectedExceptionMessageRegExp ExceptionTest::UNKNOWN_MESSAGE_REGEX_CONSTANT - */ - public function testWithUnknowRegexMessageFromClassConstant(): void - { - } -}