Skip to content

Commit 94fe6be

Browse files
committed
Fix styling with php-cs-fixer
1 parent 23f6131 commit 94fe6be

File tree

4 files changed

+134
-93
lines changed

4 files changed

+134
-93
lines changed

src/Framework/Assert.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use PHPUnit\Framework\Constraint\Callback;
2626
use PHPUnit\Framework\Constraint\Constraint;
2727
use PHPUnit\Framework\Constraint\Count;
28+
use PHPUnit\Framework\Constraint\Dictionary\IsIdenticalKeysValues;
2829
use PHPUnit\Framework\Constraint\DirectoryExists;
2930
use PHPUnit\Framework\Constraint\FileExists;
3031
use PHPUnit\Framework\Constraint\GreaterThan;
@@ -65,7 +66,6 @@
6566
use PHPUnit\Framework\Constraint\TraversableContainsEqual;
6667
use PHPUnit\Framework\Constraint\TraversableContainsIdentical;
6768
use PHPUnit\Framework\Constraint\TraversableContainsOnly;
68-
use PHPUnit\Framework\Constraint\Dictionary\IsIdenticalKeysValues;
6969
use PHPUnit\Util\Xml\Loader as XmlLoader;
7070
use PHPUnit\Util\Xml\XmlException;
7171

@@ -1775,7 +1775,7 @@ final public static function assertSameDictionaryKeysValues(array $expected, arr
17751775
self::assertThat(
17761776
$actual,
17771777
new IsIdenticalKeysValues($expected),
1778-
$message
1778+
$message,
17791779
);
17801780
}
17811781

src/Framework/Constraint/Dictionary/IsIdenticalKeysValues.php

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
<?php
22

33
declare(strict_types=1);
4-
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
512
namespace PHPUnit\Framework\Constraint\Dictionary;
613

14+
use function array_key_exists;
15+
use function assert;
16+
use function in_array;
17+
use function is_array;
18+
use function is_object;
19+
use function sprintf;
20+
use function str_replace;
21+
use function substr_replace;
22+
use function trim;
723
use PHPUnit\Framework\Constraint\Constraint;
824
use PHPUnit\Framework\ExpectationFailedException;
925
use SebastianBergmann\Comparator\ComparisonFailure;
@@ -42,11 +58,13 @@ public function evaluate(mixed $other, string $description = '', bool $returnRes
4258
if ($returnResult) {
4359
return false;
4460
}
61+
4562
throw new ExpectationFailedException(
4663
trim($description . "\n" . $f->getMessage()),
47-
$f
64+
$f,
4865
);
4966
}
67+
5068
return true;
5169
}
5270

@@ -60,15 +78,15 @@ public function toString(): string
6078

6179
/**
6280
* cribbed from `vendor/sebastian/comparator/src/ArrayComparator.php`
63-
* This potentially should be a dictionarycomparator or type-strict arraycomparator
81+
* This potentially should be a dictionarycomparator or type-strict arraycomparator.
6482
*/
6583
private function compareDictionary(array $expected, array $actual, array &$processed = []): void
6684
{
67-
$remaining = $actual;
68-
$actualAsString = "Array (\n";
85+
$remaining = $actual;
86+
$actualAsString = "Array (\n";
6987
$expectedAsString = "Array (\n";
70-
$equal = true;
71-
$exporter = new Exporter;
88+
$equal = true;
89+
$exporter = new Exporter;
7290

7391
foreach ($expected as $key => $value) {
7492
unset($remaining[$key]);
@@ -80,6 +98,7 @@ private function compareDictionary(array $expected, array $actual, array &$proce
8098
$exporter->shortenedExport($value),
8199
);
82100
$equal = false;
101+
83102
continue;
84103
}
85104

@@ -94,12 +113,13 @@ private function compareDictionary(array $expected, array $actual, array &$proce
94113
$exporter->export($actual[$key]),
95114
);
96115

97-
// expected array, got array
116+
// expected array, got array
98117
case is_array($value) && is_array($actual[$key]):
99118
$this->compareDictionary($value, $actual[$key]);
119+
100120
break;
101121

102-
// type mismatch, expected object, got something else
122+
// type mismatch, expected object, got something else
103123
case is_object($value) && !is_object($actual[$key]):
104124
throw new ComparisonFailure(
105125
$value,
@@ -108,16 +128,18 @@ private function compareDictionary(array $expected, array $actual, array &$proce
108128
$exporter->export($actual[$key]),
109129
);
110130

111-
// type mismatch, expected object, got object
131+
// type mismatch, expected object, got object
112132
case is_object($value) && is_object($actual[$key]):
113133
$this->compareObjects($value, $actual[$key], $processed);
134+
114135
break;
115136

116-
// both are not array, both are not objects, strict comparison check
137+
// both are not array, both are not objects, strict comparison check
117138
default:
118139
if ($value === $actual[$key]) {
119140
continue 2;
120141
}
142+
121143
throw new ComparisonFailure(
122144
$value,
123145
$actual[$key],
@@ -141,14 +163,14 @@ private function compareDictionary(array $expected, array $actual, array &$proce
141163
" %s => %s\n",
142164
$exporter->export($key),
143165
$e->getExpectedAsString() !== '' ? $this->indent(
144-
$e->getExpectedAsString()
166+
$e->getExpectedAsString(),
145167
) : $exporter->shortenedExport($e->getExpected()),
146168
);
147169
$actualAsString .= sprintf(
148170
" %s => %s\n",
149171
$exporter->export($key),
150172
$e->getActualAsString() !== '' ? $this->indent(
151-
$e->getActualAsString()
173+
$e->getActualAsString(),
152174
) : $exporter->shortenedExport($e->getActual()),
153175
);
154176
$equal = false;
@@ -180,9 +202,9 @@ private function compareDictionary(array $expected, array $actual, array &$proce
180202

181203
/**
182204
* cribbed from `vendor/sebastian/comparator/src/ObjectComparator.php`
183-
* this potentially should be a type-strict objectcomparator
205+
* this potentially should be a type-strict objectcomparator.
184206
*/
185-
private function compareObjects(object $expected, object $actual, array &$processed = [])
207+
private function compareObjects(object $expected, object $actual, array &$processed = []): void
186208
{
187209
if ($actual::class !== $expected::class) {
188210
$exporter = new Exporter;
@@ -207,9 +229,11 @@ private function compareObjects(object $expected, object $actual, array &$proces
207229
}
208230

209231
$processed[] = [$actual, $expected];
232+
210233
if ($actual === $expected) {
211234
return;
212235
}
236+
213237
try {
214238
$this->compareDictionary($this->toArray($expected), $this->toArray($actual), $processed);
215239
} catch (ComparisonFailure $e) {
@@ -225,15 +249,15 @@ private function compareObjects(object $expected, object $actual, array &$proces
225249
}
226250

227251
/**
228-
* cribbed from `vendor/sebastian/comparator/src/ObjectComparator.php`
252+
* cribbed from `vendor/sebastian/comparator/src/ObjectComparator.php`.
229253
*/
230254
private function toArray(object $object): array
231255
{
232256
return (new Exporter)->toArray($object);
233257
}
234258

235259
/**
236-
* cribbed from `vendor/sebastian/comparator/src/ArrayComparator.php`
260+
* cribbed from `vendor/sebastian/comparator/src/ArrayComparator.php`.
237261
*/
238262
private function indent(string $lines): string
239263
{

tests/unit/Framework/Assert/assertSameDictionaryKeysValuesTest.php

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?php declare(strict_types=1);
2-
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
310
namespace PHPUnit\Framework;
411

512
use PHPUnit\Framework\Attributes\CoversMethod;
@@ -21,36 +28,36 @@ public static function successProvider(): array
2128
return [
2229
[
2330
[
24-
'string' => 'string',
25-
true => true,
26-
1 => 1,
27-
2 => 2.5,
28-
'object' => new stdClass(),
29-
'array' => [1, 2, 3],
31+
'string' => 'string',
32+
true => true,
33+
1 => 1,
34+
2 => 2.5,
35+
'object' => new stdClass,
36+
'array' => [1, 2, 3],
3037
'dictionary' => [
3138
'string' => 'string',
32-
true => true,
33-
1 => 1,
34-
2 => 2.5,
35-
'object' => new stdClass(),
36-
'array' => [1, 2, 3],
39+
true => true,
40+
1 => 1,
41+
2 => 2.5,
42+
'object' => new stdClass,
43+
'array' => [1, 2, 3],
3744
],
3845
],
3946
[
4047
'dictionary' => [
41-
'object' => new stdClass(),
42-
'array' => [1, 2, 3],
48+
'object' => new stdClass,
49+
'array' => [1, 2, 3],
4350
'string' => 'string',
44-
true => true,
45-
1 => 1,
46-
2 => 2.5,
51+
true => true,
52+
1 => 1,
53+
2 => 2.5,
4754
],
4855
'string' => 'string',
49-
true => true,
50-
1 => 1,
51-
2 => 2.5,
52-
'object' => new stdClass(),
53-
'array' => [1, 2, 3],
56+
true => true,
57+
1 => 1,
58+
2 => 2.5,
59+
'object' => new stdClass,
60+
'array' => [1, 2, 3],
5461
],
5562
],
5663
];
@@ -64,25 +71,25 @@ public static function failureProvider(): array
6471
return [
6572
[
6673
[
67-
'string' => 'string',
68-
true => true,
69-
1 => 1,
70-
2 => 2.5,
71-
'object' => new stdClass(),
72-
'array' => [1, 2, 3],
74+
'string' => 'string',
75+
true => true,
76+
1 => 1,
77+
2 => 2.5,
78+
'object' => new stdClass,
79+
'array' => [1, 2, 3],
7380
'dictionary' => [
7481
'string' => 'string',
75-
true => true,
76-
1 => 1,
77-
2 => 2.5,
78-
'object' => new stdClass(),
79-
'array' => [1, 2, 3],
82+
true => true,
83+
1 => 1,
84+
2 => 2.5,
85+
'object' => new stdClass,
86+
'array' => [1, 2, 3],
8087
],
8188
],
8289
[
8390
'string' => 'string',
84-
true => true,
85-
1 => 1,
91+
true => true,
92+
1 => 1,
8693
],
8794
],
8895
];

0 commit comments

Comments
 (0)