Getting Started

Last updated on
5 February 2021

We created this project in response to fixtures which where fixed global records that had to be loaded into the database.

With Factories, you have more customization when you instantiate the objects & they aim to ensure that you have a valid object to work with.
They can be used anywhere in your tests and in your before and after test setup.

This module should never be enabled and exported in your Drupal configuration.
Indeed, you must require Factory Lollipop in your Tests suites only.

Getting Started

We highly recommend you to install the module using composer

$ composer require --dev drupal/factory_lollipop

Using Factory Lollipop on tests 

You have 2 options to use Factory Lollipop:

1. On KernelTest, extend the helper LollipopKernelTestBase class.

/**
 * Example of Factory Lollipop usage for a KernelTest.
 */
class MyKernelTest extends LollipopKernelTestBase {
  // ...
}

2. Add factory_lollipop to your collection of $modules to be installed and load the Blueprint Factory from the container.

/**
 * Example of Factory Lollipop usage for a KernelTest.
 */
class MyKernelTest extends EntityKernelTestBase {

  /**
   * The Factory Lollipop fixture factory.
   *
   * @var \Drupal\factory_lollipop\FixtureFactory
   */
  protected $factoryLollipop;

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'factory_lollipop',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->factoryLollipop = $this->container->get('factory_lollipop.fixture_factory');
  }
}

Help improve this page

Page status: No known problems

You can: