Skip to content

Commit

Permalink
Adjust internal response handling to work with SF6 (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandoorn authored Dec 18, 2024
1 parent 4b2ce0d commit 99ceec0
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
/behat.yml
/phpunit.xml
/phpspec.yml

/docker/
node_modules
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'
services:
db:
image: mariadb:10.6
environment:
- MYSQL_DATABASE=sylius
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- MYSQL_ROOT_HOST=%
command: --sql_mode=""
ports:
- "3306:3306"
volumes:
- ./docker/volumes/mysql:/var/lib/mysql
3 changes: 2 additions & 1 deletion tests/Application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ APP_SECRET=EDITME
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
DATABASE_URL=sqlite:///%kernel.project_dir%/var/db_%kernel.environment%.db
DATABASE_URL="mysql://root:root@127.0.0.1/sylius"

###< doctrine/doctrine-bundle ###

###> lexik/jwt-authentication-bundle ###
Expand Down
Empty file.
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
20 changes: 18 additions & 2 deletions tests/Controller/XmlApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;

abstract class XmlApiTestCase extends BaseXmlApiTestCase
{
Expand All @@ -32,10 +33,20 @@ protected function generateSitemaps(): void
$commandTester->execute(['command' => $command->getName()]);
}

protected function getBufferedResponse(string $uri): Response
protected function getResponse(string $uri): Response
{
if (\version_compare(Kernel::VERSION, '6.0', '>=')) {
$this->doRequest($uri);

return new Response(
$this->client->getInternalResponse()->getContent(),
$this->client->getInternalResponse()->getStatusCode(),
$this->client->getInternalResponse()->getHeaders(),
);
}

\ob_start();
$this->client->request('GET', $uri);
$this->doRequest($uri);
$response = $this->client->getResponse();
$contents = \ob_get_clean();

Expand Down Expand Up @@ -63,4 +74,9 @@ protected function deleteSitemaps(): void
}
}
}

private function doRequest(string $uri): void
{
$this->client->request('GET', $uri);
}
}

0 comments on commit 99ceec0

Please sign in to comment.