Skip to content

Commit

Permalink
Add composer support
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Oct 16, 2019
1 parent b372531 commit e32a2f2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 55 deletions.
37 changes: 37 additions & 0 deletions src/Bootstrap/Functional/ComposerKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Frosh\ClassicPhpunitBridge\Bootstrap\Functional;

use Shopware\Models\Shop\Shop;

class ComposerKernel extends \AppKernel
{
/**
* Static method to start boot kernel without leaving local scope in test helper
*/
public static function start()
{
$kernel = new self('testing', true);
$kernel->boot();

$container = $kernel->getContainer();
$container->get('plugins')->Core()->ErrorHandler()->registerErrorHandler(E_ALL | E_STRICT);

/** @var \Shopware\Models\Shop\Repository $repository */
$repository = $container->get('models')->getRepository(Shop::class);

$shop = $repository->getActiveDefault();
if (Shopware()->Container()->has('shopware.components.shop_registration_service')) {
Shopware()->Container()->get('shopware.components.shop_registration_service')->registerShop($shop);
} else {
$shop->registerResources();
}

$_SERVER['HTTP_HOST'] = $shop->getHost();
}

protected function getConfigPath()
{
return __DIR__ . '/config.php';
}
}
37 changes: 37 additions & 0 deletions src/Bootstrap/Functional/NormalKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Frosh\ClassicPhpunitBridge\Bootstrap\Functional;

use Shopware\Models\Shop\Shop;

class NormalKernel extends \Shopware\Kernel
{
/**
* Static method to start boot kernel without leaving local scope in test helper
*/
public static function start()
{
$kernel = new self('testing', true);
$kernel->boot();

$container = $kernel->getContainer();
$container->get('plugins')->Core()->ErrorHandler()->registerErrorHandler(E_ALL | E_STRICT);

/** @var \Shopware\Models\Shop\Repository $repository */
$repository = $container->get('models')->getRepository(Shop::class);

$shop = $repository->getActiveDefault();
if (Shopware()->Container()->has('shopware.components.shop_registration_service')) {
Shopware()->Container()->get('shopware.components.shop_registration_service')->registerShop($shop);
} else {
$shop->registerResources();
}

$_SERVER['HTTP_HOST'] = $shop->getHost();
}

protected function getConfigPath()
{
return __DIR__ . '/config.php';
}
}
41 changes: 9 additions & 32 deletions src/Bootstrap/Functional/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,18 @@
}

use Doctrine\Common\Annotations\AnnotationRegistry;
use Shopware\Models\Shop\Shop;

class TestKernel extends \Shopware\Kernel
{
/**
* Static method to start boot kernel without leaving local scope in test helper
*/
public static function start()
{
$kernel = new self('testing', true);
$kernel->boot();

$container = $kernel->getContainer();
$container->get('plugins')->Core()->ErrorHandler()->registerErrorHandler(E_ALL | E_STRICT);

/** @var \Shopware\Models\Shop\Repository $repository */
$repository = $container->get('models')->getRepository(Shop::class);

$shop = $repository->getActiveDefault();
if (Shopware()->Container()->has('shopware.components.shop_registration_service')) {
Shopware()->Container()->get('shopware.components.shop_registration_service')->registerShop($shop);
} else {
$shop->registerResources();
}

$_SERVER['HTTP_HOST'] = $shop->getHost();
}
use Dotenv\Dotenv;

protected function getConfigPath()
{
return __DIR__ . '/config.php';
}
$kernel = \Frosh\ClassicPhpunitBridge\Bootstrap\Functional\NormalKernel::class;
if (file_exists($searchDirectory . '/.env')) {
$dotenv = Dotenv::create($searchDirectory);
$dotenv->load();
$kernel = \Frosh\ClassicPhpunitBridge\Bootstrap\Functional\ComposerKernel::class;
}
define('SEARCH_DIRECTORY', $searchDirectory);


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

TestKernel::start();
$kernel::start();

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

return array_replace_recursive($this->loadConfig($this->AppPath() . 'Configs/Default.php'), [
$config = $this->loadConfig($this->AppPath() . 'Configs/Default.php');
if (file_exists(SEARCH_DIRECTORY . '/app/config/config.php')) {
$config = require SEARCH_DIRECTORY . '/app/config/config.php';
}


return array_replace_recursive($config, [
'front' => [
'throwExceptions' => true,
'disableOutputBuffering' => false,
Expand Down

0 comments on commit e32a2f2

Please sign in to comment.