2017 © Pedro Peláez
 

library fixtures

A library to define and load static fixtures

image

celtric/fixtures

A library to define and load static fixtures

  • Tuesday, September 20, 2016
  • by celtric
  • Repository
  • 2 Watchers
  • 3 Stars
  • 805 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 7 % Grown

The README.md

Celtric Fixtures - PHP

Build Status Latest Stable Version Latest Unstable Version License, (*1)

Introduction

This is a small library that aims to offer an easy way to define static fixtures. By default it uses YAML files and a custom format (inspired by Alice format, which is also partially supported using AliceStyleParser included in this package), but tries to give several extension points so any developer can easily customize it., (*2)

What this library is not

The aim of this package is not to provide dynamic fixtures (via fake data generation). Support for it can be added, but you are encouraged to check out Alice or any other fixture generator., (*3)

An example

We are going to assume that we have the following class definition:, (*4)

<?php

namespace Foo\Bar;

class Person
{
    private $name;
    private $age;

    public function __construct($name, $age)
    {
        $this->name = $name;
        $this->age = $age;
    }
}

And the following fixtures file: fixtures/people.yml, (*5)

root_type: Foo\Bar\Person

ricard:
    name: Ricard
    age: 30

laura:
    name: Laura
    age: 29

We are now ready to use the library as follows:, (*6)

<?php

namespace Tests;

class FooTest extends \PHPUnit_Framework_TestCase
{
    /** @test */
    public function can_load_fixtures()
    {
        $this->assertEquals(new Person("Ricard", 30), $this->fixture("people.ricard"));
    }

    /**
     * @param string $fixtureName
     * @return mixed
     */
    private function fixture($fixtureName)
    {
        $fixtures = Fixtures::celtricStyle(__DIR__ . "/../fixtures/");

        return $fixtures->fixture($fixtureName);
    }
}

A more complex example

We now have an slightly more complex class definition:, (*7)

<?php

namespace Foo\Bar;

class Money
{
    private $amount;
    private $currency;

    public function __construct($amount, Currency $currency)
    {
        $this->amount = $amount;
        $this->currency = $currency;
    }
}

class Currency
{
    private $isoCode;

    public function __construct($isoCode)
    {
        $this->isoCode = $isoCode;
    }
}

In order to define fixtures for it, we can use the following example: fixtures/money.yml, (*8)

root_type: Foo\Bar\Money

# We can inline the currency definition
two_euro:
    amount: 200
    currency<Foo\Bar\Currency>:
        isoCode: EUR

# Or we can reference it
three_euro:
    amount: 300
    currency: "@money.euro"

euro<Foo\Bar\Currency>:
    isoCode: EUR

Development status

This library is currently in beta. Any feedback will be welcomed, and you're encouraged to provide feedback via issues or PRs., (*9)

The Versions

20/09 2016

dev-master

9999999-dev

A library to define and load static fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

20/09 2016

0.0.6

0.0.6.0

A library to define and load static fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

13/09 2016

0.0.5

0.0.5.0

A library to define and load static fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

07/09 2016

0.0.4

0.0.4.0

A library to define and load static fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

06/09 2016

0.0.3

0.0.3.0

A library to define and load static fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

15/08 2016

0.0.2

0.0.2.0

A library to define and load static fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

15/08 2016

0.0.1

0.0.1.0

A library to define and load static fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires