dborsatto / phpspec-data-provider-extension
Data provider extension for PHPSpec 7+
Package info
github.com/dborsatto/phpspec-data-provider-extension
pkg:composer/dborsatto/phpspec-data-provider-extension
Requires
- php: 8.3.*
- phpspec/phpspec: ^7.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.47
- friendsofphp/php-cs-fixer: ^3.75
- symfony/console: ^5.0 || ^6.0
- symfony/filesystem: ^5.0 || ^6.0
- symfony/process: ^5.0 || ^6.0
- vimeo/psalm: ^6.10
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