kanel / phpspec-data-provider-extension
Extension that allows to use data provider in phpspec
Installs: 22 026
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 2
Open Issues: 3
Requires
- php: >=7.0
- phpspec/phpspec: >=4.0
This package is not auto-updated.
Last update: 2024-12-14 17:30:39 UTC
README
#PhpSpec data provider extension
This extension allows you to create data providers for examples in specs.
It was largely inspired from coduo/phpspec-data-provider-extension and adapted to handle phpspec 4 and default values of parameters
Installation
composer require kanel/phpspec-data-provider-extension
Usage
Enable extension in phpspec.yml file
extensions:
Kanel\PhpSpec\DataProvider\Extension: ~
Write a spec:
<?php namespace spec\Kanel\PhpSpec\Test; use Kanel\PhpSpec\Test\Increment; use PhpSpec\ObjectBehavior; use Prophecy\Argument; class IncrementSpec extends ObjectBehavior { /** * Example of a dataprovider with default values * @dataProvider getTestSuite */ public function it_should_be_able_to_increment_values($input, $output = 1) { $this->plusOne($input)->shouldBe($output); } public function getTestSuite() { return [ [0], [1, 2], [3, 4], [5, 6], ]; } }
Write class for spec:
<?php namespace Kanel\PhpSpec\Test; class Increment { public function plusOne(int $i): int { return $i + 1; } }
Run php spec
$ console bin/phpspec run -f pretty
You should get following output:
Kanel\PhpSpec\Test\Increment
15 ✔ should be able to increment values (129ms)
15 ✔ 2) it should be able to increment values
15 ✔ 3) it should be able to increment values
15 ✔ 4) it should be able to increment values
1 specs
4 examples (4 passed)