2017 © Pedro Peláez
 

library file-fixture

Simple file fixture loader for unittest

image

holyshared/file-fixture

Simple file fixture loader for unittest

  • Friday, January 20, 2017
  • by holyshared
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,207 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 24 Versions
  • 1 % Grown

The README.md

file-fixture

Build Status HHVM Status Coverage Status Scrutinizer Code Quality Dependency Status Stories in Ready, (*1)

Simple file fixture loader for unittest.
You can easily load the test-based fixture., (*2)

Table of contents

Basic usage

Will be able to load the fixture in four steps., (*3)

  1. Create a loader of container
  2. Create a fixture of container
  3. Create a FileFixture
  4. Load fixture from the container.
$loaders = new LoaderContainer([
    new TextLoader()
]);

$fixtures = new FixtureContainer([
    'text:default:readme' => __DIR__ . '/README.md'
]);

$fixture = new FileFixture($fixtures, $loaders);
$content = $fixture->load('text:default:readme');

print $content;

Loader is compatible with text data, mustache template, ASCII art., (*4)

  • TextLoader - Load the text data.
  • MustacheLoader - Load the mustache template
  • ArtLoader - Load the ASCII art.

Output fixture of terminal

With ArtLoader, you can load the coloring text data., (*5)

Create a fixture file

Create a fixture file.
Mark the text to apply the color in the tag., (*6)

<green>#######</green>
<green>#</green>
<green>#</green>
<green>#####</green>
<green>#</green>
<green>#</green>
<green>#</green>

Load of Output fixture

$loaders = new LoaderContainer([
    new ArtLoader(new MustacheLoader(new TextLoader()))
]);

$fixtures = new FixtureContainer([
    'art:default:header' => __DIR__ . '/art.txt'
]);

$fixture = new FileFixture($fixtures, $loaders);
$content = $fixture->load('art:default:header');

print $content;

Result of ArtLoader, (*7)

Configuration file

Using the configuration file, you will be able to easily load the fixture.
Example of the fixture to load the mustache of template., (*8)

Create a fixture template

{{name}} task was successful.

Create a configuration file of fixture

The name of the fixture, you must begin with the name of the loader., (*9)

[mustache.default]
successMessage = "template.ms"

The name of this fixture will be mustache:default:successMessage., (*10)

Load of fixture

Load the fixture by specifying the name.
When the load is successful, will return the results of template of mustache has been processed., (*11)

$textLoader = new TextLoader();
$loaders = new LoaderContainer([
    $textLoader,
    new MustacheLoader($textLoader)
]);

$factory = new FixtureContainerFactory();
$fixtures = $factory->createFromFile(__DIR__ . '/fixtures.toml');

$fixture = new FileFixture($fixtures, $loaders);
$content = $fixture->load('mustache:default:successMessage', [
    'name' => 'build'
]);

print $content;

Contributors

The Versions