Skip to content

Commit

Permalink
Merge pull request #188 from MoritzKrafeld/ntr/add-enterprise-to-sw6-…
Browse files Browse the repository at this point in the history
…plugin-namespace

NTR - add enterprise to sw6 plugin namespace
  • Loading branch information
mitelg committed Aug 23, 2022
2 parents dbd452e + ec141b9 commit 41f98fc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Extensions/Shopware/Plugin/Services/PluginFactory.php
Expand Up @@ -15,6 +15,11 @@
*/
class PluginFactory
{
public const SW6_PLUGIN_PATHS = [
'shopware/6/services',
'shopware/6/enterprise',
];

/**
* Input is a name like Backend_SwagBusinessEssentials
*
Expand All @@ -33,7 +38,10 @@ public static function getPlugin($name, $sshUrl, $httpUrl, $repoName, $repoType
$plugin->cloneUrlHttp = $httpUrl;
$plugin->repository = $repoName;
$plugin->repoType = $repoType;
$plugin->isShopware6 = (bool) \strpos($sshUrl, 'shopware/6/services'); // could not be position 0, so this is safe

$preg = \implode('|', self::SW6_PLUGIN_PATHS);
$preg = '/' . \str_replace('/', '\/', $preg) . '/';
$plugin->isShopware6 = (bool) \preg_match($preg, $sshUrl);

return $plugin;
}
Expand Down
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
/**
* (c) shopware AG <info@shopware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;
use Shopware\Plugin\Services\PluginFactory;

class PluginFactoryTest extends TestCase
{
/**
* @dataProvider sw6PluginDataProvider
*/
public function testGetPluginIsSw6Plugin(string $name, string $sshUrl, string $httpUrl, string $repoName, ?string $repoType = null): void
{
$plugin = PluginFactory::getPlugin($name, $sshUrl, $httpUrl, $repoName, $repoType);

static::assertTrue($plugin->isShopware6);
}

/**
* @dataProvider notSw6PluginDataProvider
*/
public function testGetPluginIsNotSw6Plugin(string $name, string $sshUrl, string $httpUrl, string $repoName, ?string $repoType = null): void
{
$plugin = PluginFactory::getPlugin($name, $sshUrl, $httpUrl, $repoName, $repoType);

static::assertFalse($plugin->isShopware6);
}

public function sw6PluginDataProvider(): Generator
{
foreach (PluginFactory::SW6_PLUGIN_PATHS as $path) {
yield 'Plugin is SW6 - ' . $path => [
'name' => 'frontend_myPluginName',
'sshUrl' => 'git@foo.bar.com:' . $path . '/myPlugin.git',
'httpUrl' => 'https://mygitlabserver.com/shopware/6/enterprise/myPlugin.git',
'repoName' => 'myPlugin',
'repoType' => null,
];
}
}

public function notSw6PluginDataProvider(): Generator
{
yield 'Plugin is not SW6 - custom namespace' => [
'name' => 'frontend_myPluginName',
'sshUrl' => 'git@foo.bar.com:my/custom/namespace/myPlugin.git',
'httpUrl' => 'https://mygitlabserver.com/my/custom/namespace/myPlugin.git',
'repoName' => 'myPlugin',
'repoType' => null,
];
}
}

0 comments on commit 41f98fc

Please sign in to comment.