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

Added null check in DataFixtureSetup for the scope #39423

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function apply(array $fixture): ?DataObject
$factory = $this->dataFixtureFactory->create($fixture['factory']);
if (isset($fixture['scope'])) {
$scope = DataFixtureStorageManager::getStorage()->get($fixture['scope']);
if (null === $scope) {
throw new \RuntimeException(sprintf('Scope "%s" does not exist.', $fixture['scope']));
}
$fromScope = $this->scopeSwitcher->switch($scope);
try {
$result = $factory->apply($data);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace integration\framework\tests\unit\testsuite\Magento\Test\Annotation;

use Magento\Framework\Registry;
use Magento\TestFramework\Annotation\DataFixtureSetup;
use Magento\TestFramework\Fixture\DataFixtureFactory;
use Magento\TestFramework\Fixture\DataFixtureStorage;
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
use Magento\TestFramework\ScopeSwitcherInterface;
use PHPUnit\Framework\TestCase;

class DataFixtureSetupTest extends TestCase
{
private ?DataFixtureSetup $object;

private ?Registry $registry;
private ?DataFixtureFactory $dataFixtureFactory;
private ?ScopeSwitcherInterface $scopeSwitcher;

protected function setUp(): void
{
$this->registry = $this->createMock(Registry::class);
$this->dataFixtureFactory = $this->createMock(DataFixtureFactory::class);
$this->scopeSwitcher = $this->createMock(ScopeSwitcherInterface::class);
$this->object = new DataFixtureSetup($this->registry, $this->dataFixtureFactory, $this->scopeSwitcher);
}

public function testApplyWithArbitraryScopeThrowsException(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Scope "non_existing_scope" does not exist.');

$storage = new DataFixtureStorage();
DataFixtureStorageManager::setStorage($storage);

$this->object->apply([
'data' => [],
'factory' => 'DummyFixtureClass',
'scope' => 'non_existing_scope',
]);
}
}