From 26dd39b163d88207acd3e2f54b7d35e6780f7671 Mon Sep 17 00:00:00 2001 From: Stefan Doorn Date: Wed, 18 Dec 2024 12:00:07 +0100 Subject: [PATCH 1/4] Do not use buffered responses --- .../MultiChannelSitemapIndexControllerApiTest.php | 4 ++-- .../MultiChannelSitemapStaticControllerApiTest.php | 2 +- tests/Controller/SitemapIndexControllerApiTest.php | 6 +++--- tests/Controller/SitemapProductControllerApiImagesTest.php | 2 +- .../SitemapProductControllerApiLocalesImagesTest.php | 2 +- .../Controller/SitemapProductControllerApiLocalesTest.php | 2 +- tests/Controller/SitemapProductControllerApiTest.php | 2 +- .../SitemapProductControllerApiUniqueLocaleChannelTest.php | 2 +- tests/Controller/SitemapStaticControllerApiTest.php | 2 +- tests/Controller/SitemapTaxonControllerApiLocalesTest.php | 2 +- tests/Controller/SitemapTaxonControllerApiTest.php | 2 +- tests/Controller/XmlApiTestCase.php | 7 ++----- 12 files changed, 16 insertions(+), 19 deletions(-) diff --git a/tests/Controller/MultiChannelSitemapIndexControllerApiTest.php b/tests/Controller/MultiChannelSitemapIndexControllerApiTest.php index d784d301..4fd0a0fc 100644 --- a/tests/Controller/MultiChannelSitemapIndexControllerApiTest.php +++ b/tests/Controller/MultiChannelSitemapIndexControllerApiTest.php @@ -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(); diff --git a/tests/Controller/MultiChannelSitemapStaticControllerApiTest.php b/tests/Controller/MultiChannelSitemapStaticControllerApiTest.php index b77997c3..5679a399 100644 --- a/tests/Controller/MultiChannelSitemapStaticControllerApiTest.php +++ b/tests/Controller/MultiChannelSitemapStaticControllerApiTest.php @@ -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'); } diff --git a/tests/Controller/SitemapIndexControllerApiTest.php b/tests/Controller/SitemapIndexControllerApiTest.php index 4981fef4..9f8b4a54 100644 --- a/tests/Controller/SitemapIndexControllerApiTest.php +++ b/tests/Controller/SitemapIndexControllerApiTest.php @@ -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()); diff --git a/tests/Controller/SitemapProductControllerApiImagesTest.php b/tests/Controller/SitemapProductControllerApiImagesTest.php index 6707891b..d0d17a33 100644 --- a/tests/Controller/SitemapProductControllerApiImagesTest.php +++ b/tests/Controller/SitemapProductControllerApiImagesTest.php @@ -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(); diff --git a/tests/Controller/SitemapProductControllerApiLocalesImagesTest.php b/tests/Controller/SitemapProductControllerApiLocalesImagesTest.php index 2b0b3f8b..ca4ac5b4 100644 --- a/tests/Controller/SitemapProductControllerApiLocalesImagesTest.php +++ b/tests/Controller/SitemapProductControllerApiLocalesImagesTest.php @@ -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(); diff --git a/tests/Controller/SitemapProductControllerApiLocalesTest.php b/tests/Controller/SitemapProductControllerApiLocalesTest.php index 5d07bfa1..267c2a6b 100644 --- a/tests/Controller/SitemapProductControllerApiLocalesTest.php +++ b/tests/Controller/SitemapProductControllerApiLocalesTest.php @@ -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(); } diff --git a/tests/Controller/SitemapProductControllerApiTest.php b/tests/Controller/SitemapProductControllerApiTest.php index 99e19821..ff8bef19 100644 --- a/tests/Controller/SitemapProductControllerApiTest.php +++ b/tests/Controller/SitemapProductControllerApiTest.php @@ -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(); } diff --git a/tests/Controller/SitemapProductControllerApiUniqueLocaleChannelTest.php b/tests/Controller/SitemapProductControllerApiUniqueLocaleChannelTest.php index 95f4ba9f..09c5ec35 100644 --- a/tests/Controller/SitemapProductControllerApiUniqueLocaleChannelTest.php +++ b/tests/Controller/SitemapProductControllerApiUniqueLocaleChannelTest.php @@ -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(); diff --git a/tests/Controller/SitemapStaticControllerApiTest.php b/tests/Controller/SitemapStaticControllerApiTest.php index febb42c6..f463a19e 100644 --- a/tests/Controller/SitemapStaticControllerApiTest.php +++ b/tests/Controller/SitemapStaticControllerApiTest.php @@ -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(); diff --git a/tests/Controller/SitemapTaxonControllerApiLocalesTest.php b/tests/Controller/SitemapTaxonControllerApiLocalesTest.php index 46c98615..9e52035f 100644 --- a/tests/Controller/SitemapTaxonControllerApiLocalesTest.php +++ b/tests/Controller/SitemapTaxonControllerApiLocalesTest.php @@ -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(); diff --git a/tests/Controller/SitemapTaxonControllerApiTest.php b/tests/Controller/SitemapTaxonControllerApiTest.php index 132ab084..02a98931 100644 --- a/tests/Controller/SitemapTaxonControllerApiTest.php +++ b/tests/Controller/SitemapTaxonControllerApiTest.php @@ -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(); diff --git a/tests/Controller/XmlApiTestCase.php b/tests/Controller/XmlApiTestCase.php index 50e0ea9f..0925b71a 100644 --- a/tests/Controller/XmlApiTestCase.php +++ b/tests/Controller/XmlApiTestCase.php @@ -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 From 5b6a860c3d79f81b437d83e935fd8c41a6931df9 Mon Sep 17 00:00:00 2001 From: Stefan Doorn Date: Wed, 18 Dec 2024 12:37:22 +0100 Subject: [PATCH 2/4] Use internal response for testing responses --- tests/Application/.env | 3 ++- tests/Application/public/media/image/.gitignore | 0 tests/Controller/XmlApiTestCase.php | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) delete mode 100644 tests/Application/public/media/image/.gitignore diff --git a/tests/Application/.env b/tests/Application/.env index 6e0a2f2f..29dc5f19 100644 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -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 ### diff --git a/tests/Application/public/media/image/.gitignore b/tests/Application/public/media/image/.gitignore deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/Controller/XmlApiTestCase.php b/tests/Controller/XmlApiTestCase.php index 0925b71a..6282a28c 100644 --- a/tests/Controller/XmlApiTestCase.php +++ b/tests/Controller/XmlApiTestCase.php @@ -36,7 +36,11 @@ protected function getResponse(string $uri): Response { $this->client->request('GET', $uri); - return $this->client->getResponse(); + return new Response( + $this->client->getInternalResponse()->getContent(), + $this->client->getInternalResponse()->getStatusCode(), + $this->client->getInternalResponse()->getHeaders(), + ); } protected function deleteSitemaps(): void From 0750ff4bac3491338d2babb68cbb85485685473d Mon Sep 17 00:00:00 2001 From: Stefan Doorn Date: Wed, 18 Dec 2024 12:45:31 +0100 Subject: [PATCH 3/4] Use different content fetching for SF6 and earlier --- .gitignore | 3 +++ docker-compose.yml | 15 +++++++++++++++ tests/Controller/XmlApiTestCase.php | 27 +++++++++++++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index eeb4572c..fdcc2278 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ /behat.yml /phpunit.xml /phpspec.yml + +/docker/ +node_modules diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..0e132675 --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/tests/Controller/XmlApiTestCase.php b/tests/Controller/XmlApiTestCase.php index 6282a28c..5cb1b780 100644 --- a/tests/Controller/XmlApiTestCase.php +++ b/tests/Controller/XmlApiTestCase.php @@ -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 { @@ -34,13 +35,22 @@ protected function generateSitemaps(): void protected function getResponse(string $uri): Response { - $this->client->request('GET', $uri); + 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->doRequest($uri); + $response = $this->client->getResponse(); + $contents = \ob_get_clean(); - return new Response( - $this->client->getInternalResponse()->getContent(), - $this->client->getInternalResponse()->getStatusCode(), - $this->client->getInternalResponse()->getHeaders(), - ); + return new Response($contents, $response->getStatusCode(), $response->headers->all()); } protected function deleteSitemaps(): void @@ -64,4 +74,9 @@ protected function deleteSitemaps(): void } } } + + private function doRequest(string $uri): void + { + $this->client->request('GET', $uri); + } } From 7db45dc71afbd919e34167b75c82cb6d3f10eb0d Mon Sep 17 00:00:00 2001 From: Stefan Doorn Date: Wed, 18 Dec 2024 12:49:45 +0100 Subject: [PATCH 4/4] Fix CS --- tests/Controller/XmlApiTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Controller/XmlApiTestCase.php b/tests/Controller/XmlApiTestCase.php index 5cb1b780..5425d99d 100644 --- a/tests/Controller/XmlApiTestCase.php +++ b/tests/Controller/XmlApiTestCase.php @@ -35,7 +35,7 @@ protected function generateSitemaps(): void protected function getResponse(string $uri): Response { - if (version_compare(Kernel::VERSION, '6.0', '>=')) { + if (\version_compare(Kernel::VERSION, '6.0', '>=')) { $this->doRequest($uri); return new Response(