1. Go to this page and download the library: Download dansan/fixture-handler 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/ */
dansan / fixture-handler example snippets
...
use Dan\FixtureHandler\FixtureHandler;
...
$fh = new FixtureHandler();
$fh->setRef('user.mario', new User('Mario');
...
$mario = $fh->getRef('user.mario');
...
$fh = new FixtureHandler();
$fh->setRef('user.mario', new User('Mario');
$fh->setRef('user.luigi', new User('Luigi');
$mario = $fh->getRef('user.mario');
$luigi = $fh->getRef('user.luigi');
$mario->helps($luigi);
...
class UserFixture extends AbstractFixture
{
public function load(): void
{
$this->setRef('user.mario', new User('Mario');
$this->setRef('user.luigi', new User('Luigi');
}
}
class MyScenario extends AbstractScenario
{
public function load()
{
$this->setRef('guzzle', new FakeGuzzleClient());
$this->addFixture(new ItemFixture());
$this->addFixture(new UserFixture());
}
}
$fh = new FixtureHandler();
$fh->addScenario(new MyScenario());
$guzzle = $fh->getRef('guzzle');
...
$fh = new FixtureHandler();
$fh->setRef('a_key', 'a value');
$value = $fh->getRef('a_key');
$value = $fh->getRef('a_not_existing_key', 'a default value');
$value = $fh->getRefOrFail('a_not_existing_key');
if ($fh->hasRef('a_key')) {
...
}
...
MyTest extends TestCase
{
use FixtureHandlerTrait;
public function setUp()
{
parent::setUp();
$this->addFixture(new UserFixture());
}
/**
* @test
*/
public it_works()
{
$mario = $this->getRef('user.mario');
...
}
...
}
$fh = new FixtureHandler();
$fh->addFixture(new ItemFixture()); // <--- NOT HERE
$fh->addFixture(new UserFixture()); // <--- NOT HERE
...
$mario = $fh->getRef('user.mario'); // <--- HERE
...
$fh = new FixtureHandler();
$fh->addFixture(new ItemFixture()); // <--- NOT HERE
$fh->addFixture(new UserFixture()); // <--- NOT HERE
$fh->loadFixtures(); // <--- HERE
...
$mario = $fh->getRef('user.mario'); // <--- LOADED YET
...