dborsatto/phpspec-data-provider-extension 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dborsatto/phpspec-data-provider-extension

最新稳定版本:2.0.0

Composer 安装命令:

composer require dborsatto/phpspec-data-provider-extension

包简介

Data provider extension for PHPSpec 7+

README 文档

README

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

统计信息

  • 总下载量: 60.02k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-06