PHP code example of ekiwok / quick-fixtures

1. Go to this page and download the library: Download ekiwok/quick-fixtures library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ekiwok / quick-fixtures example snippets


     $jakeWearyData = /* fetch "Jake Weary" entry from yml */
 
     $jakeWeary = $generator->generate(Customer::class, $jakeWearyData);
 

    $jakeWeary = new Customer(
        '123e4567-e89b-12d3-a456-426655440000',
        'Jake Weary',
        '[email protected]',
        new Credit(100),
    );

    $jakeWeary = (new Customer())
        ->setUUID('123e4567-e89b-12d3-a456-426655440000')
        ->setName('Jake Weary')
        ->setEmail'[email protected]')
        ->setCredit(new Credit(100))
    ;

    $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);
        }
    });