kanel / phpspec-data-provider-extension
允许在 phpspec 中使用数据提供程序的扩展
1.0.0
2017-12-12 09:39 UTC
Requires
- php: >=7.0
- phpspec/phpspec: >=4.0
This package is not auto-updated.
Last update: 2024-09-21 16:20:33 UTC
README
#PhpSpec 数据提供程序扩展
此扩展允许您为规格说明中的示例创建数据提供程序。
它主要受到 coduo/phpspec-data-provider-extension 的启发,并针对 phpspec 4 和参数的默认值进行了适配。
安装
composer require kanel/phpspec-data-provider-extension
用法
在 phpspec.yml 文件中启用扩展
extensions:
Kanel\PhpSpec\DataProvider\Extension: ~
编写规格说明
<?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], ]; } }
为规格说明编写类
<?php namespace Kanel\PhpSpec\Test; class Increment { public function plusOne(int $i): int { return $i + 1; } }
运行 php spec
$ console bin/phpspec run -f pretty
您应该得到以下输出
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)