Skip to content

Commit

Permalink
Fix migration saleschannel test
Browse files Browse the repository at this point in the history
  • Loading branch information
akf-bw committed Apr 22, 2024
1 parent 57c82c0 commit 1e4af8a
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: dev@a-k-f.de
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 1e4af8a

Please sign in to comment.