2017 © Pedro Peláez
 

library phpspec-data-provider-extension

image

coduo/phpspec-data-provider-extension

  • Tuesday, October 27, 2015
  • by norzechowicz
  • Repository
  • 5 Watchers
  • 37 Stars
  • 132,936 Installations
  • PHP
  • 22 Dependents
  • 0 Suggesters
  • 16 Forks
  • 4 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

PhpSpec data provider extension

Build Status, (*1)

This extension allows you to create data providers for examples in specs., (*2)

Installation

composer require coduo/phpspec-data-provider-extension

Usage

Enable extension in phpspec.yml file, (*3)

extensions:
  - Coduo\PhpSpec\DataProvider\DataProviderExtension

Write a spec:, (*4)

<?php

namespace spec\Coduo\ToString;

use PhpSpec\ObjectBehavior;

class StringSpec extends ObjectBehavior
{
    /**
     *  @dataProvider positiveConversionExamples
     */
    function it_convert_input_value_into_string($inputValue, $expectedValue)
    {
        $this->beConstructedWith($inputValue);
        $this->__toString()->shouldReturn($expectedValue);
    }

    public function positiveConversionExamples()
    {
        return array(
            array(1, '1'),
            array(1.1, '1.1'),
            array(new \DateTime, '\DateTime'),
            array(array('foo', 'bar'), 'Array(2)')
        );
    }
}

Write class for spec:, (*5)

<?php

namespace Coduo\ToString;

class String
{
    private $value;

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

    public function __toString()
    {
        $type = gettype($this->value);
        switch ($type) {
            case 'array':
                return sprintf('Array(%d)', count($this->value));
            case 'object':
                return sprintf("\\%s", get_class($this->value));
            default:
                return (string) $this->value;
        }
    }
}

Run php spec, (*6)

$ console bin/phpspec run -f pretty

You should get following output:, (*7)

Coduo\ToString\String

  12  ✔ convert input value into string
  12  ✔ 1) it convert input value into string
  12  ✔ 2) it convert input value into string
  12  ✔ 3) it convert input value into string
  12  ✔ 4) it convert input value into string


1 specs
5 examples (5 passed)
13ms

The Versions

27/10 2015

1.0.x-dev

1.0.9999999.9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Norbert Orzechowicz

extension data provider dataprovider phpspec coduo

27/10 2015

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Norbert Orzechowicz

extension data provider dataprovider phpspec coduo

27/10 2015

1.0.3

1.0.3.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Norbert Orzechowicz

extension data provider dataprovider phpspec coduo

26/10 2015

1.0.2

1.0.2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Norbert Orzechowicz

extension data provider dataprovider phpspec coduo

18/01 2015

1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Norbert Orzechowicz

extension data provider dataprovider phpspec coduo

08/05 2014

1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Norbert Orzechowicz

extension data provider dataprovider phpspec coduo