From 689a81dae20c15a7ed177bf6bf07457c9e3b038c Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Tue, 22 Jan 2019 14:54:19 +0100 Subject: [PATCH] Closes #3494 --- ChangeLog-8.0.md | 1 + src/Framework/Assert.php | 3 + src/Framework/Constraint/ArraySubset.php | 1 + tests/unit/Framework/AssertTest.php | 99 ------------------------ tests/unit/Util/ConfigurationTest.php | 4 - 5 files changed, 5 insertions(+), 103 deletions(-) diff --git a/ChangeLog-8.0.md b/ChangeLog-8.0.md index 506b4f4b07c..0781789b3fd 100644 --- a/ChangeLog-8.0.md +++ b/ChangeLog-8.0.md @@ -20,6 +20,7 @@ All notable changes of the PHPUnit 8.0 release series are documented in this fil * Implemented [#3444](https://github.com/sebastianbergmann/phpunit/pull/3444): Consider data provider that provides data with duplicate keys to be invalid * Implemented [#3467](https://github.com/sebastianbergmann/phpunit/pull/3467): Code location hints for `@requires` annotations as well as `--SKIPIF--`, `--EXPECT--`, `--EXPECTF--`, `--EXPECTREGEX--`, and `--{SECTION}_EXTERNAL--` sections of PHPT tests * Implemented [#3481](https://github.com/sebastianbergmann/phpunit/pull/3481): Improved `--help` output +* Implemented [#3494](https://github.com/sebastianbergmann/phpunit/issues/3494): Deprecate `assertArraySubset()` ### Removed diff --git a/src/Framework/Assert.php b/src/Framework/Assert.php index a1aa9af01e9..a7626b1aea3 100644 --- a/src/Framework/Assert.php +++ b/src/Framework/Assert.php @@ -113,10 +113,13 @@ public static function assertArrayHasKey($key, $array, string $message = ''): vo * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @throws Exception * + * @codeCoverageIgnore * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3494 */ public static function assertArraySubset($subset, $array, bool $checkForObjectIdentity = false, string $message = ''): void { + self::createWarning('assertArraySubset() is deprecated and will be removed in PHPUnit 9.'); + if (!(\is_array($subset) || $subset instanceof ArrayAccess)) { throw InvalidArgumentHelper::factory( 1, diff --git a/src/Framework/Constraint/ArraySubset.php b/src/Framework/Constraint/ArraySubset.php index 7b971939db1..284c63d8445 100644 --- a/src/Framework/Constraint/ArraySubset.php +++ b/src/Framework/Constraint/ArraySubset.php @@ -18,6 +18,7 @@ * Uses array_replace_recursive() to check if a key value subset is part of the * subject array. * + * @codeCoverageIgnore * @deprecated https://github.com/sebastianbergmann/phpunit/issues/3494 */ final class ArraySubset extends Constraint diff --git a/tests/unit/Framework/AssertTest.php b/tests/unit/Framework/AssertTest.php index e6ef2bf8201..4d445f0aa1f 100644 --- a/tests/unit/Framework/AssertTest.php +++ b/tests/unit/Framework/AssertTest.php @@ -69,105 +69,6 @@ public function testAssertArrayHasIntegerKey(): void $this->assertArrayHasKey(1, ['foo']); } - public function testAssertArraySubset(): void - { - $array = [ - 'a' => 'item a', - 'b' => 'item b', - 'c' => ['a2' => 'item a2', 'b2' => 'item b2'], - 'd' => ['a2' => ['a3' => 'item a3', 'b3' => 'item b3']], - ]; - - $this->assertArraySubset(['a' => 'item a', 'c' => ['a2' => 'item a2']], $array); - $this->assertArraySubset(['a' => 'item a', 'd' => ['a2' => ['b3' => 'item b3']]], $array); - - $arrayAccessData = new \ArrayObject($array); - - $this->assertArraySubset(['a' => 'item a', 'c' => ['a2' => 'item a2']], $arrayAccessData); - $this->assertArraySubset(['a' => 'item a', 'd' => ['a2' => ['b3' => 'item b3']]], $arrayAccessData); - - try { - $this->assertArraySubset(['a' => 'bad value'], $array); - } catch (AssertionFailedError $e) { - } - - try { - $this->assertArraySubset(['d' => ['a2' => ['bad index' => 'item b3']]], $array); - } catch (AssertionFailedError $e) { - return; - } - - $this->fail(); - } - - public function testAssertArraySubsetWithDeepNestedArrays(): void - { - $array = [ - 'path' => [ - 'to' => [ - 'the' => [ - 'cake' => 'is a lie', - ], - ], - ], - ]; - - $this->assertArraySubset(['path' => []], $array); - $this->assertArraySubset(['path' => ['to' => []]], $array); - $this->assertArraySubset(['path' => ['to' => ['the' => []]]], $array); - $this->assertArraySubset(['path' => ['to' => ['the' => ['cake' => 'is a lie']]]], $array); - - $this->expectException(AssertionFailedError::class); - - $this->assertArraySubset(['path' => ['to' => ['the' => ['cake' => 'is not a lie']]]], $array); - } - - public function testAssertArraySubsetWithNoStrictCheckAndObjects(): void - { - $obj = new \stdClass; - $reference = &$obj; - $array = ['a' => $obj]; - - $this->assertArraySubset(['a' => $reference], $array); - $this->assertArraySubset(['a' => new \stdClass], $array); - } - - public function testAssertArraySubsetWithStrictCheckAndObjects(): void - { - $obj = new \stdClass; - $reference = &$obj; - $array = ['a' => $obj]; - - $this->assertArraySubset(['a' => $reference], $array, true); - - $this->expectException(AssertionFailedError::class); - - $this->assertArraySubset(['a' => new \stdClass], $array, true); - } - - /** - * @testdox assertArraySubset($_dataName) raises exception - * @dataProvider assertArraySubsetInvalidArgumentProvider - * - * @throws Exception - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - */ - public function testAssertArraySubsetRaisesExceptionForInvalidArguments($partial, $subject): void - { - $this->expectException(Exception::class); - - $this->assertArraySubset($partial, $subject); - } - - public function assertArraySubsetInvalidArgumentProvider(): array - { - return [ - 'false, []' => [false, []], - '[], false' => [[], false], - ]; - } - public function testAssertArrayNotHasKeyThrowsExceptionForInvalidFirstArgument(): void { $this->expectException(Exception::class); diff --git a/tests/unit/Util/ConfigurationTest.php b/tests/unit/Util/ConfigurationTest.php index 25549eb1194..f52721d4ece 100644 --- a/tests/unit/Util/ConfigurationTest.php +++ b/tests/unit/Util/ConfigurationTest.php @@ -77,10 +77,6 @@ public function testInvalidConfigurationGeneratesValidationErrors(): void $configurationInstance = Configuration::getInstance($configurationFilename); $this->assertTrue($configurationInstance->hasValidationErrors()); - $this->assertArraySubset( - [1 => ["Element 'phpunit', attribute 'colors': 'Something else' is not a valid value of the atomic type 'xs:boolean'."]], - $configurationInstance->getValidationErrors() - ); } public function testShouldUseDefaultValuesForInvalidIntegers(): void