Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEXT-35502 - Fix migration saleschannel test #3679

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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