Skip to content

Commit

Permalink
Merge branch 'next-35502/auto-imported-from-github' into 'trunk'
Browse files Browse the repository at this point in the history
NEXT-35502 - Fix migration saleschannel test

See merge request shopware/6/product/platform!13668
  • Loading branch information
OliverSkroblin committed May 24, 2024
2 parents 57b3148 + cabfe11 commit 0854a31
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Fix migration saleschannel test
issue: NEXT-00000
author: Benjamin Wittwer
author_email: [email protected]
author_github: akf-bw
---
# Core
* Changed `Migration1620820321AddDefaultDomainForHeadlessSaleschannelTest` to catch `ForeignKeyConstraintViolationException`
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Shopware\Core\Migration\Test;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use PHPUnit\Framework\Attributes\RunClassInSeparateProcess;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Api\Util\AccessKeyHelper;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour;
use Shopware\Core\Framework\Uuid\Uuid;
Expand Down Expand Up @@ -77,8 +77,15 @@ public function testItAddsDefaultDomainToMultipleApiSalesChannel(): void

public function testItDoesNotBreakIfNoHeadlessSalesChannelIsPresent(): void
{
$salesChannelRepository = $this->getContainer()->get('sales_channel.repository');
$salesChannelRepository->delete([['id' => TestDefaults::SALES_CHANNEL]], Context::createDefaultContext());
try {
$salesChannelRepository = $this->getContainer()->get('sales_channel.repository');
$salesChannelRepository->delete([['id' => TestDefaults::SALES_CHANNEL]], Context::createDefaultContext());
} catch (\Exception $e) {
if (!($e instanceof ForeignKeyConstraintViolationException)) {
static::fail(sprintf('%s Trace: %s', $e->getMessage(), $e->getTraceAsString()));
}
// ignore error because it is possible that other tests (e.g. order tests that refer to the saleschannel) block the deletion of the sales channel
}

(new Migration1620820321AddDefaultDomainForHeadlessSaleschannel())->update($this->connection);
}
Expand All @@ -93,14 +100,17 @@ private function removeAddedDefaultDomains(): void

private function removeAddedSalesChannel(): void
{
$ids = $this->connection->fetchAllAssociative('
SELECT id FROM `sales_channel`
WHERE `short_name` = "API Test"
');

/** @var EntityRepository $salesChannelRepository */
$salesChannelRepository = $this->getContainer()->get('sales_channel.repository');
// $salesChannelRepository->delete([$ids], Context::createDefaultContext());
try {
$this->connection->executeStatement('
DELETE FROM `sales_channel`
WHERE `short_name` = "API Test"
');
} catch (\Exception $e) {
if (!($e instanceof ForeignKeyConstraintViolationException)) {
static::fail(sprintf('%s Trace: %s', $e->getMessage(), $e->getTraceAsString()));
}
// ignore error because it is possible that other tests (e.g. order tests that refer to the saleschannel) block the deletion of the sales channel
}
}

private function addSalesChannel(string $salesChannelType): string
Expand Down

0 comments on commit 0854a31

Please sign in to comment.