coduo/phpspec-data-provider-extension

This package is abandoned and no longer maintained. No replacement package was suggested.
Package info

github.com/coduo/phpspec-data-provider-extension

pkg:composer/coduo/phpspec-data-provider-extension

Statistics

Installs: 180 283

Dependents: 18

Suggesters: 0

Stars: 40

Open Issues: 3

1.0.3 2015-10-27 14:27 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT b8d5c8594fec5ab2d7000bc31822a411bcd45146

  • Norbert Orzechowicz <norbert.woop@orzechowicz.pl>
  • MichaΕ‚ DΔ…browski <dabrowski.woop@brillante.pl>

datadataproviderextensionproviderphpspeccoduo

This package is auto-updated.

Last update: 2021-03-20 00:27:08 UTC


README

#PhpSpec data provider extension

πŸ‘ Build Status

This extension allows you to create data providers for examples in specs.

Installation

composer require coduo/phpspec-data-provider-extension

Usage

Enable extension in phpspec.yml file

extensions:
 - Coduo\PhpSpec\DataProvider\DataProviderExtension

Write a spec:

<?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:

<?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

$ console bin/phpspec run -f pretty

You should get following output:

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