定制 m00t/phpspec-phpunit-matchers 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

m00t/phpspec-phpunit-matchers

Composer 安装命令:

composer require m00t/phpspec-phpunit-matchers

包简介

Changes IdentityMatcher from '===' to PHPUnit's assertEquals()

关键字:

README 文档

README

This extension changes PhpSpec's IdentityMatcher from "===" to PHPUnit's assertEquals() method. Also it changes PhpSpec's differ to PHPUnit's one.

Motivation

1. PHPUnit has time proven comparation library than does more than just "==" or "===", so that we can simply use it and do not worry about using "shouldBeLike()" instead of "shouldReturn()".

  1. Differ.

For example we have classes:

class Value
{
    private $value;

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

class TestValueObject
{
    public function getValue($value)
    {
        return new Value($value + 1);
    }
}

class TestValueObjectSpec extends ObjectBehavior
{
    function it_can_get_value()
    {
        $this->getValue(42)->shouldReturn(new \Value(42));
    }
}

PhpSpec output without this extension ("shouldReturn" was changed to "shouldBeLike")

$ bin/phpspec run spec/TestValueObjectSpec.php -v
TestValueObject
  10  ✘ it can get value
      expected [obj:Value], but got [obj:Value].

        10     function it_can_get_value()
        11     {
        12         $this->getValue(42)->shouldBeLike(new \Value(42));
        13     }
        14 }
        15


       0 vendor/phpspec/phpspec/src/PhpSpec/Matcher/ComparisonMatcher.php:74
         throw new PhpSpec\Exception\Example\NotEqualException("Expected [obj:Valu"...)
       1 [internal]
         spec\TestValueObjectSpec->it_can_get_value()


                       100%                        1
1 specs
1 example (1 failed)
30ms

PhpSpec output with this extension

$ bin/phpspec run spec/TestValueObjectSpec.php -v
TestValueObject
  10  ✘ it can get value
      expected [obj:Value], but got [obj:Value].

      --- Expected
      +++ Actual
      @@ @@
       Value Object (
      -    'value' => 42
      +    'value' => 43
       )


        10     function it_can_get_value()
        11     {
        12         $this->getValue(42)->shouldReturn(new \Value(42));
        13     }
        14 }
        15


       0 vendor/phpspec/phpspec/src/PhpSpec/Matcher/IdentityMatcher.php:83
         throw new PhpSpec\Exception\Example\NotEqualException("Expected [obj:Valu"...)
       1 [internal]
         spec\TestValueObjectSpec->it_can_get_value()


                       100%                        1
1 specs
1 example (1 failed)
48ms

Installation

  1. Define dependencies in your composer.json:
{
    "require-dev": {
        ...

        "m00t/phpspec-phpunit-matchers": "dev-master",
    }
}
  1. Install/update your vendors:
$ composer update m00t/phpspec-phpunit-matchers
  1. Activate extension by specifying its class in your phpspec.yml:
# phpspec.yml
extensions:
    - M00t\PhpSpec\PHPUnitMatchers\Extension\PHPUnitMatchersExtension

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-23