dborsatto/phpspec-data-provider-extension

This package is abandoned and no longer maintained. The author suggests using the phpunit/phpunit package instead.

Data provider extension for PHPSpec 7+

Maintainers

Package info

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

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

Statistics

Installs: 61 226

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

2.0.0 2025-05-20 09:03 UTC

This package is auto-updated.

Last update: 2026-05-11 08:27:28 UTC


README

This library is no longer maintained. Sadly PHPSpec as a whole does not get much support any longer, a version 8.0 contained a breaking change that made this library not work anymore. For this is reason, you should considering moving from PHPSpec to PHPUnit.

PhpSpec data provider extension

This extension allows you to create data providers for examples in specs. It is a fork of madisoft/phpspec-data-provider-extension, which is the final fork from a series started from coduo/phpspec-data-provider-extension.

Installation

composer require dborsatto/phpspec-data-provider-extension

Usage

Enable extension in your phpspec.yml file:

extensions:
  DBorsatto\PhpSpec\DataProvider\DataProviderExtension: ~

Write a spec:

<?php

declare(strict_types=1);

namespace spec\DBorsatto\ToString;

use PhpSpec\ObjectBehavior;

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

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

Write the class for your spec:

<?php

declare(strict_types=1);

namespace DBorsatto\ToString;

class StringLibrary
{
    private $value;

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

    public function __toString(): string
    {
        $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 phpspec

$ vendor/bin/phpspec run -f pretty

You should get following output:

DBorsatto\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