Skip to content

Commit

Permalink
Closes #3494
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 22, 2019
1 parent 9d840a8 commit 689a81d
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 103 deletions.
1 change: 1 addition & 0 deletions ChangeLog-8.0.md
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/Framework/Assert.php
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/Framework/Constraint/ArraySubset.php
Expand Up @@ -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
Expand Down
99 changes: 0 additions & 99 deletions tests/unit/Framework/AssertTest.php
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/Util/ConfigurationTest.php
Expand Up @@ -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
Expand Down

0 comments on commit 689a81d

Please sign in to comment.