From 4eb18b6bde58a140f42a1a00f9896d63b5cb7faa Mon Sep 17 00:00:00 2001 From: Oliver Maksimovic Date: Mon, 4 Mar 2019 08:46:52 +0100 Subject: [PATCH] #3342 Remove optional parameters of assertEquals() and assertNotEquals() #3339 Remove assertions (and helper methods) that operate on (non-public) attributes --- src/Framework/Assert.php | 760 +------------------------ src/Framework/Assert/Functions.php | 287 +--------- src/Framework/Constraint/Attribute.php | 30 - 3 files changed, 9 insertions(+), 1068 deletions(-) diff --git a/src/Framework/Assert.php b/src/Framework/Assert.php index b40a2866a75..458db0a25a6 100644 --- a/src/Framework/Assert.php +++ b/src/Framework/Assert.php @@ -15,7 +15,6 @@ use DOMElement; use PHPUnit\Framework\Constraint\ArrayHasKey; use PHPUnit\Framework\Constraint\ArraySubset; -use PHPUnit\Framework\Constraint\Attribute; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\Constraint\ClassHasAttribute; use PHPUnit\Framework\Constraint\ClassHasStaticAttribute; @@ -57,9 +56,6 @@ use PHPUnit\Util\InvalidArgumentHelper; use PHPUnit\Util\Type; use PHPUnit\Util\Xml; -use ReflectionClass; -use ReflectionException; -use ReflectionObject; use Traversable; /** @@ -180,49 +176,19 @@ public static function assertArrayNotHasKey($key, $array, string $message = ''): * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @throws Exception */ - public static function assertContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void + public static function assertContains($needle, $haystack, string $message = ''): void { - // @codeCoverageIgnoreStart - if (\is_string($haystack)) { - self::createWarning('Using assertContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringContainsString() or assertStringContainsStringIgnoringCase() instead.'); - } - - if (!$checkForObjectIdentity) { - self::createWarning('The optional $checkForObjectIdentity parameter of assertContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertContainsEquals() instead.'); - } - - if ($checkForNonObjectIdentity) { - self::createWarning('The optional $checkForNonObjectIdentity parameter of assertContains() is deprecated and will be removed in PHPUnit 9.'); - } - - if ($ignoreCase) { - self::createWarning('The optional $ignoreCase parameter of assertContains() is deprecated and will be removed in PHPUnit 9.'); - } - // @codeCoverageIgnoreEnd - if (\is_array($haystack) || (\is_object($haystack) && $haystack instanceof Traversable)) { $constraint = new TraversableContains( $needle, - $checkForObjectIdentity, - $checkForNonObjectIdentity - ); - } elseif (\is_string($haystack)) { - if (!\is_string($needle)) { - throw InvalidArgumentHelper::factory( - 1, - 'string' - ); - } - - $constraint = new StringContains( - $needle, - $ignoreCase + true, + false ); } else { throw InvalidArgumentHelper::factory( 2, - 'array, traversable or string' + 'array or traversable' ); } @@ -236,34 +202,6 @@ public static function assertContainsEquals($needle, iterable $haystack, string static::assertThat($haystack, $constraint, $message); } - /** - * Asserts that a haystack that is stored in a static attribute of a class - * or an attribute of an object contains a needle. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeContains($needle, string $haystackAttributeName, $haystackClassOrObject, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void - { - self::createWarning('assertAttributeContains() is deprecated and will be removed in PHPUnit 9.'); - - static::assertContains( - $needle, - static::readAttribute($haystackClassOrObject, $haystackAttributeName), - $message, - $ignoreCase, - $checkForObjectIdentity, - $checkForNonObjectIdentity - ); - } - /** * Asserts that a haystack does not contain a needle. * @@ -271,47 +209,15 @@ public static function assertAttributeContains($needle, string $haystackAttribut * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @throws Exception */ - public static function assertNotContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void + public static function assertNotContains($needle, $haystack, string $message = ''): void { - // @codeCoverageIgnoreStart - if (\is_string($haystack)) { - self::createWarning('Using assertNotContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringNotContainsString() or assertStringNotContainsStringIgnoringCase() instead.'); - } - - if (!$checkForObjectIdentity) { - self::createWarning('The optional $checkForObjectIdentity parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotContainsEquals() instead.'); - } - - if ($checkForNonObjectIdentity) { - self::createWarning('The optional $checkForNonObjectIdentity parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.'); - } - - if ($ignoreCase) { - self::createWarning('The optional $ignoreCase parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.'); - } - // @codeCoverageIgnoreEnd - if (\is_array($haystack) || (\is_object($haystack) && $haystack instanceof Traversable)) { $constraint = new LogicalNot( new TraversableContains( $needle, - $checkForObjectIdentity, - $checkForNonObjectIdentity - ) - ); - } elseif (\is_string($haystack)) { - if (!\is_string($needle)) { - throw InvalidArgumentHelper::factory( - 1, - 'string' - ); - } - - $constraint = new LogicalNot( - new StringContains( - $needle, - $ignoreCase + true, + false ) ); } else { @@ -331,34 +237,6 @@ public static function assertNotContainsEquals($needle, iterable $haystack, stri static::assertThat($haystack, $constraint, $message); } - /** - * Asserts that a haystack that is stored in a static attribute of a class - * or an attribute of an object does not contain a needle. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeNotContains($needle, string $haystackAttributeName, $haystackClassOrObject, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void - { - self::createWarning('assertAttributeNotContains() is deprecated and will be removed in PHPUnit 9.'); - - static::assertNotContains( - $needle, - static::readAttribute($haystackClassOrObject, $haystackAttributeName), - $message, - $ignoreCase, - $checkForObjectIdentity, - $checkForNonObjectIdentity - ); - } - /** * Asserts that a haystack contains only values of a given type. * @@ -399,33 +277,6 @@ public static function assertContainsOnlyInstancesOf(string $className, iterable ); } - /** - * Asserts that a haystack that is stored in a static attribute of a class - * or an attribute of an object contains only values of a given type. - * - * @param object|string $haystackClassOrObject - * @param bool $isNativeType - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeContainsOnly(string $type, string $haystackAttributeName, $haystackClassOrObject, ?bool $isNativeType = null, string $message = ''): void - { - self::createWarning('assertAttributeContainsOnly() is deprecated and will be removed in PHPUnit 9.'); - - static::assertContainsOnly( - $type, - static::readAttribute($haystackClassOrObject, $haystackAttributeName), - $isNativeType, - $message - ); - } - /** * Asserts that a haystack does not contain only values of a given type. * @@ -450,34 +301,6 @@ public static function assertNotContainsOnly(string $type, iterable $haystack, ? ); } - /** - * Asserts that a haystack that is stored in a static attribute of a class - * or an attribute of an object does not contain only values of a given - * type. - * - * @param object|string $haystackClassOrObject - * @param bool $isNativeType - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeNotContainsOnly(string $type, string $haystackAttributeName, $haystackClassOrObject, ?bool $isNativeType = null, string $message = ''): void - { - self::createWarning('assertAttributeNotContainsOnly() is deprecated and will be removed in PHPUnit 9.'); - - static::assertNotContainsOnly( - $type, - static::readAttribute($haystackClassOrObject, $haystackAttributeName), - $isNativeType, - $message - ); - } - /** * Asserts the number of elements of an array, Countable or Traversable. * @@ -500,31 +323,6 @@ public static function assertCount(int $expectedCount, $haystack, string $messag ); } - /** - * Asserts the number of elements of an array, Countable or Traversable - * that is stored in an attribute. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeCount(int $expectedCount, string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeCount() is deprecated and will be removed in PHPUnit 9.'); - - static::assertCount( - $expectedCount, - static::readAttribute($haystackClassOrObject, $haystackAttributeName), - $message - ); - } - /** * Asserts the number of elements of an array, Countable or Traversable. * @@ -547,31 +345,6 @@ public static function assertNotCount(int $expectedCount, $haystack, string $mes static::assertThat($haystack, $constraint, $message); } - /** - * Asserts the number of elements of an array, Countable or Traversable - * that is stored in an attribute. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeNotCount(int $expectedCount, string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeNotCount() is deprecated and will be removed in PHPUnit 9.'); - - static::assertNotCount( - $expectedCount, - static::readAttribute($haystackClassOrObject, $haystackAttributeName), - $message - ); - } - /** * Asserts that two variables are equal. * @@ -663,34 +436,6 @@ public static function assertEqualsWithDelta($expected, $actual, float $delta, s static::assertThat($actual, $constraint, $message); } - /** - * Asserts that a variable is equal to an attribute of an object. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeEquals($expected, string $actualAttributeName, $actualClassOrObject, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void - { - self::createWarning('assertAttributeEquals() is deprecated and will be removed in PHPUnit 9.'); - - static::assertEquals( - $expected, - static::readAttribute($actualClassOrObject, $actualAttributeName), - $message, - $delta, - $maxDepth, - $canonicalize, - $ignoreCase - ); - } - /** * Asserts that two variables are not equal. * @@ -795,34 +540,6 @@ public static function assertNotEqualsWithDelta($expected, $actual, float $delta static::assertThat($actual, $constraint, $message); } - /** - * Asserts that a variable is not equal to an attribute of an object. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeNotEquals($expected, string $actualAttributeName, $actualClassOrObject, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void - { - self::createWarning('assertAttributeNotEquals() is deprecated and will be removed in PHPUnit 9.'); - - static::assertNotEquals( - $expected, - static::readAttribute($actualClassOrObject, $actualAttributeName), - $message, - $delta, - $maxDepth, - $canonicalize, - $ignoreCase - ); - } - /** * Asserts that a variable is empty. * @@ -834,30 +551,6 @@ public static function assertEmpty($actual, string $message = ''): void static::assertThat($actual, static::isEmpty(), $message); } - /** - * Asserts that a static attribute of a class or an attribute of an object - * is empty. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeEmpty(string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeEmpty() is deprecated and will be removed in PHPUnit 9.'); - - static::assertEmpty( - static::readAttribute($haystackClassOrObject, $haystackAttributeName), - $message - ); - } - /** * Asserts that a variable is not empty. * @@ -869,30 +562,6 @@ public static function assertNotEmpty($actual, string $message = ''): void static::assertThat($actual, static::logicalNot(static::isEmpty()), $message); } - /** - * Asserts that a static attribute of a class or an attribute of an object - * is not empty. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeNotEmpty(string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeNotEmpty() is deprecated and will be removed in PHPUnit 9.'); - - static::assertNotEmpty( - static::readAttribute($haystackClassOrObject, $haystackAttributeName), - $message - ); - } - /** * Asserts that a value is greater than another value. * @@ -904,30 +573,6 @@ public static function assertGreaterThan($expected, $actual, string $message = ' static::assertThat($actual, static::greaterThan($expected), $message); } - /** - * Asserts that an attribute is greater than another value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeGreaterThan($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeGreaterThan() is deprecated and will be removed in PHPUnit 9.'); - - static::assertGreaterThan( - $expected, - static::readAttribute($actualClassOrObject, $actualAttributeName), - $message - ); - } - /** * Asserts that a value is greater than or equal to another value. * @@ -943,30 +588,6 @@ public static function assertGreaterThanOrEqual($expected, $actual, string $mess ); } - /** - * Asserts that an attribute is greater than or equal to another value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeGreaterThanOrEqual($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeGreaterThanOrEqual() is deprecated and will be removed in PHPUnit 9.'); - - static::assertGreaterThanOrEqual( - $expected, - static::readAttribute($actualClassOrObject, $actualAttributeName), - $message - ); - } - /** * Asserts that a value is smaller than another value. * @@ -978,30 +599,6 @@ public static function assertLessThan($expected, $actual, string $message = ''): static::assertThat($actual, static::lessThan($expected), $message); } - /** - * Asserts that an attribute is smaller than another value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeLessThan($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeLessThan() is deprecated and will be removed in PHPUnit 9.'); - - static::assertLessThan( - $expected, - static::readAttribute($actualClassOrObject, $actualAttributeName), - $message - ); - } - /** * Asserts that a value is smaller than or equal to another value. * @@ -1013,30 +610,6 @@ public static function assertLessThanOrEqual($expected, $actual, string $message static::assertThat($actual, static::lessThanOrEqual($expected), $message); } - /** - * Asserts that an attribute is smaller than or equal to another value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeLessThanOrEqual($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeLessThanOrEqual() is deprecated and will be removed in PHPUnit 9.'); - - static::assertLessThanOrEqual( - $expected, - static::readAttribute($actualClassOrObject, $actualAttributeName), - $message - ); - } - /** * Asserts that the contents of one file is equal to the contents of another * file. @@ -1581,31 +1154,6 @@ public static function assertSame($expected, $actual, string $message = ''): voi ); } - /** - * Asserts that a variable and an attribute of an object have the same type - * and value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeSame($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeSame() is deprecated and will be removed in PHPUnit 9.'); - - static::assertSame( - $expected, - static::readAttribute($actualClassOrObject, $actualAttributeName), - $message - ); - } - /** * Asserts that two variables do not have the same type and value. * Used on objects, it asserts that two variables do not reference @@ -1629,31 +1177,6 @@ public static function assertNotSame($expected, $actual, string $message = ''): ); } - /** - * Asserts that a variable and an attribute of an object do not have the - * same type and value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeNotSame($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void - { - self::createWarning('assertAttributeNotSame() is deprecated and will be removed in PHPUnit 9.'); - - static::assertNotSame( - $expected, - static::readAttribute($actualClassOrObject, $actualAttributeName), - $message - ); - } - /** * Asserts that a variable is of a given type. * @@ -1674,30 +1197,6 @@ public static function assertInstanceOf(string $expected, $actual, string $messa ); } - /** - * Asserts that an attribute is of a given type. - * - * @param object|string $classOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeInstanceOf(string $expected, string $attributeName, $classOrObject, string $message = ''): void - { - self::createWarning('assertAttributeInstanceOf() is deprecated and will be removed in PHPUnit 9.'); - - static::assertInstanceOf( - $expected, - static::readAttribute($classOrObject, $attributeName), - $message - ); - } - /** * Asserts that a variable is not of a given type. * @@ -1720,30 +1219,6 @@ public static function assertNotInstanceOf(string $expected, $actual, string $me ); } - /** - * Asserts that an attribute is of a given type. - * - * @param object|string $classOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeNotInstanceOf(string $expected, string $attributeName, $classOrObject, string $message = ''): void - { - self::createWarning('assertAttributeNotInstanceOf() is deprecated and will be removed in PHPUnit 9.'); - - static::assertNotInstanceOf( - $expected, - static::readAttribute($classOrObject, $attributeName), - $message - ); - } - /** * Asserts that a variable is of a given type. * @@ -1764,30 +1239,6 @@ public static function assertInternalType(string $expected, $actual, string $mes ); } - /** - * Asserts that an attribute is of a given type. - * - * @param object|string $classOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeInternalType(string $expected, string $attributeName, $classOrObject, string $message = ''): void - { - self::createWarning('assertAttributeInternalType() is deprecated and will be removed in PHPUnit 9.'); - - static::assertInternalType( - $expected, - static::readAttribute($classOrObject, $attributeName), - $message - ); - } - /** * Asserts that a variable is of type array. * @@ -2140,30 +1591,6 @@ public static function assertIsNotIterable($actual, string $message = ''): void ); } - /** - * Asserts that an attribute is of a given type. - * - * @param object|string $classOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ReflectionException - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function assertAttributeNotInternalType(string $expected, string $attributeName, $classOrObject, string $message = ''): void - { - self::createWarning('assertAttributeNotInternalType() is deprecated and will be removed in PHPUnit 9.'); - - static::assertNotInternalType( - $expected, - static::readAttribute($classOrObject, $attributeName), - $message - ); - } - /** * Asserts that a string matches a given regular expression. * @@ -2833,17 +2260,6 @@ public static function isNan(): IsNan return new IsNan; } - /** - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function attribute(Constraint $constraint, string $attributeName): Attribute - { - self::createWarning('attribute() is deprecated and will be removed in PHPUnit 9.'); - - return new Attribute($constraint, $attributeName); - } - public static function contains($value, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): TraversableContains { return new TraversableContains($value, $checkForObjectIdentity, $checkForNonObjectIdentity); @@ -2872,26 +2288,6 @@ public static function equalTo($value, float $delta = 0.0, int $maxDepth = 10, b return new IsEqual($value, $delta, $maxDepth, $canonicalize, $ignoreCase); } - /** - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function attributeEqualTo(string $attributeName, $value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): Attribute - { - self::createWarning('attributeEqualTo() is deprecated and will be removed in PHPUnit 9.'); - - return static::attribute( - static::equalTo( - $value, - $delta, - $maxDepth, - $canonicalize, - $ignoreCase - ), - $attributeName - ); - } - public static function isEmpty(): IsEmpty { return new IsEmpty; @@ -3015,148 +2411,6 @@ public static function fail(string $message = ''): void throw new AssertionFailedError($message); } - /** - * Returns the value of an attribute of a class or an object. - * This also works for attributes that are declared protected or private. - * - * @param object|string $classOrObject - * - * @throws Exception - * @throws ReflectionException - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function readAttribute($classOrObject, string $attributeName) - { - self::createWarning('readAttribute() is deprecated and will be removed in PHPUnit 9.'); - - if (!self::isValidAttributeName($attributeName)) { - throw InvalidArgumentHelper::factory(2, 'valid attribute name'); - } - - if (\is_string($classOrObject)) { - if (!\class_exists($classOrObject)) { - throw InvalidArgumentHelper::factory( - 1, - 'class name' - ); - } - - return static::getStaticAttribute( - $classOrObject, - $attributeName - ); - } - - if (\is_object($classOrObject)) { - return static::getObjectAttribute( - $classOrObject, - $attributeName - ); - } - - throw InvalidArgumentHelper::factory( - 1, - 'class name or object' - ); - } - - /** - * Returns the value of a static attribute. - * This also works for attributes that are declared protected or private. - * - * @throws Exception - * @throws ReflectionException - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function getStaticAttribute(string $className, string $attributeName) - { - self::createWarning('getStaticAttribute() is deprecated and will be removed in PHPUnit 9.'); - - if (!\class_exists($className)) { - throw InvalidArgumentHelper::factory(1, 'class name'); - } - - if (!self::isValidAttributeName($attributeName)) { - throw InvalidArgumentHelper::factory(2, 'valid attribute name'); - } - - $class = new ReflectionClass($className); - - while ($class) { - $attributes = $class->getStaticProperties(); - - if (\array_key_exists($attributeName, $attributes)) { - return $attributes[$attributeName]; - } - - $class = $class->getParentClass(); - } - - throw new Exception( - \sprintf( - 'Attribute "%s" not found in class.', - $attributeName - ) - ); - } - - /** - * Returns the value of an object's attribute. - * This also works for attributes that are declared protected or private. - * - * @param object $object - * - * @throws Exception - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3338 - * @codeCoverageIgnore - */ - public static function getObjectAttribute($object, string $attributeName) - { - self::createWarning('getObjectAttribute() is deprecated and will be removed in PHPUnit 9.'); - - if (!\is_object($object)) { - throw InvalidArgumentHelper::factory(1, 'object'); - } - - if (!self::isValidAttributeName($attributeName)) { - throw InvalidArgumentHelper::factory(2, 'valid attribute name'); - } - - try { - $reflector = new ReflectionObject($object); - - do { - try { - $attribute = $reflector->getProperty($attributeName); - - if (!$attribute || $attribute->isPublic()) { - return $object->$attributeName; - } - - $attribute->setAccessible(true); - $value = $attribute->getValue($object); - $attribute->setAccessible(false); - - return $value; - } catch (ReflectionException $e) { - } - } while ($reflector = $reflector->getParentClass()); - } catch (ReflectionException $e) { - } - - throw new Exception( - \sprintf( - 'Attribute "%s" not found in object.', - $attributeName - ) - ); - } - /** * Mark the test as incomplete. * diff --git a/src/Framework/Assert/Functions.php b/src/Framework/Assert/Functions.php index fffce4b24eb..776d49c1750 100644 --- a/src/Framework/Assert/Functions.php +++ b/src/Framework/Assert/Functions.php @@ -113,50 +113,22 @@ function assertArrayNotHasKey($key, $array, string $message = ''): void * @throws ExpectationFailedException * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException */ -function assertContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void +function assertContains($needle, $haystack, string $message = ''): void { Assert::assertContains(...\func_get_args()); } -/** - * Asserts that a haystack that is stored in a static attribute of a class - * or an attribute of an object contains a needle. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeContains($needle, string $haystackAttributeName, $haystackClassOrObject, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void -{ - Assert::assertAttributeContains(...\func_get_args()); -} - /** * Asserts that a haystack does not contain a needle. * * @throws ExpectationFailedException * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException */ -function assertNotContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void +function assertNotContains($needle, $haystack, string $message = ''): void { Assert::assertNotContains(...\func_get_args()); } -/** - * Asserts that a haystack that is stored in a static attribute of a class - * or an attribute of an object does not contain a needle. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeNotContains($needle, string $haystackAttributeName, $haystackClassOrObject, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): void -{ - Assert::assertAttributeNotContains(...\func_get_args()); -} - /** * Asserts that a haystack contains only values of a given type. * @@ -179,21 +151,6 @@ function assertContainsOnlyInstancesOf(string $className, iterable $haystack, st Assert::assertContainsOnlyInstancesOf(...\func_get_args()); } -/** - * Asserts that a haystack that is stored in a static attribute of a class - * or an attribute of an object contains only values of a given type. - * - * @param object|string $haystackClassOrObject - * @param bool $isNativeType - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeContainsOnly(string $type, string $haystackAttributeName, $haystackClassOrObject, ?bool $isNativeType = null, string $message = ''): void -{ - Assert::assertAttributeContainsOnly(...\func_get_args()); -} - /** * Asserts that a haystack does not contain only values of a given type. * @@ -205,22 +162,6 @@ function assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNative Assert::assertNotContainsOnly(...\func_get_args()); } -/** - * Asserts that a haystack that is stored in a static attribute of a class - * or an attribute of an object does not contain only values of a given - * type. - * - * @param object|string $haystackClassOrObject - * @param bool $isNativeType - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeNotContainsOnly(string $type, string $haystackAttributeName, $haystackClassOrObject, ?bool $isNativeType = null, string $message = ''): void -{ - Assert::assertAttributeNotContainsOnly(...\func_get_args()); -} - /** * Asserts the number of elements of an array, Countable or Traversable. * @@ -234,20 +175,6 @@ function assertCount(int $expectedCount, $haystack, string $message = ''): void Assert::assertCount(...\func_get_args()); } -/** - * Asserts the number of elements of an array, Countable or Traversable - * that is stored in an attribute. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeCount(int $expectedCount, string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void -{ - Assert::assertAttributeCount(...\func_get_args()); -} - /** * Asserts the number of elements of an array, Countable or Traversable. * @@ -261,20 +188,6 @@ function assertNotCount(int $expectedCount, $haystack, string $message = ''): vo Assert::assertNotCount(...\func_get_args()); } -/** - * Asserts the number of elements of an array, Countable or Traversable - * that is stored in an attribute. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeNotCount(int $expectedCount, string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void -{ - Assert::assertAttributeNotCount(...\func_get_args()); -} - /** * Asserts that two variables are equal. * @@ -286,19 +199,6 @@ function assertEquals($expected, $actual, string $message = '', float $delta = 0 Assert::assertEquals(...\func_get_args()); } -/** - * Asserts that a variable is equal to an attribute of an object. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeEquals($expected, string $actualAttributeName, $actualClassOrObject, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void -{ - Assert::assertAttributeEquals(...\func_get_args()); -} - /** * Asserts that two variables are not equal. * @@ -315,19 +215,6 @@ function assertNotEquals($expected, $actual, string $message = '', $delta = 0.0, Assert::assertNotEquals(...\func_get_args()); } -/** - * Asserts that a variable is not equal to an attribute of an object. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeNotEquals($expected, string $actualAttributeName, $actualClassOrObject, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void -{ - Assert::assertAttributeNotEquals(...\func_get_args()); -} - /** * Asserts that a variable is empty. * @@ -339,20 +226,6 @@ function assertEmpty($actual, string $message = ''): void Assert::assertEmpty(...\func_get_args()); } -/** - * Asserts that a static attribute of a class or an attribute of an object - * is empty. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeEmpty(string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void -{ - Assert::assertAttributeEmpty(...\func_get_args()); -} - /** * Asserts that a variable is not empty. * @@ -364,20 +237,6 @@ function assertNotEmpty($actual, string $message = ''): void Assert::assertNotEmpty(...\func_get_args()); } -/** - * Asserts that a static attribute of a class or an attribute of an object - * is not empty. - * - * @param object|string $haystackClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeNotEmpty(string $haystackAttributeName, $haystackClassOrObject, string $message = ''): void -{ - Assert::assertAttributeNotEmpty(...\func_get_args()); -} - /** * Asserts that a value is greater than another value. * @@ -389,19 +248,6 @@ function assertGreaterThan($expected, $actual, string $message = ''): void Assert::assertGreaterThan(...\func_get_args()); } -/** - * Asserts that an attribute is greater than another value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeGreaterThan($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void -{ - Assert::assertAttributeGreaterThan(...\func_get_args()); -} - /** * Asserts that a value is greater than or equal to another value. * @@ -413,19 +259,6 @@ function assertGreaterThanOrEqual($expected, $actual, string $message = ''): voi Assert::assertGreaterThanOrEqual(...\func_get_args()); } -/** - * Asserts that an attribute is greater than or equal to another value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeGreaterThanOrEqual($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void -{ - Assert::assertAttributeGreaterThanOrEqual(...\func_get_args()); -} - /** * Asserts that a value is smaller than another value. * @@ -437,19 +270,6 @@ function assertLessThan($expected, $actual, string $message = ''): void Assert::assertLessThan(...\func_get_args()); } -/** - * Asserts that an attribute is smaller than another value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeLessThan($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void -{ - Assert::assertAttributeLessThan(...\func_get_args()); -} - /** * Asserts that a value is smaller than or equal to another value. * @@ -461,19 +281,6 @@ function assertLessThanOrEqual($expected, $actual, string $message = ''): void Assert::assertLessThanOrEqual(...\func_get_args()); } -/** - * Asserts that an attribute is smaller than or equal to another value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeLessThanOrEqual($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void -{ - Assert::assertAttributeLessThanOrEqual(...\func_get_args()); -} - /** * Asserts that the contents of one file is equal to the contents of another * file. @@ -880,20 +687,6 @@ function assertSame($expected, $actual, string $message = ''): void Assert::assertSame(...\func_get_args()); } -/** - * Asserts that a variable and an attribute of an object have the same type - * and value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeSame($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void -{ - Assert::assertAttributeSame(...\func_get_args()); -} - /** * Asserts that two variables do not have the same type and value. * Used on objects, it asserts that two variables do not reference @@ -907,20 +700,6 @@ function assertNotSame($expected, $actual, string $message = ''): void Assert::assertNotSame(...\func_get_args()); } -/** - * Asserts that a variable and an attribute of an object do not have the - * same type and value. - * - * @param object|string $actualClassOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeNotSame($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void -{ - Assert::assertAttributeNotSame(...\func_get_args()); -} - /** * Asserts that a variable is of a given type. * @@ -932,19 +711,6 @@ function assertInstanceOf(string $expected, $actual, string $message = ''): void Assert::assertInstanceOf(...\func_get_args()); } -/** - * Asserts that an attribute is of a given type. - * - * @param object|string $classOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeInstanceOf(string $expected, string $attributeName, $classOrObject, string $message = ''): void -{ - Assert::assertAttributeInstanceOf(...\func_get_args()); -} - /** * Asserts that a variable is not of a given type. * @@ -956,19 +722,6 @@ function assertNotInstanceOf(string $expected, $actual, string $message = ''): v Assert::assertNotInstanceOf(...\func_get_args()); } -/** - * Asserts that an attribute is of a given type. - * - * @param object|string $classOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeNotInstanceOf(string $expected, string $attributeName, $classOrObject, string $message = ''): void -{ - Assert::assertAttributeNotInstanceOf(...\func_get_args()); -} - /** * Asserts that a variable is of a given type. * @@ -980,19 +733,6 @@ function assertInternalType(string $expected, $actual, string $message = ''): vo Assert::assertInternalType(...\func_get_args()); } -/** - * Asserts that an attribute is of a given type. - * - * @param object|string $classOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeInternalType(string $expected, string $attributeName, $classOrObject, string $message = ''): void -{ - Assert::assertAttributeInternalType(...\func_get_args()); -} - /** * Asserts that a variable is not of a given type. * @@ -1004,19 +744,6 @@ function assertNotInternalType(string $expected, $actual, string $message = ''): Assert::assertNotInternalType(...\func_get_args()); } -/** - * Asserts that an attribute is of a given type. - * - * @param object|string $classOrObject - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ -function assertAttributeNotInternalType(string $expected, string $attributeName, $classOrObject, string $message = ''): void -{ - Assert::assertAttributeNotInternalType(...\func_get_args()); -} - /** * Asserts that a string matches a given regular expression. * @@ -1404,11 +1131,6 @@ function isNan(): IsNan return Assert::isNan(); } -function attribute(Constraint $constraint, string $attributeName): Attribute -{ - return Assert::attribute(...\func_get_args()); -} - function contains($value, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false): TraversableContains { return Assert::contains(...\func_get_args()); @@ -1434,11 +1156,6 @@ function equalTo($value, float $delta = 0.0, int $maxDepth = 10, bool $canonical return Assert::equalTo(...\func_get_args()); } -function attributeEqualTo(string $attributeName, $value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): Attribute -{ - return Assert::attributeEqualTo(...\func_get_args()); -} - function isEmpty(): IsEmpty { return Assert::isEmpty(); diff --git a/src/Framework/Constraint/Attribute.php b/src/Framework/Constraint/Attribute.php index df2837fda54..af16a1339d4 100644 --- a/src/Framework/Constraint/Attribute.php +++ b/src/Framework/Constraint/Attribute.php @@ -9,9 +9,6 @@ */ namespace PHPUnit\Framework\Constraint; -use PHPUnit\Framework\Assert; -use PHPUnit\Framework\ExpectationFailedException; - final class Attribute extends Composite { /** @@ -26,33 +23,6 @@ public function __construct(Constraint $constraint, string $attributeName) $this->attributeName = $attributeName; } - /** - * Evaluates the constraint for parameter $other - * - * If $returnResult is set to false (the default), an exception is thrown - * in case of a failure. null is returned otherwise. - * - * If $returnResult is true, the result of the evaluation is returned as - * a boolean value instead: true in case of success, false in case of a - * failure. - * - * @throws ExpectationFailedException - * @throws \PHPUnit\Framework\Exception - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \ReflectionException - */ - public function evaluate($other, string $description = '', bool $returnResult = false) - { - return parent::evaluate( - Assert::readAttribute( - $other, - $this->attributeName - ), - $description, - $returnResult - ); - } - /** * Returns a string representation of the constraint. */