DoctrineFixturesBundle, the bundle that integrates Doctrine's data fixtures library in Symfony applications, has just released its 3.1.0 version.
The most important new feature of this version is the possibility of
organizing your fixtures in groups to load some but not all of them. This is
configured using the getGroups()
method defined in the new
FixtureGroupInterface
:
1 2 3 4 5 6 7 8 9 10 11 12
// src/DataFixtures/UserFixtures.php
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
class UserFixtures extends Fixture implements FixtureGroupInterface
{
// ...
public static function getGroups(): array
{
return ['group1', 'group2'];
}
}
Once you have defined the group or groups each fixture class belongs to, pass
the new --group
option to load only the fixtures associated with those
groups:
1 2 3 4 5
# only load the 'group1' fixture classes
$ ./bin/console doctrine:fixtures:load --group=group1
# the '--group' option is multiple, so you can load several groups
$ ./bin/console doctrine:fixtures:load --group=group1 --group=group2
In order to improve your productivity, each fixture class is added to a group
whose name matches the short name of the class. In the previous example, the
class also belongs to a group named UserFixtures
. This allows to load just
one fixtures class:
1
$ php bin/console doctrine:fixtures:load --group=UserFixtures
The new bundle version also includes other minor improvements and drops support for PHP versions lower than 7.1, as you can read in the DoctrineFixturesBundle 3.1.0 changelog.
Thanks! Been waiting for this feature for just 3 years ^^
Thanks.
Thanks Ryan for working on this new feature, and thanks Andreas for publishing the new release and for your maintenance work in this bundle.
Yahoo, this is great! But I think "drops support for PHP 7.1 or earlier" isn't correct, should be "drops support for earlier than PHP 7.1", as 7.1 is still supported (https://github.com/doctrine/DoctrineFixturesBundle/pull/265/commits/74743ef486b30bbf331a68f0d11eadc57484a366)
@Tac you are right! Thanks for the heads up. We've just updated the blog post to fix that issue.