2017 © Pedro Peláez
 

library quick-fixtures

Generate complex fixtures based on @var annotations.

image

ekiwok/quick-fixtures

Generate complex fixtures based on @var annotations.

  • Tuesday, January 17, 2017
  • by ekiwok
  • Repository
  • 0 Watchers
  • 0 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

QuickFixtures Build Status

  • Did you ever add unnecessary setter because you didn't want to use reflections in fixtures?
  • Did you give up on using value objects because writing fixtures this way was messy?
  • Did you create trait to help with \DateTime creation in fixtures?

If anything above applies to you you may find this helpful., (*1)

This small library may quickly generate fixtures for you based on dockblock annotations that probably already are present in your code., (*2)

Provided generator accepts associative arrays so you may keep your fixtures data in file of your choice. It might be yaml, xml, csv, etc..., (*3)

Fe. prepare yaml file like this:, (*4)

yml "Jake Weary": uuid: "123e4567-e89b-12d3-a456-426655440000" name: "Jake Weary" email: "jake.weary@example.com" # Notice that for single property objects it's ok to skip property name credit: 100, (*5)

And just use this data to generate fixture:, (*6)

```php $jakeWearyData = /* fetch "Jake Weary" entry from yml */, (*7)

 $jakeWeary = $generator->generate(Customer::class, $jakeWearyData);

```, (*8)

Instead of writing:, (*9)

    $jakeWeary = new Customer(
        '123e4567-e89b-12d3-a456-426655440000',
        'Jake Weary',
        'jake.weary@example.com',
        new Credit(100),
    );

or:, (*10)

    $jakeWeary = (new Customer())
        ->setUUID('123e4567-e89b-12d3-a456-426655440000')
        ->setName('Jake Weary')
        ->setEmail'jake.weary@example.com')
        ->setCredit(new Credit(100))
    ;

Installation

Install with composer: composer require ekiwok/quick-fixtures, (*11)

Extending

It's easily extendable by adding your own processors., (*12)

    $generator->addProcessor(new class implements \Ekiwok\QuickFixtures\Processor\PrioritisedProcessorInterface{

        public function getPriority()
        {
            return 1025;
        }

        public function process(\Ekiwok\QuickFixtures\ContextInterface $context, $payload, \Ekiwok\QuickFixtures\GeneratorInterface $generator)
        {
            return new \DateTime($payload);
        }

        public function applies(\Ekiwok\QuickFixtures\ContextInterface $context, $payload)
        {
            $type = $context->getType();

            // in real life we would also check payload to be sure it
            // also makes sense

            return $type->hasAnyClass()
                && $type->hasClass(\DateTime::class);
        }
    });

Processor with this priority will be run before built in processors and will set all properties these are marked as @var \DateTime., (*13)

Documentation

The Versions

17/01 2017

dev-master

9999999-dev

Generate complex fixtures based on @var annotations.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

17/01 2017

0.9.1

0.9.1.0

Generate complex fixtures based on @var annotations.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

10/01 2017

dev-develop

dev-develop

Generate complex fixtures based on @var annotations.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

10/01 2017

0.9.0

0.9.0.0

Generate complex fixtures based on @var annotations.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires