Skip to content

Commit 81bb759

Browse files
[JsonEncoder] Simplify tests
1 parent f6312d3 commit 81bb759

File tree

6 files changed

+16
-34
lines changed

6 files changed

+16
-34
lines changed

src/Symfony/Component/JsonEncoder/Tests/CacheWarmer/EncoderDecoderCacheWarmerTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function setUp(): void
4242

4343
public function testWarmUp()
4444
{
45-
$this->cacheWarmer([ClassicDummy::class])->warmUp('useless');
45+
$this->cacheWarmer()->warmUp('useless');
4646

4747
$this->assertSame([
4848
\sprintf('%s/d147026bb5d25e5012afcdc1543cf097.json.php', $this->encodersDir),
@@ -54,15 +54,12 @@ public function testWarmUp()
5454
], glob($this->decodersDir.'/*'));
5555
}
5656

57-
/**
58-
* @param list<class-string> $encodable
59-
*/
60-
private function cacheWarmer(array $encodable): EncoderDecoderCacheWarmer
57+
private function cacheWarmer(): EncoderDecoderCacheWarmer
6158
{
6259
$typeResolver = TypeResolver::create();
6360

6461
return new EncoderDecoderCacheWarmer(
65-
$encodable,
62+
[ClassicDummy::class],
6663
new PropertyMetadataLoader($typeResolver),
6764
new PropertyMetadataLoader($typeResolver),
6865
$this->encodersDir,

src/Symfony/Component/JsonEncoder/Tests/Decode/Denormalizer/DateTimeDenormalizerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testDenormalizeImmutable()
2323

2424
$this->assertEquals(
2525
new \DateTimeImmutable('2023-07-26'),
26-
$denormalizer->denormalize('2023-07-26', []),
26+
$denormalizer->denormalize('2023-07-26'),
2727
);
2828

2929
$this->assertEquals(
@@ -38,7 +38,7 @@ public function testDenormalizeMutable()
3838

3939
$this->assertEquals(
4040
new \DateTime('2023-07-26'),
41-
$denormalizer->denormalize('2023-07-26', []),
41+
$denormalizer->denormalize('2023-07-26'),
4242
);
4343

4444
$this->assertEquals(
@@ -52,15 +52,15 @@ public function testThrowWhenInvalidNormalized()
5252
$this->expectException(InvalidArgumentException::class);
5353
$this->expectExceptionMessage('The normalized data is either not an string, or an empty string, or null; you should pass a string that can be parsed with the passed format or a valid DateTime string.');
5454

55-
(new DateTimeDenormalizer(immutable: true))->denormalize(true, []);
55+
(new DateTimeDenormalizer(immutable: true))->denormalize(true);
5656
}
5757

5858
public function testThrowWhenInvalidDateTimeString()
5959
{
6060
$denormalizer = new DateTimeDenormalizer(immutable: true);
6161

6262
try {
63-
$denormalizer->denormalize('0', []);
63+
$denormalizer->denormalize('0');
6464
$this->fail(\sprintf('A "%s" exception must have been thrown.', InvalidArgumentException::class));
6565
} catch (InvalidArgumentException $e) {
6666
$this->assertEquals("Parsing datetime string \"0\" resulted in 1 errors: \nat position 0: Unexpected character", $e->getMessage());

src/Symfony/Component/JsonEncoder/Tests/Decode/SplitterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ public static function splitListInvalidDataProvider(): iterable
107107
yield ['Expected end, but got "100".', '{"a": true} 100'];
108108
}
109109

110-
private function assertListBoundaries(?array $expectedBoundaries, string $content, int $offset = 0, ?int $length = null): void
110+
private function assertListBoundaries(?array $expectedBoundaries, string $content): void
111111
{
112112
$resource = fopen('php://temp', 'w');
113113
fwrite($resource, $content);
114114
rewind($resource);
115115

116-
$boundaries = (new Splitter())->splitList($resource, $offset, $length);
116+
$boundaries = (new Splitter())->splitList($resource);
117117
$boundaries = null !== $boundaries ? iterator_to_array($boundaries) : null;
118118

119119
$this->assertSame($expectedBoundaries, $boundaries);
@@ -122,19 +122,19 @@ private function assertListBoundaries(?array $expectedBoundaries, string $conten
122122
fwrite($resource, $content);
123123
rewind($resource);
124124

125-
$boundaries = (new Splitter())->splitList($resource, $offset, $length);
125+
$boundaries = (new Splitter())->splitList($resource, 0, null);
126126
$boundaries = null !== $boundaries ? iterator_to_array($boundaries) : null;
127127

128128
$this->assertSame($expectedBoundaries, $boundaries);
129129
}
130130

131-
private function assertDictBoundaries(?array $expectedBoundaries, string $content, int $offset = 0, ?int $length = null): void
131+
private function assertDictBoundaries(?array $expectedBoundaries, string $content): void
132132
{
133133
$resource = fopen('php://temp', 'w');
134134
fwrite($resource, $content);
135135
rewind($resource);
136136

137-
$boundaries = (new Splitter())->splitDict($resource, $offset, $length);
137+
$boundaries = (new Splitter())->splitDict($resource);
138138
$boundaries = null !== $boundaries ? iterator_to_array($boundaries) : null;
139139

140140
$this->assertSame($expectedBoundaries, $boundaries);
@@ -143,7 +143,7 @@ private function assertDictBoundaries(?array $expectedBoundaries, string $conten
143143
fwrite($resource, $content);
144144
rewind($resource);
145145

146-
$boundaries = (new Splitter())->splitDict($resource, $offset, $length);
146+
$boundaries = (new Splitter())->splitDict($resource, 0, null);
147147
$boundaries = null !== $boundaries ? iterator_to_array($boundaries) : null;
148148

149149
$this->assertSame($expectedBoundaries, $boundaries);

src/Symfony/Component/JsonEncoder/Tests/Encode/EncoderGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function testCallPropertyMetadataLoaderWithProperContext()
141141
])
142142
->willReturn([]);
143143

144-
$generator = new EncoderGenerator($propertyMetadataLoader, $this->encodersDir, false);
144+
$generator = new EncoderGenerator($propertyMetadataLoader, $this->encodersDir);
145145
$generator->generate($type);
146146
}
147147
}

src/Symfony/Component/JsonEncoder/Tests/Encode/Normalizer/DateTimeNormalizerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testNormalize()
2323

2424
$this->assertEquals(
2525
'2023-07-26T00:00:00+00:00',
26-
$normalizer->normalize(new \DateTimeImmutable('2023-07-26', new \DateTimeZone('UTC')), []),
26+
$normalizer->normalize(new \DateTimeImmutable('2023-07-26', new \DateTimeZone('UTC'))),
2727
);
2828

2929
$this->assertEquals(
@@ -37,6 +37,6 @@ public function testThrowWhenInvalidDenormalized()
3737
$this->expectException(InvalidArgumentException::class);
3838
$this->expectExceptionMessage('The denormalized data must implement the "\DateTimeInterface".');
3939

40-
(new DateTimeNormalizer())->normalize(true, []);
40+
(new DateTimeNormalizer())->normalize(true);
4141
}
4242
}

src/Symfony/Component/JsonEncoder/Tests/Fixtures/Model/DummyWithPhpDoc.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,4 @@ class DummyWithPhpDoc
1313
* @var list<mixed>
1414
*/
1515
public array $array = [];
16-
17-
/**
18-
* @param array<DummyWithNameAttributes> $arrayOfDummies
19-
*
20-
* @return array<string>
21-
*/
22-
public static function castArrayOfDummiesToArrayOfStrings(mixed $arrayOfDummies): mixed
23-
{
24-
return array_column('name', $arrayOfDummies);
25-
}
26-
27-
public static function countArray(array $array): int
28-
{
29-
return count($array);
30-
}
3116
}

0 commit comments

Comments
 (0)