kunstmaan / fixtures-bundle
With this bundle you'll be able to create fixtures through yaml files in an easy way
Installs: 46 126
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 9
Forks: 1
Open Issues: 1
Type:symfony-bundle
Requires
- php: ^8.1
- doctrine/doctrine-fixtures-bundle: ^3.3
- fakerphp/faker: ^1.15
- kunstmaan/admin-bundle: ^7.0
- kunstmaan/media-bundle: ^7.0
- kunstmaan/menu-bundle: ^7.0
- kunstmaan/node-bundle: ^7.0
- kunstmaan/pagepart-bundle: ^7.0
- kunstmaan/utilities-bundle: ^7.0
- symfony/mime: ^5.4|^6.4
- symfony/string: ^5.4|^6.4
Requires (Dev)
- matthiasnoback/symfony-config-test: ^4.2.1
- matthiasnoback/symfony-dependency-injection-test: ^4.2.1
- phpunit/phpunit: ^9.5.5
- symfony/phpunit-bridge: ^7.0
Conflicts
- doctrine/persistence: <1.3
- 7.x-dev
- 7.2.x-dev
- 7.1.x-dev
- 7.1.2
- 7.1.1
- 7.1.0
- 7.1.0-alpha2
- 7.1.0-alpha1
- 7.0.x-dev
- 7.0.5
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 7.0.0-alpha1
- 6.x-dev
- 6.4.x-dev
- 6.4.3
- 6.4.2
- 6.4.1
- 6.4.0
- 6.4.0-alpha2
- 6.4.0-alpha1
- 6.3.x-dev
- 6.3.1
- 6.3.0
- 6.2.x-dev
- 6.2.5
- 6.2.4
- 6.2.3
- 6.2.2
- 6.2.1
- 6.2.0
- 6.1.x-dev
- 6.1.9
- 6.1.8
- 6.1.7
- 6.1.6
- 6.1.5
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.x-dev
- 6.0.6
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.10.x-dev
- dev-master / 5.10.x-dev
- 5.10.7
- 5.10.6
- 5.10.5
- 5.10.4
- 5.10.3
- 5.10.2
- 5.10.1
- 5.10.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2.6
- 3.2.5
- 3.2.4.1
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1.1
- 3.2.1
- 3.2.0
- dev-6.0-copy
- dev-sf3
This package is auto-updated.
Last update: 2024-12-11 14:47:52 UTC
README
You will still use the default doctrine fixtures way but instead of extending from the Doctrine\Common\DataFixtures\AbstractFixture
class,
you will instead extend from the Kunstmaan\FixturesBundle\Loader\FixtureLoader
class.
This is what your fixture class will look like:
<?php namespace Acme\SomeBundle\DataFixtures\ORM\DefaultSiteGenerator; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Kunstmaan\FixturesBundle\Loader\FixtureLoader; class YamlFixtures extends FixtureLoader implements OrderedFixtureInterface { protected function getFixtures() { return [ __DIR__ . '/media.yml', __DIR__ . '/default.yml', ]; } /** * Get the order of this fixture * * @return integer */ public function getOrder() { return 50; } }
Yaml you say?
Yes! Creating fixtures will has never been this easy. It's inspired by the Nelmio/Alice bundle. Why don't we use that bundle? That's because Nelmio/Alice is great for "simple" entities, but with our CMS alot of stuff happens during the creation of pages and pageparts. For this reason we wanted to start from scratch instead of hacking our way into another bundle.
So how do these yaml files look like?
\Kunstmaan\MediaBundle\Entity\Media: image_homepage-header: folder: image originalFilename: <getMediaPath()>homepage-header.jpg image_{some.svg, this.svg, that.svg, yes.svg, no.svg}: folder: image originalFilename: <getMediaPath()><current()> \Acme\SomeBundle\Entity\Pages\HomePage: homepage: title: <word()> parameters: page_internal_name: homepage set_online: true hidden_from_nav: false creator: <adminUser()> translations: nl: title: Home fr: title: Home \Acme\SomeBundle\Entity\Pages\ContentPage: content{1..10}: title: <word()> parameters: parent: @homepage page_internal_name: content<current()> set_online: true hidden_from_nav: false creator: <adminUser()> translations: nl: [] fr: [] \Acme\SomeBundle\Entity\Contact: contact_{ironman, blackwidow, thor, hulk, captainamerica, hawkeye}: firstName: <firstName()> lastName: <lastName()> email: <email()> function: <word()> mobile: <phoneNumber()> phone: <phoneNumber()> \Acme\SomeBundle\Entity\PageParts\HeaderPagePart: header_pp_{1..10}: title: <word()> niv: 1 parameters: page: @content<current()> context: header translations: nl: [] fr: [] \Acme\SomeBundle\Entity\PageParts\ContactPagePart: contact_pp_{1..5}: contacts: - @contact_ironman - @contact_blackwidow - @contact_thor parameters: page: @content<current()> context: main translations: nl: [] fr: [] contact_pp_{6..10}: contacts: - @contact_hulk - @contact_captainamerica - @contact_hawkeye parameters: page: @content<current()> context: main translations: nl: [] fr: []
Providers
Providers are classes that can be used to return data to a fixture. For example, if you use the <current()>
method, the Spec provider will be called upon.
So if you want to add some functionality to easily return the value of the page creator, you can add a Provider that contains the method
public function adminUser() { return 'admin'; }
By default you can add these kind of methods to your fixture class as it's automatically added as a provider.
Furthermore you have the Spec provider, NodeTranslation provider and Faker providers. You can add your own by adding the function getProviders()
to your fixture class and returning an array containing your providers or you can tag your providers with kunstmaan_fixtures.provider
.
Parsers
Parsers are used to translate the yaml data into actual data. So something like @content<current()>
will be transformed to an object by different parsers.
By default you have the Method and the Reference parser for property data and the Listed and Range parser for specs. If you want to add your
own parser, you can simply to that by tagging them with kunstmaan_fixtures.parser.property
or kunstmaan_fixtures.parser.spec
Populators
Does exactly what the name says. Populators will populate the entities once all the yaml data is parsed. If you want to add your own populator,
simply tag it with kunstmaan_fixtures.populator
Builders
With builders you can manipulate the behaviour during the creation of your entity. This can happen in three stages, preBuild, postBuild and postFlushBuild.
During these stages you can manipulate your entity or add more entities like we do in the PageBuilder for instance. If you want to add your own builder,
simply tag it with kunstmaan_fixtures.builder