Skip to content

Commit 1e559a6

Browse files
Merge pull request #75 from Zales0123/new-directory-structure
🎃
2 parents b3be707 + 4733c36 commit 1e559a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+811
-255
lines changed

.env.test.dist

Lines changed: 0 additions & 9 deletions
This file was deleted.

.travis.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ before_install:
2626
- echo "memory_limit=4096M" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
2727
- mkdir -p "${SYLIUS_CACHE_DIR}"
2828

29+
- cp tests/Application/.env.test.dist tests/Application/.env.test
30+
- set -a && source tests/Application/.env.test && set +a
31+
2932
install:
3033
- composer require "symfony/symfony:${SYMFONY_VERSION}" --no-interaction --no-update
3134
- composer install --no-interaction --prefer-dist
3235
- (cd tests/Application && yarn install)
3336

3437
before_script:
35-
- mv .env.test.dist .env.test
36-
- set -a && source .env.test && set +a
37-
3838
- (cd tests/Application && bin/console doctrine:database:create --env=test -vvv)
3939
- (cd tests/Application && bin/console doctrine:schema:create --env=test -vvv)
40-
- (cd tests/Application && bin/console assets:install web --env=test -vvv)
40+
- (cd tests/Application && bin/console assets:install --env=test -vvv)
41+
- (cd tests/Application && bin/console cache:warmup --env=test -vvv)
4142
- (cd tests/Application && yarn build)
4243

4344
# Configure display
@@ -67,15 +68,15 @@ before_script:
6768
- java -Dwebdriver.chrome.driver=$SYLIUS_CACHE_DIR/chromedriver -jar $SYLIUS_CACHE_DIR/selenium.jar > /dev/null 2>&1 &
6869

6970
# Run webserver
70-
- (cd tests/Application && bin/console server:run 127.0.0.1:8080 -d web --env=test --quiet > /dev/null 2>&1 &)
71+
- (cd tests/Application && bin/console server:run 127.0.0.1:8080 --env=test --quiet > /dev/null 2>&1 &)
7172

7273
script:
7374
- composer validate --strict
7475
- composer analyse
7576

76-
- vendor/bin/phpspec run
7777
- vendor/bin/phpunit
78-
- vendor/bin/behat --strict -vvv --no-interaction --tags="~@todo" || bin/behat --strict -vvv --no-interaction --rerun --tags="~@todo"
78+
- vendor/bin/phpspec run
79+
- vendor/bin/behat --strict -vvv --no-interaction --tags="~@todo" || vendor/bin/behat --strict -vvv --no-interaction --rerun --tags="~@todo"
7980

8081
after_failure:
8182
- vendor/lakion/mink-debug-extension/travis/tools/upload-textfiles "${SYLIUS_BUILD_DIR}/*.log"

behat.yml.dist

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ default:
1010
- tests/Behat/Resources/services.xml
1111

1212
FriendsOfBehat\SymfonyExtension:
13+
env_file: tests/Application/.env.test
1314
kernel:
14-
class: AppKernel
15-
path: tests/Application/app/AppKernel.php
16-
bootstrap: vendor/autoload.php
15+
env: test
16+
debug: true
17+
class: Tests\Sylius\RefundPlugin\Application\Kernel
18+
path: tests/Application/Kernel.php
19+
bootstrap: ~
1720

1821
Lakion\Behat\MinkDebugExtension:
1922
directory: etc/build

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
"Tests\\Sylius\\RefundPlugin\\": "tests/"
5858
}
5959
},
60-
"autoload-dev": {
61-
"classmap": ["tests/Application/app/AppKernel.php"]
62-
},
6360
"scripts": {
6461
"analyse": [
6562
"vendor/bin/phpstan.phar analyse -c phpstan.neon -l max src/",

src/Resources/config/app/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ sylius_grid:
6464
options:
6565
class: Sylius\RefundPlugin\Entity\CreditMemo
6666
sorting:
67-
number: desc
67+
number: asc
6868
fields:
6969
number:
7070
type: string
7171
label: sylius.ui.number
72+
sortable: ~
7273
orderNumber:
7374
type: string
7475
label: sylius_refund.ui.order_number

tests/Application/.env.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file
2+
# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production.
3+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
4+
5+
###> symfony/framework-bundle ###
6+
APP_ENV=dev
7+
APP_DEBUG=1
8+
APP_SECRET=EDITME
9+
###< symfony/framework-bundle ###
10+
11+
###> doctrine/doctrine-bundle ###
12+
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
13+
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
14+
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
15+
DATABASE_URL=mysql://root@127.0.0.1/sylius_refund_plugin_%kernel.environment%?serverVersion=5.5
16+
###< doctrine/doctrine-bundle ###
17+
18+
###> symfony/swiftmailer-bundle ###
19+
# For Gmail as a transport, use: "gmail://username:password@localhost"
20+
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
21+
# Delivery is disabled by default via "null://localhost"
22+
MAILER_URL=smtp://localhost
23+
###< symfony/swiftmailer-bundle ###

tests/Application/.env.prod.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file
2+
# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production.
3+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
4+
5+
###> symfony/framework-bundle ###
6+
APP_ENV=prod
7+
APP_DEBUG=0
8+
APP_SECRET=EDITME
9+
###< symfony/framework-bundle ###
10+
11+
###> doctrine/doctrine-bundle ###
12+
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
13+
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
14+
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
15+
DATABASE_URL=mysql://root@127.0.0.1/sylius_refund_plugin_%kernel.environment%?serverVersion=5.5
16+
###< doctrine/doctrine-bundle ###
17+
18+
###> symfony/swiftmailer-bundle ###
19+
# For Gmail as a transport, use: "gmail://username:password@localhost"
20+
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
21+
# Delivery is disabled by default via "null://localhost"
22+
MAILER_URL=smtp://localhost
23+
###< symfony/swiftmailer-bundle ###

tests/Application/.env.test.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file
2+
# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production.
3+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
4+
5+
###> symfony/framework-bundle ###
6+
APP_ENV=test
7+
APP_DEBUG=1
8+
APP_SECRET=EDITME
9+
###< symfony/framework-bundle ###
10+
11+
###> doctrine/doctrine-bundle ###
12+
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
13+
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
14+
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
15+
DATABASE_URL=mysql://root@127.0.0.1/sylius_refund_plugin_%kernel.environment%?serverVersion=5.5
16+
###< doctrine/doctrine-bundle ###
17+
18+
###> symfony/swiftmailer-bundle ###
19+
# For Gmail as a transport, use: "gmail://username:password@localhost"
20+
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
21+
# Delivery is disabled by default via "null://localhost"
22+
MAILER_URL=null://localhost
23+
###< symfony/swiftmailer-bundle ###

tests/Application/.gitignore

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
/node_modules/
2-
31
/var/*
4-
!/var/.gitkeep
2+
!/var/.gitignore
3+
4+
/public/assets
5+
/public/bundles
6+
/public/css
7+
/public/js
8+
/public/media
9+
10+
/vendor
11+
/node_modules
512

6-
/web/*
7-
!/web/app.php
8-
!/web/app_dev.php
9-
!/web/app_test.php
10-
!/web/media/credit-memos/
13+
/.env
14+
/.env.prod
15+
/.env.staging
16+
/.env.test
17+
/.env.test_cached

tests/Application/Kernel.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Sylius\RefundPlugin\Application;
6+
7+
use ProxyManager\Proxy\VirtualProxyInterface;
8+
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
9+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
10+
use Symfony\Component\Config\Loader\LoaderInterface;
11+
use Symfony\Component\Config\Resource\FileResource;
12+
use Symfony\Component\DependencyInjection\ContainerBuilder;
13+
use Symfony\Component\DependencyInjection\ContainerInterface;
14+
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
15+
use Symfony\Component\Routing\RouteCollectionBuilder;
16+
17+
final class Kernel extends BaseKernel
18+
{
19+
use MicroKernelTrait;
20+
21+
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
22+
23+
private const IGNORED_SERVICES_DURING_CLEANUP = [
24+
'kernel',
25+
'http_kernel',
26+
'liip_imagine.mime_type_guesser',
27+
'liip_imagine.extension_guesser',
28+
];
29+
30+
public function getCacheDir(): string
31+
{
32+
return $this->getProjectDir() . '/var/cache/' . $this->environment;
33+
}
34+
35+
public function getLogDir(): string
36+
{
37+
return $this->getProjectDir() . '/var/log';
38+
}
39+
40+
public function registerBundles(): iterable
41+
{
42+
$contents = require $this->getProjectDir() . '/config/bundles.php';
43+
foreach ($contents as $class => $envs) {
44+
if (isset($envs['all']) || isset($envs[$this->environment])) {
45+
yield new $class();
46+
}
47+
}
48+
}
49+
50+
public function shutdown(): void
51+
{
52+
if (!$this->isTestEnvironment()) {
53+
parent::shutdown();
54+
55+
return;
56+
}
57+
58+
if (false === $this->booted) {
59+
return;
60+
}
61+
62+
$container = $this->getContainer();
63+
64+
parent::shutdown();
65+
66+
$this->cleanupContainer($container);
67+
}
68+
69+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
70+
{
71+
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
72+
$container->setParameter('container.dumper.inline_class_loader', true);
73+
$confDir = $this->getProjectDir() . '/config';
74+
75+
$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
76+
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
77+
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
78+
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
79+
}
80+
81+
protected function configureRoutes(RouteCollectionBuilder $routes): void
82+
{
83+
$confDir = $this->getProjectDir() . '/config';
84+
85+
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
86+
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
87+
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
88+
}
89+
90+
protected function getContainerBaseClass(): string
91+
{
92+
if ($this->isTestEnvironment()) {
93+
return MockerContainer::class;
94+
}
95+
96+
return parent::getContainerBaseClass();
97+
}
98+
99+
private function isTestEnvironment(): bool
100+
{
101+
return 0 === strpos($this->getEnvironment(), 'test');
102+
}
103+
104+
/**
105+
* Remove all container references from all loaded services
106+
*/
107+
private function cleanupContainer(ContainerInterface $container): void
108+
{
109+
$containerReflection = new \ReflectionObject($container);
110+
$containerServicesPropertyReflection = $containerReflection->getProperty('services');
111+
$containerServicesPropertyReflection->setAccessible(true);
112+
113+
$services = $containerServicesPropertyReflection->getValue($container) ?: [];
114+
foreach ($services as $serviceId => $service) {
115+
if (null === $service) {
116+
continue;
117+
}
118+
119+
if (in_array($serviceId, self::IGNORED_SERVICES_DURING_CLEANUP, true)) {
120+
continue;
121+
}
122+
123+
$serviceReflection = new \ReflectionObject($service);
124+
125+
if ($serviceReflection->implementsInterface(VirtualProxyInterface::class)) {
126+
continue;
127+
}
128+
129+
$servicePropertiesReflections = $serviceReflection->getProperties();
130+
$servicePropertiesDefaultValues = $serviceReflection->getDefaultProperties();
131+
foreach ($servicePropertiesReflections as $servicePropertyReflection) {
132+
$defaultPropertyValue = null;
133+
if (isset($servicePropertiesDefaultValues[$servicePropertyReflection->getName()])) {
134+
$defaultPropertyValue = $servicePropertiesDefaultValues[$servicePropertyReflection->getName()];
135+
}
136+
137+
$servicePropertyReflection->setAccessible(true);
138+
$servicePropertyReflection->setValue($service, $defaultPropertyValue);
139+
}
140+
}
141+
142+
$containerServicesPropertyReflection->setValue($container, null);
143+
}
144+
}

0 commit comments

Comments
 (0)