Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[JsonEncoder] Simplify tests #59494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function setUp(): void

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

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

/**
* @param list<class-string> $encodable
*/
private function cacheWarmer(array $encodable): EncoderDecoderCacheWarmer
private function cacheWarmer(): EncoderDecoderCacheWarmer
{
$typeResolver = TypeResolver::create();

return new EncoderDecoderCacheWarmer(
$encodable,
[ClassicDummy::class],
new PropertyMetadataLoader($typeResolver),
new PropertyMetadataLoader($typeResolver),
$this->encodersDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testDenormalizeImmutable()

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

$this->assertEquals(
Expand All @@ -38,7 +38,7 @@ public function testDenormalizeMutable()

$this->assertEquals(
new \DateTime('2023-07-26'),
$denormalizer->denormalize('2023-07-26', []),
$denormalizer->denormalize('2023-07-26'),
);

$this->assertEquals(
Expand All @@ -52,15 +52,15 @@ public function testThrowWhenInvalidNormalized()
$this->expectException(InvalidArgumentException::class);
$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.');

(new DateTimeDenormalizer(immutable: true))->denormalize(true, []);
(new DateTimeDenormalizer(immutable: true))->denormalize(true);
}

public function testThrowWhenInvalidDateTimeString()
{
$denormalizer = new DateTimeDenormalizer(immutable: true);

try {
$denormalizer->denormalize('0', []);
$denormalizer->denormalize('0');
$this->fail(\sprintf('A "%s" exception must have been thrown.', InvalidArgumentException::class));
} catch (InvalidArgumentException $e) {
$this->assertEquals("Parsing datetime string \"0\" resulted in 1 errors: \nat position 0: Unexpected character", $e->getMessage());
Expand Down
12 changes: 6 additions & 6 deletions 12 src/Symfony/Component/JsonEncoder/Tests/Decode/SplitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ public static function splitListInvalidDataProvider(): iterable
yield ['Expected end, but got "100".', '{"a": true} 100'];
}

private function assertListBoundaries(?array $expectedBoundaries, string $content, int $offset = 0, ?int $length = null): void
private function assertListBoundaries(?array $expectedBoundaries, string $content): void
{
$resource = fopen('php://temp', 'w');
fwrite($resource, $content);
rewind($resource);

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

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

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

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

private function assertDictBoundaries(?array $expectedBoundaries, string $content, int $offset = 0, ?int $length = null): void
private function assertDictBoundaries(?array $expectedBoundaries, string $content): void
{
$resource = fopen('php://temp', 'w');
fwrite($resource, $content);
rewind($resource);

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

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

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

$this->assertSame($expectedBoundaries, $boundaries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testCallPropertyMetadataLoaderWithProperContext()
])
->willReturn([]);

$generator = new EncoderGenerator($propertyMetadataLoader, $this->encodersDir, false);
$generator = new EncoderGenerator($propertyMetadataLoader, $this->encodersDir);
$generator->generate($type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testNormalize()

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

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

(new DateTimeNormalizer())->normalize(true, []);
(new DateTimeNormalizer())->normalize(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,4 @@ class DummyWithPhpDoc
* @var list<mixed>
*/
public array $array = [];

/**
* @param array<DummyWithNameAttributes> $arrayOfDummies
*
* @return array<string>
*/
public static function castArrayOfDummiesToArrayOfStrings(mixed $arrayOfDummies): mixed
{
return array_column('name', $arrayOfDummies);
}

public static function countArray(array $array): int
{
return count($array);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.