Skip to content
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
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,8 @@ parameters:
- src/Symfony/Bundle/Test
- tests
- src # TODO

-
identifier: method.notFound
paths:
- tests/Functional/JsonStreamerTest.php
81 changes: 14 additions & 67 deletions tests/Functional/JsonStreamerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,8 @@ public function testJsonStreamerJsonLd(): void
$this->markTestSkipped();
}

$buffer = '';
ob_start(function (string $chunk) use (&$buffer): void {
$buffer .= $chunk;
});

self::createClient()->request('GET', '/json_stream_resources/1', ['headers' => ['accept' => 'application/ld+json']]);

ob_get_clean();

$res = json_decode($buffer, true);
$r = self::createClient()->request('GET', '/json_stream_resources/1', ['headers' => ['accept' => 'application/ld+json']]);
$res = json_decode($r->getBrowserKitResponse()->getContent(), true);
$this->assertIsInt($res['views']);
$this->assertIsInt($res['rating']);
$this->assertIsBool($res['isFeatured']);
Expand All @@ -144,11 +136,8 @@ public function testJsonStreamerCollectionJsonLd(): void
$buffer .= $chunk;
});

self::createClient()->request('GET', '/json_stream_resources', ['headers' => ['accept' => 'application/ld+json']]);

ob_get_clean();

$res = json_decode($buffer, true);
$r = self::createClient()->request('GET', '/json_stream_resources', ['headers' => ['accept' => 'application/ld+json']]);
$res = json_decode($r->getBrowserKitResponse()->getContent(), true);

$this->assertIsArray($res);
$this->assertArrayHasKey('@context', $res);
Expand All @@ -173,16 +162,8 @@ public function testJsonStreamerJson(): void
$this->markTestSkipped();
}

$buffer = '';
ob_start(function (string $chunk) use (&$buffer): void {
$buffer .= $chunk;
});

self::createClient()->request('GET', '/json_stream_resources/1', ['headers' => ['accept' => 'application/json']]);

ob_get_clean();

$res = json_decode($buffer, true);
$r = self::createClient()->request('GET', '/json_stream_resources/1', ['headers' => ['accept' => 'application/json']]);
$res = json_decode($r->getBrowserKitResponse()->getContent(), true);
$this->assertIsInt($res['views']);
$this->assertIsInt($res['rating']);
$this->assertIsBool($res['isFeatured']);
Expand All @@ -202,17 +183,8 @@ public function testJsonStreamerCollectionJson(): void
$this->markTestSkipped();
}

$buffer = '';
ob_start(function (string $chunk) use (&$buffer): void {
$buffer .= $chunk;
});

self::createClient()->request('GET', '/json_stream_resources', ['headers' => ['accept' => 'application/json']]);

ob_get_clean();

$res = json_decode($buffer, true);

$r = self::createClient()->request('GET', '/json_stream_resources', ['headers' => ['accept' => 'application/json']]);
$res = json_decode($r->getBrowserKitResponse()->getContent(), true);
$this->assertIsArray($res);
$this->assertArrayNotHasKey('@id', $res);
$this->assertArrayNotHasKey('@type', $res);
Expand All @@ -233,12 +205,7 @@ public function testJsonStreamerWriteJsonLd(): void
$this->markTestSkipped('PHP version is lower than 8.4');
}

$buffer = '';
ob_start(function (string $chunk) use (&$buffer): void {
$buffer .= $chunk;
});

self::createClient()->request('POST', '/json_stream_resources', [
$r = self::createClient()->request('POST', '/json_stream_resources', [
'json' => [
'title' => 'asd',
'views' => 0,
Expand All @@ -251,10 +218,7 @@ public function testJsonStreamerWriteJsonLd(): void
'headers' => ['content-type' => 'application/ld+json'],
]);

ob_get_clean();

$res = json_decode($buffer, true);

$res = json_decode($r->getBrowserKitResponse()->getContent(), true);
$this->assertResponseIsSuccessful();
$this->assertSame('asd', $res['title']);
$this->assertSame(0, $res['views']);
Expand Down Expand Up @@ -286,12 +250,7 @@ public function testJsonStreamerWriteJson(): void
$this->markTestSkipped('PHP version is lower than 8.4');
}

$buffer = '';
ob_start(function (string $chunk) use (&$buffer): void {
$buffer .= $chunk;
});

self::createClient()->request('POST', '/json_stream_resources', [
$r = self::createClient()->request('POST', '/json_stream_resources', [
'json' => [
'title' => 'asd',
'views' => 0,
Expand All @@ -303,11 +262,7 @@ public function testJsonStreamerWriteJson(): void
],
'headers' => ['content-type' => 'application/json', 'accept' => 'application/json'],
]);

ob_get_clean();

$res = json_decode($buffer, true);

$res = json_decode($r->getBrowserKitResponse()->getContent(), true);
$this->assertResponseIsSuccessful();
$this->assertSame('asd', $res['title']);
$this->assertSame(0, $res['views']);
Expand Down Expand Up @@ -335,16 +290,8 @@ public function testJsonStreamerJsonLdGenIdFalseWithDifferentTypeThenShortname()
$this->markTestSkipped();
}

$buffer = '';
ob_start(function (string $chunk) use (&$buffer): void {
$buffer .= $chunk;
});

self::createClient()->request('GET', '/json-stream-products/test', ['headers' => ['accept' => 'application/ld+json']]);

ob_get_clean();

$res = json_decode($buffer, true);
$r = self::createClient()->request('GET', '/json-stream-products/test', ['headers' => ['accept' => 'application/ld+json']]);
$res = json_decode($r->getBrowserKitResponse()->getContent(), true);
$this->assertArrayNotHasKey('@id', $res['aggregateRating']);
$this->assertEquals('https://schema.org/AggregateRating', $res['aggregateRating']['@type']);
$this->assertEquals('https://schema.org/Product', $res['@type']);
Expand Down
Loading