Skip to content

Commit 2db5b76

Browse files
authored
Add support for service factories (#283)
* Add support for service factories * Housekeeping
1 parent f815081 commit 2db5b76

File tree

19 files changed

+488
-97
lines changed

19 files changed

+488
-97
lines changed

.php_cs

-24
This file was deleted.

.styleci.yml

-15
This file was deleted.

.travis.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ env:
1616
- PHPUNIT_CONFIG='phpunit.xml.dist'
1717
- PHPUNIT_FLAGS='--stop-on-failure --verbose'
1818

19+
cache:
20+
directories:
21+
- $HOME/.composer/cache/files
22+
- $HOME/.bin/
23+
1924
services:
2025
- mysql
2126

@@ -26,7 +31,7 @@ matrix:
2631
env:
2732
- COMPOSER_FLAGS="--prefer-lowest"
2833
- COVERAGE="true"
29-
- PHPUNIT_FLAGS="--coverage-text --coverage-clover=coverage.xml"
34+
- PHPUNIT_FLAGS="--stop-on-failure --verbose --coverage-text --coverage-clover=coverage.xml"
3035
- SYMFONY_VERSION="~3.1.0"
3136
- php: '7.0'
3237
env: SYMFONY_VERSION='~3.2.0@dev'
@@ -35,11 +40,6 @@ matrix:
3540
- php: '7.1'
3641
- env: SYMFONY_VERSION='~3.2.0@dev'
3742

38-
cache:
39-
directories:
40-
- $HOME/.composer/cache/files
41-
- $HOME/.bin/
42-
4343
before_install:
4444
- set -eo pipefail
4545
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ project to know which database/ORM is supported.
2525
3. [Advanced usage](doc/advanced-usage.md)
2626
1. [Enabling databases](doc/advanced-usage.md#enabling-databases)
2727
2. [Environment specific fixtures](doc/advanced-usage.md#environment-specific-fixtures)
28-
2. [Fixtures parameters](doc/advanced-usage.md#fixtures-parameters)
28+
3. [Fixtures parameters](doc/advanced-usage.md#fixtures-parameters)
2929
1. [Alice parameters](doc/advanced-usage.md#alice-parameters)
30-
1. [Application parameters](doc/advanced-usage.md#application-parameters)
30+
2. [Application parameters](doc/advanced-usage.md#application-parameters)
31+
4. [Use service factories](doc/advanced-usage.md#use-service-factories)
3132
4. [Custom Faker Providers](doc/faker-providers.md)
3233
5. [Custom Alice Processors](doc/alice-processors.md)
3334
7. [Resources](#resources)

bin/clear_cache.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# This file is part of the Hautelook\AliceBundle package.
5+
#
6+
# (c) Baldur Rensch <[email protected]>
7+
#
8+
# For the full copyright and license information, please view the LICENSE
9+
# file that was distributed with this source code.
10+
#
11+
12+
rm -rf fixtures/Functional/cache/*ch

composer.json

+6-22
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,16 @@
3333
"symfony/finder": "^2.7||^3.0"
3434
},
3535
"require-dev": {
36-
"sllh/php-cs-fixer-styleci-bridge": "^1.0",
37-
"symfony/console": "^2.3||~3.0",
38-
"symfony/framework-bundle": "^2.3||^3.0",
39-
"symfony/phpunit-bridge": "^2.7.4||^3.0",
40-
"symfony/yaml": "^2.3||^3.0",
41-
"symfony/validator": "^2.3|^3.0",
42-
"bamarni/composer-bin-plugin": "dev-master",
43-
"theofidry/alice-data-fixtures": "^1.0@dev",
44-
"doctrine/orm": "^2.5",
45-
"doctrine/doctrine-bundle": "^1.6",
4636
"doctrine/data-fixtures": "^1.2",
37+
"doctrine/doctrine-bundle": "^1.6",
38+
"doctrine/orm": "^2.5",
4739
"phpunit/phpunit": "^5.6",
48-
"theofidry/psysh-bundle": "^2.0",
49-
"symfony/monolog-bundle": "^2.11",
50-
"easycorp/easy-log-handler": "^1.0"
40+
"symfony/symfony": "^2.3||~3.0",
41+
"symfony/phpunit-bridge": "^3.1",
42+
"theofidry/alice-data-fixtures": "^1.0@dev"
5143
},
5244
"suggest": {
53-
"theofidry/alice-bundle-extension": "Behat extension for HautelookAliceBundle",
54-
"doctrine/data-fixtures": "To use Doctrine fixtures loader",
55-
"doctrine/orm": "To use Doctrine ORM",
56-
"doctrine/doctrine-bundle": "To use Doctrine with Symfony",
57-
"doctrine/mongodb-odm": "To use Doctrine MongoDB",
58-
"doctrine/mongodb-odm-bundle": "To use Doctrine MongoDB with Symfony",
59-
"jackalope/jackalope-doctrine-dbal": "To use Doctrine PHPCR",
60-
"doctrine/phpcr-odm": "To use Doctrine PHPCR ODM",
61-
"doctrine/phpcr-bundle": "To use Doctrine PHPCR ODM with Symfony"
45+
"theofidry/alice-bundle-extension": "Behat extension for HautelookAliceBundle"
6246
},
6347
"extra": {
6448
"branch-alias": {

doc/advanced-usage.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ For more, check [Alice documentation](https://github.com/nelmio/alice#table-of-c
7272
You can access out of the box to your application parameters:
7373
7474
```yaml
75-
# AppBundle/DataFixtures/ORM/dummy.yml
75+
# app/Resources/fixtures/orm/dummy.yml
7676

7777
AppBundle\Entity\Dummy:
7878
dummy_0:
@@ -83,5 +83,20 @@ Alice parameters will **not** be injected in your application `ParameterBag`, i.
8383
fixtures.
8484

8585

86+
# Use service factories
87+
88+
If your entity `AppBundle\Entity\Dummy` requires a factory registered as a service (Alice already supports [static
89+
factories](https://github.com/nelmio/alice/blob/master/doc/complete-reference.md#specifying-constructor-arguments)) to
90+
`dummy_factory` be instantiated, you can specify it as a constructor:
91+
92+
```yaml
93+
# app/Resources/fixtures/orm/dummy.yml
94+
95+
AppBundle\Entity\Dummy:
96+
dummy_0:
97+
__construct: { '@dummy_factory::create': ['<username()>'] }
98+
```
99+
100+
86101
Previous chapter: [Basic usage](../README.md#basic-usage)<br />
87102
Next chapter: [Custom Faker Providers](faker-providers.md)

fixtures/Functional/AppKernel.php

-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1515
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
16-
use Fidry\PsyshBundle\PsyshBundle;
1716
use Hautelook\AliceBundle\HautelookAliceBundle;
1817
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
1918
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
20-
use Symfony\Bundle\MonologBundle\MonologBundle;
2119
use Symfony\Component\Config\Loader\LoaderInterface;
2220
use Symfony\Component\HttpKernel\Kernel;
2321

@@ -30,12 +28,10 @@ public function registerBundles()
3028
{
3129
return [
3230
new FrameworkBundle(),
33-
new MonologBundle(),
3431
new NelmioAliceBundle(),
3532
new FidryAliceDataFixturesBundle(),
3633
new DoctrineBundle(),
3734
new HautelookAliceBundle(),
38-
new PsyshBundle(),
3935
];
4036
}
4137

fixtures/Functional/ConfigurableKernel.php

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Hautelook\AliceBundle\HautelookAliceBundle;
1515
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
16-
use Symfony\Bundle\MonologBundle\MonologBundle;
1716
use Symfony\Component\Config\Loader\LoaderInterface;
1817
use Symfony\Component\HttpKernel\Bundle\Bundle;
1918
use Symfony\Component\HttpKernel\Kernel;
@@ -33,7 +32,6 @@ public function registerBundles()
3332
return array_merge(
3433
[
3534
new FrameworkBundle(),
36-
new MonologBundle(),
3735
new HautelookAliceBundle(),
3836
],
3937
$this->addedBundles
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Hautelook\AliceBundle package.
5+
*
6+
* (c) Baldur Rensch <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types = 1);
13+
14+
namespace Hautelook\AliceBundle\Functional\TestBundle\Entity;
15+
16+
/**
17+
* @author Théo FIDRY <[email protected]>
18+
*/
19+
class CityFactory
20+
{
21+
public function create(string $name): City
22+
{
23+
$instance = new City();
24+
$instance->name = $name;
25+
26+
return $instance;
27+
}
28+
}

fixtures/Functional/TestKernel.php

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Hautelook\AliceBundle\Functional\TestBundle\TestBundle;
2121
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
2222
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
23-
use Symfony\Bundle\MonologBundle\MonologBundle;
2423
use Symfony\Component\Config\Loader\LoaderInterface;
2524
use Symfony\Component\HttpKernel\Kernel;
2625

@@ -33,7 +32,6 @@ public function registerBundles()
3332
{
3433
return [
3534
new FrameworkBundle(),
36-
new MonologBundle(),
3735
new NelmioAliceBundle(),
3836
new FidryAliceDataFixturesBundle(),
3937
new DoctrineBundle(),

fixtures/Functional/config/config.yml

+5-16
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,13 @@ framework:
1313
session: ~
1414
test: ~
1515

16-
monolog:
17-
handlers:
18-
buffered:
19-
type: buffer
20-
handler: easylog
21-
level: debug
22-
easylog:
23-
type: service
24-
id: easycorp.easylog.handler
25-
console:
26-
type: console
27-
2816
services:
2917
data_fixtures.faker.provider.foo:
3018
class: Hautelook\AliceBundle\Functional\TestBundle\DataFixtures\Faker\Provider\FooProvider
3119
tags: [ { name: nelmio_alice.faker.provider } ]
3220

33-
easycorp.easylog.handler:
34-
class: EasyCorp\EasyLog\EasyLogHandler
35-
arguments:
36-
- '%kernel.logs_dir%/%kernel.environment%.log'
21+
app.city_factory:
22+
class: Hautelook\AliceBundle\Functional\TestBundle\Entity\CityFactory
23+
24+
logger:
25+
class: Psr\Log\NullLogger

fixtures/HttpKernel/DummyKernel.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,13 @@ public function getLogDir()
172172
public function getCharset()
173173
{
174174
$this->__call(__METHOD__, func_get_args());
175-
}}
175+
}
176+
177+
/**
178+
* @inheritdoc
179+
*/
180+
public function isClassInActiveBundle($class)
181+
{
182+
$this->__call(__METHOD__, func_get_args());
183+
}
184+
}

fixtures/fixture_files/city.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Hautelook\AliceBundle\Functional\TestBundle\Entity\City:
2+
city_{0..10}:
3+
__construct:
4+
'@app.city_factory::create':
5+
- <current()>

resources/config/alice.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
<services>
6+
7+
<service id="hautelook_alice.alice.generator.instantiator.chainable.instantiated_reference_instantiator"
8+
class="Hautelook\AliceBundle\Alice\Generator\Instantiator\Chainable\InstantiatedReferenceInstantiator">
9+
<call method="setContainer">
10+
<argument type="service" id="service_container" />
11+
</call>
12+
13+
<tag name="nelmio_alice.generator.instantiator.chainable_instantiator" />
14+
</service>
15+
16+
</services>
17+
18+
</container>

0 commit comments

Comments
 (0)