Skip to content

Commit 9e6c5fa

Browse files
committed
Conform to new Coding Standard
1 parent ab7001d commit 9e6c5fa

File tree

5 files changed

+46
-22
lines changed

5 files changed

+46
-22
lines changed

phpcs.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
<file>tests</file>
1212

1313
<rule ref="DMS"/>
14+
15+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators.DisallowedEqualOperator">
16+
<exclude-pattern>src/Constraint/ArraySubset.php</exclude-pattern>
17+
</rule>
1418
</ruleset>

src/ArraySubsetAsserts.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
use ArrayAccess;
77
use DMS\PHPUnitExtensions\ArraySubset\Constraint\ArraySubset;
88
use Exception;
9-
use function is_array;
109
use PHPUnit\Framework\Assert as PhpUnitAssert;
1110
use PHPUnit\Framework\ExpectationFailedException;
1211
use PHPUnit\Util\InvalidArgumentHelper;
1312
use SebastianBergmann\RecursionContext\InvalidArgumentException;
13+
use function is_array;
1414

1515
trait ArraySubsetAsserts
1616
{
1717
/**
1818
* Asserts that an array has a specified subset.
1919
*
20-
* @param array|ArrayAccess $subset
21-
* @param array|ArrayAccess $array
20+
* @param array|ArrayAccess|mixed[] $subset
21+
* @param array|ArrayAccess|mixed[] $array
2222
*
2323
* @throws ExpectationFailedException
2424
* @throws InvalidArgumentException

src/Constraint/ArraySubset.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace DMS\PHPUnitExtensions\ArraySubset\Constraint;
55

6+
use ArrayAccess;
67
use ArrayObject;
78
use PHPUnit\Framework\Constraint\Constraint;
89
use PHPUnit\Framework\ExpectationFailedException;
@@ -23,14 +24,17 @@
2324
final class ArraySubset extends Constraint
2425
{
2526
/**
26-
* @var iterable
27+
* @var iterable|mixed[]
2728
*/
2829
private $subset;
2930
/**
3031
* @var bool
3132
*/
3233
private $strict;
3334

35+
/**
36+
* @param mixed[] $subset
37+
*/
3438
public function __construct(iterable $subset, bool $strict = false)
3539
{
3640
$this->strict = $strict;
@@ -47,6 +51,9 @@ public function __construct(iterable $subset, bool $strict = false)
4751
* a boolean value instead: true in case of success, false in case of a
4852
* failure.
4953
*
54+
* @param mixed[]|ArrayAccess $other
55+
* @return mixed[]|null|bool
56+
*
5057
* @throws ExpectationFailedException
5158
* @throws InvalidArgumentException
5259
*/
@@ -103,6 +110,11 @@ protected function failureDescription($other): string
103110
return 'an array ' . $this->toString();
104111
}
105112

113+
/**
114+
* @param mixed[]|iterable $other
115+
*
116+
* @return mixed[]
117+
*/
106118
private function toArray(iterable $other): array
107119
{
108120
if (is_array($other)) {

tests/Unit/AssertTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
namespace DMS\PHPUnitExtensions\ArraySubset\Tests\Unit;
55

66
use DMS\PHPUnitExtensions\ArraySubset\Assert;
7+
use PHPUnit\Framework\Exception;
78
use PHPUnit\Framework\ExpectationFailedException;
89
use PHPUnit\Framework\TestCase;
9-
use PHPUnit\Framework\Exception;
1010

1111
final class AssertTest extends TestCase
1212
{
@@ -19,7 +19,7 @@ public function testAssertArraySubsetPassesStrictConfig(): void
1919
public function testAssertArraySubsetThrowsExceptionForInvalidSubset(): void
2020
{
2121
$this->expectException(ExpectationFailedException::class);
22-
Assert::assertArraySubset([6,7], [1,2,3,4,5,6]);
22+
Assert::assertArraySubset([6, 7], [1, 2, 3, 4, 5, 6]);
2323
}
2424

2525
public function testAssertArraySubsetThrowsExceptionForInvalidSubsetArgument(): void
@@ -36,6 +36,6 @@ public function testAssertArraySubsetThrowsExceptionForInvalidArrayArgument(): v
3636

3737
public function testAssertArraySubsetDoesNothingForValidScenario(): void
3838
{
39-
Assert::assertArraySubset([1,2], [1,2,3]);
39+
Assert::assertArraySubset([1, 2], [1, 2, 3]);
4040
}
4141
}

tests/Unit/Constraint/ArraySubsetTest.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
declare(strict_types=1);
33

4-
54
namespace DMS\PHPUnitExtensions\ArraySubset\Tests\Unit\Constraint;
65

76
use ArrayAccessible;
@@ -18,22 +17,25 @@
1817

1918
final class ArraySubsetTest extends TestCase
2019
{
20+
/**
21+
* @return mixed[]
22+
*/
2123
public static function evaluateDataProvider(): array
2224
{
2325
return [
24-
'loose array subset and array other' => [
26+
'loose array subset and array other' => [
2527
'expected' => true,
2628
'subset' => ['bar' => 0],
2729
'other' => ['foo' => '', 'bar' => '0'],
2830
'strict' => false,
2931
],
30-
'strict array subset and array other' => [
32+
'strict array subset and array other' => [
3133
'expected' => false,
3234
'subset' => ['bar' => 0],
3335
'other' => ['foo' => '', 'bar' => '0'],
3436
'strict' => true,
3537
],
36-
'loose array subset and ArrayObject other' => [
38+
'loose array subset and ArrayObject other' => [
3739
'expected' => true,
3840
'subset' => ['bar' => 0],
3941
'other' => new ArrayObject(['foo' => '', 'bar' => '0']),
@@ -49,9 +51,9 @@ public static function evaluateDataProvider(): array
4951
}
5052

5153
/**
52-
* @param array|Traversable $subset
53-
* @param array|Traversable $other
54-
* @param bool $strict
54+
* @param array|Traversable|mixed[] $subset
55+
* @param array|Traversable|mixed[] $other
56+
* @param bool $strict
5557
*
5658
* @throws ExpectationFailedException
5759
* @throws InvalidArgumentException
@@ -92,19 +94,25 @@ public function testIsCountable(): void
9294
{
9395
$reflection = new ReflectionClass(ArraySubset::class);
9496

95-
$this->assertTrue($reflection->implementsInterface(Countable::class), sprintf(
96-
'Failed to assert that ArraySubset implements "%s".',
97-
Countable::class
98-
));
97+
$this->assertTrue(
98+
$reflection->implementsInterface(Countable::class),
99+
sprintf(
100+
'Failed to assert that ArraySubset implements "%s".',
101+
Countable::class
102+
)
103+
);
99104
}
100105

101106
public function testIsSelfDescribing(): void
102107
{
103108
$reflection = new ReflectionClass(ArraySubset::class);
104109

105-
$this->assertTrue($reflection->implementsInterface(SelfDescribing::class), sprintf(
106-
'Failed to assert that Array implements "%s".',
107-
SelfDescribing::class
108-
));
110+
$this->assertTrue(
111+
$reflection->implementsInterface(SelfDescribing::class),
112+
sprintf(
113+
'Failed to assert that Array implements "%s".',
114+
SelfDescribing::class
115+
)
116+
);
109117
}
110118
}

0 commit comments

Comments
 (0)