From 9bb739fdbe7ffbd83f2c4aca9ea9bc26ba491509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 3 Jan 2022 19:09:55 +0100 Subject: [PATCH] Fix: Deprecate assertions --- CHANGELOG.md | 2 + README.md | 2 + phpstan-baseline.neon | 171 ++++++++++++++++++++++++++++++++++++++++++ psalm-baseline.xml | 51 +++++++++++++ src/Helper.php | 30 ++++++++ 5 files changed, 256 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40fee4e..a0cf6ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Deprecated all data providers ([#526]), by [@localheinz] - Dropped support for PHP 7.2 ([#530]), by [@localheinz] - Dropped support for PHP 7.3 ([#540]), by [@localheinz] +- Deprecated all assertions ([#548]), by [@localheinz] For a full diff see [`1.5.0...main`][1.5.0...main]. @@ -192,6 +193,7 @@ For a full diff see [`0.7.0...0.8.0`][0.7.0...0.8.0]. [#526]: https://github.com/ergebnis/test-util/pull/526 [#530]: https://github.com/ergebnis/test-util/pull/530 [#540]: https://github.com/ergebnis/test-util/pull/540 +[#548]: https://github.com/ergebnis/test-util/pull/548 [@dependabot]: https://github.com/dependabot [@ergebnis]: https://github.com/ergebnis diff --git a/README.md b/README.md index b6f0ab0..9457f75 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ For reference, see [`fzaninotto/faker`](https://github.com/fzaninotto/Faker). #### Additional Assertions +:exclamation: The assertions have been deprecated. Stop using them. + In addition to the assertions made available by extending from `PHPUnit\Framework\TestCase`, the `Helper` trait provides the following assertions: * `assertClassesAreAbstractOrFinal(string $directory, array $excludeClassNames = [])` diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2bb9ef5..d1d7490 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1009,6 +1009,15 @@ parameters: count: 1 path: test/Unit/DataProvider/StringProviderTest.php + - + message: + """ + #^Call to deprecated method assertClassExtends\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\Exception\\\\EmptyValuesTest\\: + Will be removed with the next major release\\.$# + """ + count: 1 + path: test/Unit/Exception/EmptyValuesTest.php + - message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\Exception\\\\EmptyValuesTest\\:\\:assertClassExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#" count: 1 @@ -1104,6 +1113,15 @@ parameters: count: 1 path: test/Unit/Exception/EmptyValuesTest.php + - + message: + """ + #^Call to deprecated method assertClassExtends\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\Exception\\\\InvalidExcludeClassNameTest\\: + Will be removed with the next major release\\.$# + """ + count: 1 + path: test/Unit/Exception/InvalidExcludeClassNameTest.php + - message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\Exception\\\\InvalidExcludeClassNameTest\\:\\:assertClassExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#" count: 1 @@ -1199,6 +1217,15 @@ parameters: count: 1 path: test/Unit/Exception/InvalidExcludeClassNameTest.php + - + message: + """ + #^Call to deprecated method assertClassExtends\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\Exception\\\\NonExistentDirectoryTest\\: + Will be removed with the next major release\\.$# + """ + count: 1 + path: test/Unit/Exception/NonExistentDirectoryTest.php + - message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\Exception\\\\NonExistentDirectoryTest\\:\\:assertClassExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#" count: 1 @@ -1294,6 +1321,15 @@ parameters: count: 1 path: test/Unit/Exception/NonExistentDirectoryTest.php + - + message: + """ + #^Call to deprecated method assertClassExtends\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\Exception\\\\NonExistentExcludeClassTest\\: + Will be removed with the next major release\\.$# + """ + count: 1 + path: test/Unit/Exception/NonExistentExcludeClassTest.php + - message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\Exception\\\\NonExistentExcludeClassTest\\:\\:assertClassExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#" count: 1 @@ -1389,6 +1425,141 @@ parameters: count: 1 path: test/Unit/Exception/NonExistentExcludeClassTest.php + - + message: + """ + #^Call to deprecated method assertClassExists\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 2 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertClassExtends\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 4 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertClassImplementsInterface\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 4 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertClassIsAbstract\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 3 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertClassIsFinal\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 3 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertClassSatisfiesSpecification\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 4 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertClassUsesTrait\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 4 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertClassesAreAbstractOrFinal\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 8 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertClassesHaveTests\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 9 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertClassyConstructsSatisfySpecification\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 8 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertInterfaceExists\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 2 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertInterfaceExtends\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 4 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertInterfaceSatisfiesSpecification\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 4 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertTraitExists\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 2 + path: test/Unit/HelperTest.php + + - + message: + """ + #^Call to deprecated method assertTraitSatisfiesSpecification\\(\\) of class Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\HelperTest\\: + Will be removed with the next major release\\.$# + """ + count: 4 + path: test/Unit/HelperTest.php + - message: "#^Generator expects key type string, int given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 6d67ca2..8eb398a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -58,6 +58,21 @@ + + self::assertClassExists($className) + self::assertClassExists($className) + self::assertClassExists($className) + self::assertClassExists($className) + self::assertClassExists($className) + self::assertClassExists($className) + self::assertClassExists($parentClassName) + self::assertInterfaceExists($interfaceName) + self::assertInterfaceExists($interfaceName) + self::assertInterfaceExists($interfaceName) + self::assertInterfaceExists($parentInterfaceName) + self::assertTraitExists($traitName) + self::assertTraitExists($traitName) + $excludeClassyName $excludeClassyName @@ -144,11 +159,29 @@ StringProvider::withWhitespace() + + + self::assertClassExtends(\InvalidArgumentException::class, EmptyValues::class) + + + + self::assertClassExtends(\InvalidArgumentException::class, InvalidExcludeClassName::class) + \Generator<array<null|array|bool|float|int|resource|\stdClass>> + + + self::assertClassExtends(\InvalidArgumentException::class, NonExistentDirectory::class) + + + + + self::assertClassExtends(\InvalidArgumentException::class, NonExistentExcludeClass::class) + + $className @@ -168,6 +201,24 @@ $traitName $traitName + + self::assertClassExists($className) + self::assertClassExists($className) + self::assertClassIsAbstract($className) + self::assertClassIsAbstract($className) + self::assertClassIsAbstract($className) + self::assertClassIsFinal($className) + self::assertClassIsFinal($className) + self::assertClassIsFinal($className) + self::assertClassesAreAbstractOrFinal($directory) + self::assertClassesAreAbstractOrFinal($directory) + self::assertClassesAreAbstractOrFinal($directory) + self::assertClassesAreAbstractOrFinal($directory) + self::assertInterfaceExists($interfaceName) + self::assertInterfaceExists($interfaceName) + self::assertTraitExists($traitName) + self::assertTraitExists($traitName) + \Generator<string, array<string>> diff --git a/src/Helper.php b/src/Helper.php index 5fcfcd4..3df8ced 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -46,6 +46,8 @@ final protected static function faker(string $locale = 'en_US'): Generator } /** + * @deprecated Will be removed with the next major release. + * * Asserts that classes in a directory are either abstract or final. * * Useful to prevent long inheritance chains. @@ -80,6 +82,8 @@ static function (string $className): bool { } /** + * @deprecated Will be removed with the next major release. + * * Asserts that classes in a directory have matching test classes extending from PHPUnit\Framework\TestCase. * * @phpstam-param array $excludeClassyNames @@ -180,6 +184,8 @@ final protected static function assertClassesHaveTests(string $directory, string } /** + * @deprecated Will be removed with the next major release. + * * Asserts that all classes, interfaces, and traits found in a directory satisfy a specification. * * Useful for asserting that production and test code conforms to certain requirements. @@ -231,6 +237,8 @@ final protected static function assertClassyConstructsSatisfySpecification(calla } /** + * @deprecated Will be removed with the next major release. + * * Asserts that a class exists. */ final protected static function assertClassExists(string $className): void @@ -242,6 +250,8 @@ final protected static function assertClassExists(string $className): void } /** + * @deprecated Will be removed with the next major release. + * * Asserts that a class extends from a parent class. * * @phpstan-param class-string $parentClassName @@ -266,6 +276,8 @@ final protected static function assertClassExtends(string $parentClassName, stri } /** + * @deprecated Will be removed with the next major release. + * * Asserts that a class implements an interface. * * @phpstan-param class-string $interfaceName @@ -290,6 +302,8 @@ final protected static function assertClassImplementsInterface(string $interface } /** + * @deprecated Will be removed with the next major release. + * * Asserts that a class is abstract. * * @phpstan-param class-string $className @@ -310,6 +324,8 @@ final protected static function assertClassIsAbstract(string $className): void } /** + * @deprecated Will be removed with the next major release. + * * Asserts that a class is final. * * Useful to prevent long inheritance chains. @@ -332,6 +348,8 @@ final protected static function assertClassIsFinal(string $className): void } /** + * @deprecated Will be removed with the next major release. + * * Asserts that a class satisfies a specification. * * The specification will be invoked with a single argument, the class name, and should return true or false. @@ -352,6 +370,8 @@ final protected static function assertClassSatisfiesSpecification(callable $spec } /** + * @deprecated Will be removed with the next major release. + * * Asserts that a class uses a trait. * * @phpstan-param class-string $traitName @@ -373,6 +393,8 @@ final protected static function assertClassUsesTrait(string $traitName, string $ } /** + * @deprecated Will be removed with the next major release. + * * Asserts that an interface exists. */ final protected static function assertInterfaceExists(string $interfaceName): void @@ -384,6 +406,8 @@ final protected static function assertInterfaceExists(string $interfaceName): vo } /** + * @deprecated Will be removed with the next major release. + * * Asserts that an interface extends a parent interface. * * @phpstan-param class-string $parentInterfaceName @@ -408,6 +432,8 @@ final protected static function assertInterfaceExtends(string $parentInterfaceNa } /** + * @deprecated Will be removed with the next major release. + * * Asserts that an interface satisfies a specification. * * The specification will be invoked with a single argument, the class name, and should return true or false. @@ -428,6 +454,8 @@ final protected static function assertInterfaceSatisfiesSpecification(callable $ } /** + * @deprecated Will be removed with the next major release. + * * Asserts that a trait exists. */ final protected static function assertTraitExists(string $traitName): void @@ -439,6 +467,8 @@ final protected static function assertTraitExists(string $traitName): void } /** + * @deprecated Will be removed with the next major release. + * * Asserts that a trait satisfies a specification. * * The specification will be invoked with a single argument, the class name, and should return true or false.