mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Documentation] [Fixtures] Review fixes
This commit is contained in:
parent
981b351295
commit
8aa78a2a94
5 changed files with 28 additions and 24 deletions
|
|
@ -34,19 +34,19 @@ persist some entities in the database, upload some files, dispatch some events o
|
|||
priority: 0 # The higher priority is, the sooner the fixture will be executed
|
||||
options: ~ # Fixture options
|
||||
|
||||
They implement ``Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface`` and needs to be registered under
|
||||
``sylius_fixtures.fixture`` tag in order to be used in suite configuration.
|
||||
They implement the ``Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface`` and need to be registered under
|
||||
the ``sylius_fixtures.fixture`` tag in order to be used in suite configuration.
|
||||
|
||||
.. note::
|
||||
|
||||
The former interface extends ``ConfigurationInterface``, which is widely known from ``Configuration`` classes
|
||||
The former interface extends the ``ConfigurationInterface``, which is widely known from ``Configuration`` classes
|
||||
placed under ``DependencyInjection`` directory in Symfony bundles.
|
||||
|
||||
|
||||
Listeners
|
||||
---------
|
||||
|
||||
Listeners allows you to execute code at some point of fixtures loading.
|
||||
Listeners allow you to execute code at some point of fixtures loading.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ They implement at least one of four interfaces:
|
|||
|
||||
.. note::
|
||||
|
||||
The former interface extends ``ConfigurationInterface``, which is widely known from ``Configuration`` classes
|
||||
The former interface extends the ``ConfigurationInterface``, which is widely known from ``Configuration`` classes
|
||||
placed under ``DependencyInjection`` directory in Symfony bundles.
|
||||
|
||||
In order to be used in suite configuration, they need to be registered under ``sylius_fixtures.listener``.
|
||||
In order to be used in suite configuration, they need to be registered under the ``sylius_fixtures.listener``.
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
Built-in listeners
|
||||
==================
|
||||
|
||||
**SyliusFixturesBundle** comes bundled with a few useful listeners.
|
||||
**SyliusFixturesBundle** comes with a few useful listeners.
|
||||
|
||||
Logger (``logger``)
|
||||
-------------------
|
||||
|
||||
Provides output during running ``sylius:fixtures:load`` command.
|
||||
Provides output while running ``sylius:fixtures:load`` command.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ Provides output during running ``sylius:fixtures:load`` command.
|
|||
Running fixture "currency"...
|
||||
$ _
|
||||
|
||||
Has no configuration options, can be enabled by:
|
||||
The logger does not have any configuration options. It can be enabled in such a way:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ Purges the relational database. Uses ``delete`` purge mode and the default entit
|
|||
Configuration options:
|
||||
|
||||
- ``purge_mode`` - sets how databse is purged, available values: ``delete`` (default), ``truncate``
|
||||
- ``managers`` - array of entity managers names used to purge the database, ``[null]`` by default
|
||||
- ``managers`` - an array of entity managers' names used to purge the database, ``[null]`` by default
|
||||
|
||||
Example configuration:
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ Purges the document database. Uses the default document manager if not configure
|
|||
|
||||
Configuration options:
|
||||
|
||||
- ``managers`` - array of document managers names used to purge the database, ``[null]`` by default
|
||||
- ``managers`` - an array of document managers' names used to purge the database, ``[null]`` by default
|
||||
|
||||
Example configuration:
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Commands
|
|||
Listing fixtures
|
||||
----------------
|
||||
|
||||
To list all available suites and fixtures, use ``sylius:fixtures:list`` command.
|
||||
To list all available suites and fixtures, use the ``sylius:fixtures:list`` command.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ To list all available suites and fixtures, use ``sylius:fixtures:list`` command.
|
|||
Loading fixtures
|
||||
----------------
|
||||
|
||||
To load a suite, use ``sylius:fixtures:load [suite]`` command.
|
||||
To load a suite, use the ``sylius:fixtures:load [suite]`` command.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Custom fixture
|
|||
Basic fixture
|
||||
-------------
|
||||
|
||||
Let's create a fixture that loads all countries from ``Intl`` library. We'll extend on ``AbstractFixture`` in order
|
||||
Let's create a fixture that loads all countries from the ``Intl`` library. We'll extend the ``AbstractFixture`` in order
|
||||
to skip the configuration part for now:
|
||||
|
||||
.. code-block:: php
|
||||
|
|
@ -44,7 +44,7 @@ to skip the configuration part for now:
|
|||
|
||||
The next step is to register this fixture:
|
||||
|
||||
.. code-block:: yaml
|
||||
.. code-block:: xml
|
||||
|
||||
<service id="app.fixture.country" class="AppBundle\Fixture\CountryFixture">
|
||||
<argument type="service" id="doctrine.orm.entity_manager" />
|
||||
|
|
@ -52,7 +52,7 @@ The next step is to register this fixture:
|
|||
</service>
|
||||
|
||||
|
||||
Fixture is already registered and ready to use in your suite:
|
||||
Fixture is now registered and ready to use in your suite:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
|
|
@ -65,11 +65,13 @@ Fixture is already registered and ready to use in your suite:
|
|||
Configurable fixture
|
||||
--------------------
|
||||
|
||||
Loading all countries may be useful, but what if you want to load some defined countries in one suite and all
|
||||
countries in the other? You don't need to create multiple fixtures, one configurable will do the job!
|
||||
Loading all countries may be useful, but what if you want to load only some defined countries in one suite and all
|
||||
the countries in the another one? You don't need to create multiple fixtures, a one configurable fixture will do the job!
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// ...
|
||||
|
||||
final class CountryFixture extends AbstractFixture implements FixtureInterface
|
||||
{
|
||||
// ...
|
||||
|
|
@ -98,11 +100,11 @@ countries in the other? You don't need to create multiple fixtures, one configur
|
|||
|
||||
.. note::
|
||||
|
||||
``AbstractFixture`` implements ``ConfigurationInterface::getConfigTreeBuilder()`` and exposes handy
|
||||
The ``AbstractFixture`` implements the ``ConfigurationInterface::getConfigTreeBuilder()`` and exposes a handy
|
||||
``configureOptionsNode()`` method to reduce the boilerplate. It is possible to test this configuration
|
||||
using `SymfonyConfigTest`_ library. For examples of that tests have a look at `Sylius Fixtures Configuration Tests`_.
|
||||
|
||||
Now, it is possible for fixture to create different outcomes just by changing its configuration:
|
||||
Now, it is possible for the fixture to create different outcomes by just changing its configuration:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
|
|
|
|||
|
|
@ -30,14 +30,14 @@ Let's create a listener that removes the directory before loading the fixtures.
|
|||
|
||||
The next step is to register this listener:
|
||||
|
||||
.. code-block:: yaml
|
||||
.. code-block:: xml
|
||||
|
||||
<service id="app.listener.directory_purger" class="AppBundle\Listener\DirectoryPurgerListener">
|
||||
<tag name="sylius_fixtures.listener" />
|
||||
</service>
|
||||
|
||||
|
||||
Listener is already registered and ready to use in your suite:
|
||||
Listener is now registered and ready to use in your suite:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
|
|
@ -50,11 +50,13 @@ Listener is already registered and ready to use in your suite:
|
|||
Configurable listener
|
||||
---------------------
|
||||
|
||||
Listener that removes hardcoded directory isn't very useful. Allowing it to receive an array of directories would make
|
||||
Listener that removes a hardcoded directory isn't very useful. Allowing it to receive an array of directories would make
|
||||
this listener a lot more reusable.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
// ...
|
||||
|
||||
final class DirectoryPurgerListener extends AbstarctListener implements ListenerInterface
|
||||
{
|
||||
// ...
|
||||
|
|
@ -76,7 +78,7 @@ this listener a lot more reusable.
|
|||
|
||||
.. note::
|
||||
|
||||
``AbstractListener`` implements ``ConfigurationInterface::getConfigTreeBuilder()`` and exposes handy
|
||||
The ``AbstractListener`` implements the ``ConfigurationInterface::getConfigTreeBuilder()`` and exposes a handy
|
||||
``configureOptionsNode()`` method to reduce the boilerplate. It is possible to test this configuration
|
||||
using `SymfonyConfigTest`_ library.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue