Skip to content

Commit e32a2f2

Browse files
committed
Add composer support
1 parent b372531 commit e32a2f2

File tree

4 files changed

+90
-55
lines changed

4 files changed

+90
-55
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Frosh\ClassicPhpunitBridge\Bootstrap\Functional;
4+
5+
use Shopware\Models\Shop\Shop;
6+
7+
class ComposerKernel extends \AppKernel
8+
{
9+
/**
10+
* Static method to start boot kernel without leaving local scope in test helper
11+
*/
12+
public static function start()
13+
{
14+
$kernel = new self('testing', true);
15+
$kernel->boot();
16+
17+
$container = $kernel->getContainer();
18+
$container->get('plugins')->Core()->ErrorHandler()->registerErrorHandler(E_ALL | E_STRICT);
19+
20+
/** @var \Shopware\Models\Shop\Repository $repository */
21+
$repository = $container->get('models')->getRepository(Shop::class);
22+
23+
$shop = $repository->getActiveDefault();
24+
if (Shopware()->Container()->has('shopware.components.shop_registration_service')) {
25+
Shopware()->Container()->get('shopware.components.shop_registration_service')->registerShop($shop);
26+
} else {
27+
$shop->registerResources();
28+
}
29+
30+
$_SERVER['HTTP_HOST'] = $shop->getHost();
31+
}
32+
33+
protected function getConfigPath()
34+
{
35+
return __DIR__ . '/config.php';
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Frosh\ClassicPhpunitBridge\Bootstrap\Functional;
4+
5+
use Shopware\Models\Shop\Shop;
6+
7+
class NormalKernel extends \Shopware\Kernel
8+
{
9+
/**
10+
* Static method to start boot kernel without leaving local scope in test helper
11+
*/
12+
public static function start()
13+
{
14+
$kernel = new self('testing', true);
15+
$kernel->boot();
16+
17+
$container = $kernel->getContainer();
18+
$container->get('plugins')->Core()->ErrorHandler()->registerErrorHandler(E_ALL | E_STRICT);
19+
20+
/** @var \Shopware\Models\Shop\Repository $repository */
21+
$repository = $container->get('models')->getRepository(Shop::class);
22+
23+
$shop = $repository->getActiveDefault();
24+
if (Shopware()->Container()->has('shopware.components.shop_registration_service')) {
25+
Shopware()->Container()->get('shopware.components.shop_registration_service')->registerShop($shop);
26+
} else {
27+
$shop->registerResources();
28+
}
29+
30+
$_SERVER['HTTP_HOST'] = $shop->getHost();
31+
}
32+
33+
protected function getConfigPath()
34+
{
35+
return __DIR__ . '/config.php';
36+
}
37+
}

src/Bootstrap/Functional/bootstrap.php

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,18 @@
2020
}
2121

2222
use Doctrine\Common\Annotations\AnnotationRegistry;
23-
use Shopware\Models\Shop\Shop;
24-
25-
class TestKernel extends \Shopware\Kernel
26-
{
27-
/**
28-
* Static method to start boot kernel without leaving local scope in test helper
29-
*/
30-
public static function start()
31-
{
32-
$kernel = new self('testing', true);
33-
$kernel->boot();
34-
35-
$container = $kernel->getContainer();
36-
$container->get('plugins')->Core()->ErrorHandler()->registerErrorHandler(E_ALL | E_STRICT);
37-
38-
/** @var \Shopware\Models\Shop\Repository $repository */
39-
$repository = $container->get('models')->getRepository(Shop::class);
40-
41-
$shop = $repository->getActiveDefault();
42-
if (Shopware()->Container()->has('shopware.components.shop_registration_service')) {
43-
Shopware()->Container()->get('shopware.components.shop_registration_service')->registerShop($shop);
44-
} else {
45-
$shop->registerResources();
46-
}
47-
48-
$_SERVER['HTTP_HOST'] = $shop->getHost();
49-
}
23+
use Dotenv\Dotenv;
5024

51-
protected function getConfigPath()
52-
{
53-
return __DIR__ . '/config.php';
54-
}
25+
$kernel = \Frosh\ClassicPhpunitBridge\Bootstrap\Functional\NormalKernel::class;
26+
if (file_exists($searchDirectory . '/.env')) {
27+
$dotenv = Dotenv::create($searchDirectory);
28+
$dotenv->load();
29+
$kernel = \Frosh\ClassicPhpunitBridge\Bootstrap\Functional\ComposerKernel::class;
5530
}
31+
define('SEARCH_DIRECTORY', $searchDirectory);
32+
5633

5734
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
5835

59-
TestKernel::start();
36+
$kernel::start();
6037

src/Bootstrap/Functional/config.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
<?php
2-
/**
3-
* Shopware 5
4-
* Copyright (c) shopware AG
5-
*
6-
* According to our dual licensing model, this program can be used either
7-
* under the terms of the GNU Affero General Public License, version 3,
8-
* or under a proprietary license.
9-
*
10-
* The texts of the GNU Affero General Public License with an additional
11-
* permission and of our proprietary license can be found at and
12-
* in the LICENSE file you have received along with this program.
13-
*
14-
* This program is distributed in the hope that it will be useful,
15-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
* GNU Affero General Public License for more details.
18-
*
19-
* "Shopware" is a registered trademark of shopware AG.
20-
* The licensing of the program under the AGPLv3 does not imply a
21-
* trademark license. Therefore any rights, title and interest in
22-
* our trademarks remain entirely with us.
23-
*/
242

25-
return array_replace_recursive($this->loadConfig($this->AppPath() . 'Configs/Default.php'), [
3+
$config = $this->loadConfig($this->AppPath() . 'Configs/Default.php');
4+
if (file_exists(SEARCH_DIRECTORY . '/app/config/config.php')) {
5+
$config = require SEARCH_DIRECTORY . '/app/config/config.php';
6+
}
7+
8+
9+
return array_replace_recursive($config, [
2610
'front' => [
2711
'throwExceptions' => true,
2812
'disableOutputBuffering' => false,

0 commit comments

Comments
 (0)