Skip to content

Commit

Permalink
Do not use buffered response in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandoorn committed Oct 1, 2024
1 parent dc8aaf5 commit b719556
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public function testShowActionResponse()
$this->loadFixturesFromFiles(['multi_channel.yaml']);
$this->generateSitemaps();

$response = $this->getBufferedResponse('http://localhost/sitemap_index.xml');
$response = $this->getResponse('http://localhost/sitemap_index.xml');
$this->assertResponse($response, 'show_sitemap_index');

$response = $this->getBufferedResponse('http://store.fr/sitemap_index.xml');
$response = $this->getResponse('http://store.fr/sitemap_index.xml');
$this->assertResponse($response, 'show_second_sitemap_index');

$this->deleteSitemaps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function testShowActionResponse()
$this->loadFixturesFromFiles(['multi_channel.yaml']);
$this->generateSitemaps();

$response = $this->getBufferedResponse('http://store.fr/sitemap/static.xml');
$response = $this->getResponse('http://store.fr/sitemap/static.xml');

$this->assertResponse($response, 'show_sitemap_static_fr');
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Controller/SitemapIndexControllerApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ protected function setUp(): void

public function testRedirectActionResponse()
{
$response = $this->getBufferedResponse('/sitemap.xml');
$response = $this->getResponse('/sitemap.xml');
self::assertResponseRedirects('http://localhost/sitemap_index.xml', 301);
$this->deleteSitemaps();
}

public function testShowActionResponse()
{
$response = $this->getBufferedResponse('/sitemap_index.xml');
$response = $this->getResponse('/sitemap_index.xml');
$this->assertResponse($response, 'show_sitemap_index');
$this->deleteSitemaps();
}

public function testRedirectResponse()
{
$response = $this->getBufferedResponse('/sitemap.xml');
$response = $this->getResponse('/sitemap.xml');

$this->assertResponseCode($response, 301);
$this->assertTrue($response->isRedirect());
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/SitemapProductControllerApiImagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function testShowActionResponse()
{
$this->loadFixturesFromFiles(['channel.yaml', 'product_images.yaml']);
$this->generateSitemaps();
$response = $this->getBufferedResponse('/sitemap/products.xml');
$response = $this->getResponse('/sitemap/products.xml');

$this->assertResponse($response, 'show_sitemap_products_image');
$this->deleteSitemaps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function testShowActionResponse()
{
$this->loadFixturesFromFiles(['channel.yaml', 'product_locale_image.yaml']);
$this->generateSitemaps();
$response = $this->getBufferedResponse('/sitemap/products.xml');
$response = $this->getResponse('/sitemap/products.xml');

$this->assertResponse($response, 'show_sitemap_products_locale_image');
$this->deleteSitemaps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function testShowActionResponse()
{
$this->loadFixturesFromFiles(['channel.yaml', 'product_locale.yaml']);
$this->generateSitemaps();
$response = $this->getBufferedResponse('/sitemap/products.xml');
$response = $this->getResponse('/sitemap/products.xml');
$this->assertResponse($response, 'show_sitemap_products_locale');
$this->deleteSitemaps();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/SitemapProductControllerApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function testShowActionResponse()
$this->loadFixturesFromFiles(['channel.yaml', 'product.yaml']);
$this->generateSitemaps();

$response = $this->getBufferedResponse('/sitemap/products.xml');
$response = $this->getResponse('/sitemap/products.xml');
$this->assertResponse($response, 'show_sitemap_products');
$this->deleteSitemaps();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function testShowActionResponse()
$this->loadFixturesFromFiles(['product_unique_locale_channel.yaml']);
$this->generateSitemaps();

$response = $this->getBufferedResponse('/sitemap/products.xml');
$response = $this->getResponse('/sitemap/products.xml');

$this->assertResponse($response, 'show_sitemap_products_unique_channel_locale');
$this->deleteSitemaps();
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/SitemapStaticControllerApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function testShowActionResponse()
{
$this->loadFixturesFromFiles(['channel.yaml']);
$this->generateSitemaps();
$response = $this->getBufferedResponse('/sitemap/static.xml');
$response = $this->getResponse('/sitemap/static.xml');

$this->assertResponse($response, 'show_sitemap_static');
$this->deleteSitemaps();
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/SitemapTaxonControllerApiLocalesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function testShowActionResponse()
{
$this->loadFixturesFromFiles(['channel.yaml', 'taxon_locale.yaml']);
$this->generateSitemaps();
$response = $this->getBufferedResponse('/sitemap/taxons.xml');
$response = $this->getResponse('/sitemap/taxons.xml');

$this->assertResponse($response, 'show_sitemap_taxons_locale');
$this->deleteSitemaps();
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/SitemapTaxonControllerApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function testShowActionResponse()
{
$this->loadFixturesFromFiles(['channel.yaml', 'taxon.yaml']);
$this->generateSitemaps();
$response = $this->getBufferedResponse('/sitemap/taxons.xml');
$response = $this->getResponse('/sitemap/taxons.xml');

$this->assertResponse($response, 'show_sitemap_taxons');
$this->deleteSitemaps();
Expand Down
7 changes: 2 additions & 5 deletions tests/Controller/XmlApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ protected function generateSitemaps(): void
$commandTester->execute(['command' => $command->getName()]);
}

protected function getBufferedResponse(string $uri): Response
protected function getResponse(string $uri): Response
{
\ob_start();
$this->client->request('GET', $uri);
$response = $this->client->getResponse();
$contents = \ob_get_clean();

return new Response($contents, $response->getStatusCode(), $response->headers->all());
return $this->client->getResponse();
}

protected function deleteSitemaps(): void
Expand Down

0 comments on commit b719556

Please sign in to comment.