Skip to content

Commit

Permalink
Merge pull request Sylius#6811 from TheMadeleine/bundles-services-test
Browse files Browse the repository at this point in the history
[Bundles] Services initialization tests
  • Loading branch information
pjedrzejewski authored Nov 29, 2016
2 parents f88f3e6 + 03fc42e commit fa32cdd
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ bin/

composer.phar
composer.lock

test/app/cache
test/app/logs
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@
"webmozart/assert": "^1.0"
},
"require-dev": {
"doctrine/orm": "^2.5",
"phpspec/phpspec": "^3.2",
"phpunit/phpunit": "^5.6",
"twig/twig": "^1.0",
"sylius/currency-bundle": "^1.0",
"symfony/form": "^3.2@rc",
"twig/twig": "^1.0"
"symfony/browser-kit": "^3.2@rc",
"incenteev/composer-parameter-handler": "~2.0",
"polishsymfonycommunity/symfony-mocker-container": "^1.0"
},
"config": {
"bin-dir": "bin"
Expand All @@ -41,7 +46,10 @@
"psr-4": { "Sylius\\Bundle\\MoneyBundle\\": "" }
},
"autoload-dev": {
"psr-4": { "Sylius\\Bundle\\MoneyBundle\\spec\\": "spec/" }
"psr-4": {
"Sylius\\Bundle\\MoneyBundle\\spec\\": "spec/",
"AppBundle\\": "test/src/AppBundle/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -54,6 +62,9 @@
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"incenteev-parameters": {
"file": "test/app/config/parameters.yml"
}
}
}
18 changes: 18 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="test/app/autoload.php"
>
<php>
<server name="KERNEL_DIR" value="test/app/" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
</php>
<testsuites>
<testsuite name="SyliusMoneyBundle Test Suite">
<directory>./test/</directory>
</testsuite>
</testsuites>
</phpunit>
59 changes: 59 additions & 0 deletions test/app/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

/**
* @author Magdalena Banasiak <[email protected]>
*/
class AppKernel extends Kernel
{
/**
* {@inheritdoc}
*/
public function registerBundles()
{
return [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new winzou\Bundle\StateMachineBundle\winzouStateMachineBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle($this),
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
new Sylius\Bundle\MoneyBundle\SyliusMoneyBundle(),
new Sylius\Bundle\ResourceBundle\SyliusResourceBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
];
}

/**
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config.yml');
}

/**
* {@inheritdoc}
*/
protected function getContainerBaseClass()
{
if ('test' === $this->environment) {
return MockerContainer::class;
}

return parent::getContainerBaseClass();
}
}
20 changes: 20 additions & 0 deletions test/app/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = require __DIR__.'/../../vendor/autoload.php';

require __DIR__.'/AppKernel.php';

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

return $loader;
43 changes: 43 additions & 0 deletions test/app/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
imports:
- { resource: "@SyliusMoneyBundle/test/app/config/parameters.yml" }

framework:
assets: false
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
form: ~
csrf_protection: true
templating:
engines: ['twig']
default_locale: "%locale%"
session:
handler_id: ~
http_method_override: true
test: ~
session:
storage_id: session.storage.mock_file

twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"

doctrine:
dbal:
driver: "%database_driver%"
path: "%database_path%"
charset: UTF8
orm:
entity_managers:
default:
auto_mapping: true

fos_rest:
view:
formats:
json: true
empty_content: 204
format_listener:
rules:
- { path: '^/', priorities: ['json'], fallback_format: json, prefer_extension: true }
6 changes: 6 additions & 0 deletions test/app/config/parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
database_driver: pdo_sqlite
database_path: "%kernel.root_dir%/db.sql"

locale: en_US
secret: "Three can keep a secret, if two of them are dead."
24 changes: 24 additions & 0 deletions test/app/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env php
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

set_time_limit(0);

require_once __DIR__ . "/../../vendor/autoload.php";
require_once __DIR__.'/AppKernel.php';

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;

$input = new ArgvInput();

$application = new Application(new AppKernel('test', true));
$application->run($input);
40 changes: 40 additions & 0 deletions test/src/Tests/SyliusMoneyBundleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\MoneyBundle\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* @author Magdalena Banasiak <[email protected]>
*/
class SyliusMoneyBundleTest extends WebTestCase
{
/**
* @test
*/
public function its_services_are_intitializable()
{
/** @var ContainerInterface $container */
$container = self::createClient()->getContainer();

$services = $container->getServiceIds();

$services = array_filter($services, function ($serviceId) {
return false !== strpos($serviceId, 'sylius');
});

foreach ($services as $id) {
$container->get($id);
}
}
}

0 comments on commit fa32cdd

Please sign in to comment.