Skip to content

Commit 990655b

Browse files
authored
Dep injection (#25)
* Loader with DI added * After test cache clearance * Tests added * Fixture Loaders are now private * CS and debug * SF 4.1 and 4.2@dev tests * Documentation * Branch aliases updated
1 parent 99fed9c commit 990655b

32 files changed

+587
-474
lines changed

.php_cs.dist

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
$header = 'The MIT License (MIT)
4+
5+
Copyright (c) 2016-2018 Spomky-Labs
6+
7+
This software may be modified and distributed under the terms
8+
of the MIT license. See the LICENSE file for details.';
9+
10+
$finder = PhpCsFixer\Finder::create()
11+
->in(__DIR__.'/src')
12+
;
13+
14+
return PhpCsFixer\Config::create()
15+
->setRules([
16+
'@PSR1' => true,
17+
'@PSR2' => true,
18+
'@Symfony' => true,
19+
'@DoctrineAnnotation' => true,
20+
'@PHP70Migration' => true,
21+
'@PHP71Migration' => true,
22+
'strict_param' => true,
23+
'strict_comparison' => true,
24+
'array_syntax' => ['syntax' => 'short'],
25+
'array_indentation' => true,
26+
'ordered_imports' => true,
27+
'protected_to_private' => true,
28+
'declare_strict_types' => true,
29+
'native_function_invocation' => [
30+
'include' => ['@compiler_optimized'],
31+
'scope' => 'namespaced',
32+
],
33+
'mb_str_functions' => true,
34+
'linebreak_after_opening_tag' => true,
35+
'combine_consecutive_issets' => true,
36+
'combine_consecutive_unsets' => true,
37+
'compact_nullable_typehint' => true,
38+
'no_superfluous_phpdoc_tags' => true,
39+
'no_superfluous_elseif' => true,
40+
'phpdoc_trim_consecutive_blank_line_separation' => true,
41+
'phpdoc_order' => true,
42+
'pow_to_exponentiation' => true,
43+
'simplified_null_return' => true,
44+
'header_comment' => [
45+
'header' => $header,
46+
],
47+
'align_multiline_comment' => [
48+
'comment_type' => 'all_multiline',
49+
],
50+
'php_unit_test_annotation' => [
51+
'case' => 'snake',
52+
'style' => 'annotation',
53+
],
54+
'php_unit_test_case_static_method_calls' => true,
55+
])
56+
->setRiskyAllowed(true)
57+
->setUsingCache(true)
58+
->setFinder($finder)
59+
;

.travis.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ matrix:
1717
- php: 7.1
1818
env: SYMFONY_VERSION='3.4.*'
1919
- php: 7.1
20-
env: SYMFONY_VERSION='4.0.*'
21-
- php: 7.1
22-
env: DEPS=dev SYMFONY_VERSION='4.1.*'
20+
env: SYMFONY_VERSION='4.1.*'
2321
- php: 7.2
2422
env: SYMFONY_VERSION='4.0.*'
23+
- php: 7.2
24+
env: SYMFONY_VERSION='4.1.*'
2525
- php: nightly
26-
env: DEPS=dev SYMFONY_VERSION='4.1.*'
26+
env: DEPS=dev SYMFONY_VERSION='4.2.*'
2727
allow_failures:
28-
- php: 7.1
29-
env: SYMFONY_VERSION='4.1.*'
3028
- php: nightly
31-
env: SYMFONY_VERSION='4.1.*'
29+
env: DEPS=dev SYMFONY_VERSION='4.2.*'
3230

3331
before_install:
3432
- composer self-update

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ default:
2020
extensions:
2121
BehatExtension\DoctrineDataFixturesExtension\Extension:
2222
lifetime: 'feature'
23-
autoload: true
2423
directories: ~
2524
fixtures: ~
2625
```
@@ -29,14 +28,15 @@ When **lifetime** is set to "feature" (or unspecified), data fixtures are reload
2928
when **lifetime** is set to "scenario", data fixtures are reloaded between scenarios (i.e., increased
3029
test isolation at the expense of increased run time).
3130
32-
When **autoload** is true, the extension will load the data fixtures for registered bundles.
33-
Please note that only fixtures stored in the folder `/DataFixtures/ORM` of the bundles are loaded.
34-
If you want to load fixtures tagged with `doctrine.fixture.orm`, you must enable the bundle `BehatExtension\DoctrineDataFixturesExtension\Bundle\BehatDoctrineDataFixturesExtensionBundle`
35-
in your test `AppKernel` class.
31+
When **fixtures** is set, the extension will load the specified fixture classes.
32+
This must contain a list of fully qualified class names. Classes MUST not have any constructor arguments (or at least optional).
33+
If the interface `Symfony\Component\DependencyInjection\ContainerAwareInterface` is implemented, the container is set to the fixture loader.
3634

37-
When **fixtures** is set, the DoctrineDataFixtures extension will load the specified fixture classes.
35+
When **directories** is set, the extension will load the data fixtures globed from the respective directories.
36+
Classes MUST not have any constructor arguments (or at least optional).
37+
If the interface `Symfony\Component\DependencyInjection\ContainerAwareInterface` is implemented, the container is set to the fixture loader.
3838

39-
When **directories** is set, the DoctrineDataFixtures extension will load the data fixtures globed from the respective directories.
39+
This extension will also load every fixtures declared as services and tagged with `doctrine.fixture.orm`.
4040

4141
```yaml
4242
# behat.yml
@@ -45,7 +45,6 @@ default:
4545
extensions:
4646
BehatExtension\DoctrineDataFixturesExtension\Extension:
4747
lifetime: 'feature'
48-
autoload: true
4948
directories:
5049
- '/project/src/AcmeAnalytics/Tests/DataFixtures/ORM'
5150
fixtures:
@@ -59,7 +58,10 @@ default:
5958
To speed up the tests, a backup system is available. The whole database will be set in cache and reloaded when needed.
6059
You should periodically clear the cache as it does not detect changes to the data fixture contents because the hash is based on the collection of data fixture class names.
6160

62-
This feature is only available for the following SGDB: SQLite, MySQL, PostgreSQL.
61+
This feature is only available for SQLite, MySQL and PostgreSQL.
62+
63+
* For MySQL, `mysql` and `mysqldump` must be available.
64+
* For PostgreSQL, `pg_restore` and `pg_dump` must be available.
6365

6466
It is enabled by default. To disable it, you just have to set `use_backup: false` in the extension configuration:
6567

@@ -70,7 +72,6 @@ default:
7072
extensions:
7173
BehatExtension\DoctrineDataFixturesExtension\Extension:
7274
lifetime: 'feature'
73-
autoload: true
7475
use_backup: false
7576
```
7677

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
"require-dev": {
2828
"doctrine/doctrine-bundle": "^1.8",
2929
"doctrine/doctrine-fixtures-bundle": "^3.0",
30-
"phpstan/phpstan": "^0.9.2",
31-
"symfony/process": "^3.4|^4.0"
30+
"symfony/process": "^3.4|^4.0",
31+
"adamquaile/behat-command-runner-extension": "^0.1.1",
32+
"symfony/var-dumper": "^3.4|^4.0"
3233
},
3334
"suggest": {
3435
"doctrine/migrations": "Uses DBAL to load versioned database schema and migration classes",
@@ -42,7 +43,8 @@
4243
},
4344
"extra": {
4445
"branch-alias": {
45-
"dev-master": "5.0.x-dev"
46+
"v6.0": "6.0.x-dev",
47+
"v5.0": "5.0.x-dev"
4648
}
4749
}
4850
}

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
includes:
3+
- %rootDir%/../phpstan-phpunit/extension.neon
4+
- %rootDir%/../phpstan-phpunit/rules.neon
5+
- %rootDir%/../phpstan-symfony/extension.neon

src/Bundle/BehatDoctrineDataFixturesExtensionBundle.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121
final class BehatDoctrineDataFixturesExtensionBundle extends Bundle
2222
{
23-
/**
24-
* {@inheritdoc}
25-
*/
2623
public function getContainerExtension()
2724
{
2825
return new class() extends Extension {

src/Context/FixtureServiceAwareContextInterface.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,7 @@
1515

1616
use BehatExtension\DoctrineDataFixturesExtension\Service\FixtureService;
1717

18-
/**
19-
* Interface FixtureServiceAwareContextInterface.
20-
*/
2118
interface FixtureServiceAwareContextInterface
2219
{
23-
/**
24-
* Set the FixtureService.
25-
*
26-
* @param FixtureService $service
27-
*
28-
* @return void
29-
*/
3020
public function setFixtureService(FixtureService $service): void;
3121
}

src/Context/Initializer/FixtureServiceAwareInitializer.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,15 @@
1818
use BehatExtension\DoctrineDataFixturesExtension\Context\FixtureServiceAwareContextInterface;
1919
use BehatExtension\DoctrineDataFixturesExtension\Service\FixtureService;
2020

21-
/**
22-
* Class FixtureServiceAwareInitializer.
23-
*/
2421
final class FixtureServiceAwareInitializer implements ContextInitializer
2522
{
26-
/**
27-
* @var FixtureService
28-
*/
2923
private $fixtureService;
3024

31-
/**
32-
* FixtureServiceAwareInitializer constructor.
33-
*
34-
* @param FixtureService $fixtureService
35-
*/
3625
public function __construct(FixtureService $fixtureService)
3726
{
3827
$this->fixtureService = $fixtureService;
3928
}
4029

41-
/**
42-
* {@inheritdoc}
43-
*/
4430
public function initializeContext(Context $context)
4531
{
4632
if (!$context instanceof FixtureServiceAwareContextInterface && !$this->usesReferenceDictionary($context)) {
@@ -52,10 +38,6 @@ public function initializeContext(Context $context)
5238

5339
/**
5440
* Checks whether the context uses the ReferenceDictionary trait.
55-
*
56-
* @param Context $context
57-
*
58-
* @return bool
5941
*/
6042
private function usesReferenceDictionary(Context $context): bool
6143
{
@@ -65,6 +47,6 @@ private function usesReferenceDictionary(Context $context): bool
6547
return false;
6648
}
6749

68-
return in_array('BehatExtension\DoctrineDataFixturesExtension\Context\ReferenceDictionary', $refl->getTraitNames());
50+
return \in_array('BehatExtension\DoctrineDataFixturesExtension\Context\ReferenceDictionary', $refl->getTraitNames(), true);
6951
}
7052
}

src/Context/ReferenceDictionary.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515

1616
use BehatExtension\DoctrineDataFixturesExtension\Service\FixtureService;
1717

18-
/**
19-
* Class ReferenceDictionary.
20-
*/
2118
trait ReferenceDictionary
2219
{
2320
/**
@@ -27,10 +24,6 @@ trait ReferenceDictionary
2724

2825
/**
2926
* Sets the Reference Repository.
30-
*
31-
* @param FixtureService $service
32-
*
33-
* @return void
3427
*/
3528
public function setFixtureService(FixtureService $service): void
3629
{
@@ -39,8 +32,6 @@ public function setFixtureService(FixtureService $service): void
3932

4033
/**
4134
* Returns the Reference Repository.
42-
*
43-
* @return FixtureService
4435
*/
4536
public function getFixtureService(): FixtureService
4637
{
@@ -50,23 +41,17 @@ public function getFixtureService(): FixtureService
5041
/**
5142
* Takes a reference string and returns the entity created in fixtures.
5243
*
53-
* @param string $reference
54-
*
5544
* @return object
5645
*/
57-
public function getReference($reference)
46+
public function getReference(string $reference)
5847
{
5948
return $this->fixtureService->getReferenceRepository()->getReference($reference);
6049
}
6150

6251
/**
6352
* Checks if the reference is known to the Repository.
64-
*
65-
* @param string $reference
66-
*
67-
* @return bool
6853
*/
69-
public function hasReference($reference): bool
54+
public function hasReference(string $reference): bool
7055
{
7156
return $this->fixtureService->getReferenceRepository()->hasReference($reference);
7257
}

0 commit comments

Comments
 (0)