Skip to content

Commit

Permalink
NTR: Fix fixtures autoload
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed May 31, 2024
1 parent 5ed8b5a commit d2aba2a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 29 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
"autoload": {
"psr-4": {
"Kiener\\MolliePayments\\": "src/",
"Mollie\\Api\\": "vendor_manual/mollie/mollie-api-php/src/",
"Shopware\\Core\\": "polyfill/Shopware/Core/",
"MolliePayments\\Fixtures\\": "tests/Fixtures/"
"Mollie\\Api\\": "vendor_manual/mollie/mollie-api-php/src/"
}
},
"autoload-dev": {
Expand Down
34 changes: 17 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 24 additions & 6 deletions src/Compatibility/DependencyLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,34 @@ public function loadServices(): void
$loader->load('compatibility/flowbuilder/6.4.6.0.xml');
}

if ($this->shouldLoadFixtures()) {
$loader->load('services/fixtures/fixtures.xml');
}
}

$composerDevReqsInstalled = file_exists(__DIR__.'/../../vendor/bin/phpunit');
public function registerFixturesAutoloader():void
{
if ($this->shouldLoadFixtures() === false) {
return;
}

if ($composerDevReqsInstalled) {
$dirFixtures = (string)realpath(__DIR__ . '/../../tests/Fixtures/');
$dirFixtures = (string)realpath(__DIR__ . '/../../tests/Fixtures/');
# we need to tell Shopware to load our custom fixtures
# from our TEST autoload-dev area....
$classLoader = new ClassLoader();
$classLoader->addPsr4("MolliePayments\\Fixtures\\", $dirFixtures, true);

if (is_dir($dirFixtures)) {
$loader->load('services/fixtures/fixtures.xml');
}
$classLoader->register();
}

private function shouldLoadFixtures():bool
{
$composerDevReqsInstalled = file_exists(__DIR__.'/../../vendor/bin/phpunit');
if ($composerDevReqsInstalled === false) {
return false;
}
$dirFixtures = (string)realpath(__DIR__ . '/../../tests/Fixtures/');
return is_dir($dirFixtures);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/MolliePayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ public function activate(ActivateContext $context): void
$this->runDbMigrations($context->getMigrationCollection());
}

public function boot(): void
{
parent::boot();

if ($this->container === null) {
return;
}
/** @var Container $container */
$container = $this->container;

$shopwareVersion = $container->getParameter('kernel.shopware_version');
if (!is_string($shopwareVersion)) {
$shopwareVersion = Kernel::SHOPWARE_FALLBACK_VERSION;
}
# load the dependencies that are compatible
# with our current shopware version

$loader = new DependencyLoader($container, new VersionCompare($shopwareVersion));
$loader->registerFixturesAutoloader();
}


/**
* @param Context $context
Expand Down
3 changes: 0 additions & 3 deletions switch-composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ function moveToDev(array $composerContent, string $swVersion)
unset($composerContent['require']["shopware/administration"]);
unset($composerContent['require']["shopware/storefront"]);

$composerContent['autoload']['psr-4']['MolliePayments\\Fixtures\\'] = "tests/Fixtures/";

return $composerContent;
}

Expand All @@ -56,6 +54,5 @@ function moveToProd(array $composerContent, string $swVersion)
unset($composerContent['require-dev']["shopware/administration"]);
unset($composerContent['require-dev']["shopware/storefront"]);

unset($composerContent['autoload']['psr-4']['MolliePayments\\Fixtures\\']);
return $composerContent;
}

0 comments on commit d2aba2a

Please sign in to comment.