From da4c344ea2227005c5c72b0f1f87e8031a25d9e7 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 7 Oct 2024 13:21:37 +0200 Subject: [PATCH] Closes #5473 --- ChangeLog-12.0.md | 1 + DEPRECATIONS.md | 7 --- src/Framework/Assert.php | 55 ------------------- src/Framework/Assert/Functions.php | 36 ------------ .../event/_files/DeprecatedAssertionTest.php | 20 ------- .../event/deprecated-assertion.phpt | 39 ------------- .../assertStringNotMatchesFormatFileTest.php | 34 ------------ .../assertStringNotMatchesFormatTest.php | 34 ------------ 8 files changed, 1 insertion(+), 225 deletions(-) delete mode 100644 tests/end-to-end/event/_files/DeprecatedAssertionTest.php delete mode 100644 tests/end-to-end/event/deprecated-assertion.phpt delete mode 100644 tests/unit/Framework/Assert/assertStringNotMatchesFormatFileTest.php delete mode 100644 tests/unit/Framework/Assert/assertStringNotMatchesFormatTest.php diff --git a/ChangeLog-12.0.md b/ChangeLog-12.0.md index 7ce8e5fa7fa..19db908d0cb 100644 --- a/ChangeLog-12.0.md +++ b/ChangeLog-12.0.md @@ -20,6 +20,7 @@ All notable changes of the PHPUnit 12.0 release series are documented in this fi * [#5314](https://github.com/sebastianbergmann/phpunit/issues/5314): `MockBuilder::getMockForAbstractClass()` * [#5316](https://github.com/sebastianbergmann/phpunit/issues/5316): `MockBuilder::enableArgumentCloning()` and `MockBuilder::disableArgumentCloning()` * [#5321](https://github.com/sebastianbergmann/phpunit/issues/5321): `MockBuilder::addMethods()` +* [#5473](https://github.com/sebastianbergmann/phpunit/issues/5473): `assertStringNotMatchesFormat()` and `assertStringNotMatchesFormatFile()` * [#5978](https://github.com/sebastianbergmann/phpunit/issues/5978): Support for PHP 8.2 [12.0.0]: https://github.com/sebastianbergmann/phpunit/compare/11.5...main diff --git a/DEPRECATIONS.md b/DEPRECATIONS.md index 98b7bc378c1..6707d535f6e 100644 --- a/DEPRECATIONS.md +++ b/DEPRECATIONS.md @@ -6,13 +6,6 @@ This functionality is currently [hard-deprecated](https://phpunit.de/backward-co ### Writing Tests -#### Assertions, Constraints, and Expectations - -| Issue | Description | Since | Replacement | -|-------------------------------------------------------------------|------------------------------------------------|--------|-------------| -| [#5472](https://github.com/sebastianbergmann/phpunit/issues/5472) | `TestCase::assertStringNotMatchesFormat()` | 10.4.0 | | -| [#5472](https://github.com/sebastianbergmann/phpunit/issues/5472) | `TestCase::assertStringNotMatchesFormatFile()` | 10.4.0 | | - #### Test Double API | Issue | Description | Since | Replacement | diff --git a/src/Framework/Assert.php b/src/Framework/Assert.php index 067dc5a115f..705badf22de 100644 --- a/src/Framework/Assert.php +++ b/src/Framework/Assert.php @@ -19,7 +19,6 @@ use ArrayAccess; use Countable; use Generator; -use PHPUnit\Event; use PHPUnit\Framework\Constraint\ArrayHasKey; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\Constraint\Constraint; @@ -1747,29 +1746,6 @@ final public static function assertStringMatchesFormat(string $format, string $s self::assertThat($string, new StringMatchesFormatDescription($format), $message); } - /** - * Asserts that a string does not match a given format string. - * - * @throws ExpectationFailedException - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5472 - */ - final public static function assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void - { - Event\Facade::emitter()->testTriggeredPhpunitDeprecation( - null, - 'assertStringNotMatchesFormat() is deprecated and will be removed in PHPUnit 12 without replacement.', - ); - - self::assertThat( - $string, - new LogicalNot( - new StringMatchesFormatDescription($format), - ), - $message, - ); - } - /** * Asserts that a string matches a given format file. * @@ -1792,37 +1768,6 @@ final public static function assertStringMatchesFormatFile(string $formatFile, s ); } - /** - * Asserts that a string does not match a given format string. - * - * @throws ExpectationFailedException - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5472 - */ - final public static function assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void - { - Event\Facade::emitter()->testTriggeredPhpunitDeprecation( - null, - 'assertStringNotMatchesFormatFile() is deprecated and will be removed in PHPUnit 12 without replacement.', - ); - - self::assertFileExists($formatFile, $message); - - $formatDescription = file_get_contents($formatFile); - - self::assertIsString($formatDescription); - - self::assertThat( - $string, - new LogicalNot( - new StringMatchesFormatDescription( - $formatDescription, - ), - ), - $message, - ); - } - /** * Asserts that a string starts with a given prefix. * diff --git a/src/Framework/Assert/Functions.php b/src/Framework/Assert/Functions.php index 7c01eebd94a..d3263264c6c 100644 --- a/src/Framework/Assert/Functions.php +++ b/src/Framework/Assert/Functions.php @@ -1977,24 +1977,6 @@ function assertStringMatchesFormat(string $format, string $string, string $messa } } -if (!function_exists('PHPUnit\Framework\assertStringNotMatchesFormat')) { - /** - * Asserts that a string does not match a given format string. - * - * @throws ExpectationFailedException - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5472 - * - * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit - * - * @see Assert::assertStringNotMatchesFormat - */ - function assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void - { - Assert::assertStringNotMatchesFormat(...func_get_args()); - } -} - if (!function_exists('PHPUnit\Framework\assertStringMatchesFormatFile')) { /** * Asserts that a string matches a given format file. @@ -2011,24 +1993,6 @@ function assertStringMatchesFormatFile(string $formatFile, string $string, strin } } -if (!function_exists('PHPUnit\Framework\assertStringNotMatchesFormatFile')) { - /** - * Asserts that a string does not match a given format string. - * - * @throws ExpectationFailedException - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5472 - * - * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit - * - * @see Assert::assertStringNotMatchesFormatFile - */ - function assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void - { - Assert::assertStringNotMatchesFormatFile(...func_get_args()); - } -} - if (!function_exists('PHPUnit\Framework\assertStringStartsWith')) { /** * Asserts that a string starts with a given prefix. diff --git a/tests/end-to-end/event/_files/DeprecatedAssertionTest.php b/tests/end-to-end/event/_files/DeprecatedAssertionTest.php deleted file mode 100644 index a0d03c77bac..00000000000 --- a/tests/end-to-end/event/_files/DeprecatedAssertionTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace PHPUnit\TestFixture; - -use PHPUnit\Framework\TestCase; - -final class DeprecatedAssertionTest extends TestCase -{ - public function testUsingDeprecatedAssertion(): void - { - $this->assertStringNotMatchesFormat('*%s*', '**'); - } -} diff --git a/tests/end-to-end/event/deprecated-assertion.phpt b/tests/end-to-end/event/deprecated-assertion.phpt deleted file mode 100644 index f60e71934a3..00000000000 --- a/tests/end-to-end/event/deprecated-assertion.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -The right events are emitted in the right order for a successful test that uses a deprecated assertion ---FILE-- -run($_SERVER['argv']); - -print file_get_contents($traceFile); - -unlink($traceFile); ---EXPECTF-- -PHPUnit Started (PHPUnit %s using %s) -Test Runner Configured -Event Facade Sealed -Test Suite Loaded (1 test) -Test Runner Started -Test Suite Sorted -Test Runner Execution Started (1 test) -Test Suite Started (PHPUnit\TestFixture\DeprecatedAssertionTest, 1 test) -Test Preparation Started (PHPUnit\TestFixture\DeprecatedAssertionTest::testUsingDeprecatedAssertion) -Test Prepared (PHPUnit\TestFixture\DeprecatedAssertionTest::testUsingDeprecatedAssertion) -Test Triggered PHPUnit Deprecation (PHPUnit\TestFixture\DeprecatedAssertionTest::testUsingDeprecatedAssertion) -assertStringNotMatchesFormat() is deprecated and will be removed in PHPUnit 12 without replacement. -Test Passed (PHPUnit\TestFixture\DeprecatedAssertionTest::testUsingDeprecatedAssertion) -Test Finished (PHPUnit\TestFixture\DeprecatedAssertionTest::testUsingDeprecatedAssertion) -Test Suite Finished (PHPUnit\TestFixture\DeprecatedAssertionTest, 1 test) -Test Runner Execution Finished -Test Runner Finished -PHPUnit Finished (Shell Exit Code: 0) diff --git a/tests/unit/Framework/Assert/assertStringNotMatchesFormatFileTest.php b/tests/unit/Framework/Assert/assertStringNotMatchesFormatFileTest.php deleted file mode 100644 index f59a0135316..00000000000 --- a/tests/unit/Framework/Assert/assertStringNotMatchesFormatFileTest.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace PHPUnit\Framework; - -use PHPUnit\Framework\Attributes\CoversMethod; -use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; -use PHPUnit\Framework\Attributes\Small; -use PHPUnit\Framework\Attributes\TestDox; - -#[CoversMethod(Assert::class, 'assertStringNotMatchesFormatFile')] -#[TestDox('assertStringNotMatchesFormatFile()')] -#[Small] -#[IgnorePhpunitDeprecations] -final class assertStringNotMatchesFormatFileTest extends TestCase -{ - public function testSucceedsWhenConstraintEvaluatesToTrue(): void - { - $this->assertStringNotMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "BAR\n"); - } - - public function testFailsWhenConstraintEvaluatesToFalse(): void - { - $this->expectException(AssertionFailedError::class); - - $this->assertStringNotMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "FOO\n"); - } -} diff --git a/tests/unit/Framework/Assert/assertStringNotMatchesFormatTest.php b/tests/unit/Framework/Assert/assertStringNotMatchesFormatTest.php deleted file mode 100644 index a513995f508..00000000000 --- a/tests/unit/Framework/Assert/assertStringNotMatchesFormatTest.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace PHPUnit\Framework; - -use PHPUnit\Framework\Attributes\CoversMethod; -use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; -use PHPUnit\Framework\Attributes\Small; -use PHPUnit\Framework\Attributes\TestDox; - -#[CoversMethod(Assert::class, 'assertStringNotMatchesFormat')] -#[TestDox('assertStringNotMatchesFormat()')] -#[Small] -#[IgnorePhpunitDeprecations] -final class assertStringNotMatchesFormatTest extends TestCase -{ - public function testSucceedsWhenConstraintEvaluatesToTrue(): void - { - $this->assertStringNotMatchesFormat('*%s*', '**'); - } - - public function testFailsWhenConstraintEvaluatesToFalse(): void - { - $this->expectException(AssertionFailedError::class); - - $this->assertStringMatchesFormat('*%s*', '**'); - } -}