Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cngJo committed Sep 12, 2023
1 parent 918b32e commit 622df50
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 69 deletions.
5 changes: 5 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
__DIR__ . '/tests',
]);

$ecsConfig->skip([
__DIR__ . "/tests/TestBootstrap.php",
__DIR__ . "/tests/TestBootstrapper.php",
]);

$ecsConfig->sets([
SetList::PSR_12,
SetList::STRICT,
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ parameters:
paths:
- src
- tests
excludePaths:
- tests/TestBootstrap.php
- tests/TestBootstrapper.php
3 changes: 2 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
bootstrap="tests/TestBootstrap.php"
cacheResult="false">

<php>
<ini name="error_reporting" value="-1"/>
<server name="KERNEL_CLASS" value="Shopware\Core\Kernel"/>
<env name="APP_ENV" value="test"/>
<env name="APP_URL" value="https://localhost"/>
<env name="APP_DEBUG" value="1"/>
<env name="APP_SECRET" value="s$cretf0rt3st"/>
<env name="SHELL_VERBOSITY" value="-1"/>
Expand Down
5 changes: 5 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
__DIR__ . '/tests',
]);

$rectorConfig->skip([
__DIR__ . "/tests/TestBootstrap.php",
__DIR__ . "/tests/TestBootstrapper.php",
]);

$rectorConfig->sets([
// PHP Version set list
SetList::PHP_81,
Expand Down
13 changes: 11 additions & 2 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<defaults autowire="true" autoconfigure="true"/>
<defaults autowire="true" autoconfigure="true" public="true"/>

<prototype namespace="MobilisticsGmbH\MamoConnector\" resource="../../../src/*" exclude="../src/{Resources}"/>
<prototype
namespace="MobilisticsGmbH\MamoConnector\"
resource="../../../src/*"
exclude="../src/{Resources,Dto}"/>

<service id="MobilisticsGmbH\MamoConnector\Service\ExtensionDataProvider">
<argument type="service" id="plugin.repository"/>
</service>

<service id="MobilisticsGmbH\MamoConnector\Controller\Mamo\MetricsController" public="true">
<call method="setContainer">
<argument type="service" id="service_container"/>
</call>
</service>

</services>
</container>
47 changes: 47 additions & 0 deletions tests/Controller/MetricsControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace MobilisticsGmbH\MamoConnector\Tests\Controller;

use MobilisticsGmbH\MamoConnector\MobiMamoConnector;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Test\Controller\StorefrontControllerTestBehaviour;

class MetricsControllerTest extends TestCase
{
use IntegrationTestBehaviour;
use StorefrontControllerTestBehaviour;

public function testMetricsAction(): void
{
/** @var SystemConfigService $systemConfigService */
$systemConfigService = $this->getContainer()->get(SystemConfigService::class);

$systemConfigService->set(MobiMamoConnector::CONFIG_KEY_SECRET, 'testing-secret');

$metrics = $this->request('GET', 'mamo-connector/metrics?unsecure&secret=testing-secret', []);

$content = $metrics->getContent();
static::assertNotFalse($content);
static::assertEquals(200, $metrics->getStatusCode());

static::assertStringContainsString('mamo_shopware6_platform', $content);
}

public function testFailWhenNoSecretProvided(): void
{
/** @var SystemConfigService $systemConfigService */
$systemConfigService = $this->getContainer()->get(SystemConfigService::class);

$systemConfigService->set(MobiMamoConnector::CONFIG_KEY_SECRET, 'testing-secret');

$metrics = $this->request('GET', 'mamo-connector/metrics', []);
$content = $metrics->getContent();

static::assertNotFalse($content);
static::assertEquals(401, $metrics->getStatusCode());
}
}
28 changes: 28 additions & 0 deletions tests/TestBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

/*
* (c) shopware AG <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Shopware\Core\TestBootstrapper;

if (is_readable(__DIR__ . '/../vendor/shopware/platform/src/Core/TestBootstrapper.php')) {
require __DIR__ . '/../vendor/shopware/platform/src/Core/TestBootstrapper.php';
} elseif (is_readable(__DIR__ . '/../vendor/shopware/core/TestBootstrapper.php')) {
require __DIR__ . '/../vendor/shopware/core/TestBootstrapper.php';
} else {
// vendored from platform, only use local TestBootstrapper if not already defined in platform
require __DIR__ . '/TestBootstrapper.php';
}

return (new TestBootstrapper())
->setProjectDir($_SERVER['PROJECT_ROOT'] ?? dirname(__DIR__, 4))
->setLoadEnvFile(true)
//->setForceInstallPlugins(true)
->addCallingPlugin()
->bootstrap()
->setClassLoader(require dirname(__DIR__) . '/vendor/autoload.php')
->getClassLoader();
Loading

0 comments on commit 622df50

Please sign in to comment.