定制 jameshalsall/phpspec-array-contains-matchers 二次开发

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

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

jameshalsall/phpspec-array-contains-matchers

Composer 安装命令:

composer require jameshalsall/phpspec-array-contains-matchers

包简介

Provides additional contains matchers for PHPSpec

README 文档

README

Build Status

Provides additional contains matchers for arrays in PHPSpec

Requirements

The extensions has been built for PHPSpec 3.x and PHP 5.6 or later.

Installation

Install the extension via composer:

$ composer require jameshalsall/phpspec-array-contains-matchers

You can then add the extension to your phpspec.yml as follows:

extensions:
  JamesHalsall\PhpSpecContainsMatchers\Extension: ~

Usage

The extension currently supports the following matchers:

  • containOnly
  • containAnyOf
  • containAllOf

containOnly matcher

The containOnly matcher is used when you want to ensure that an array value contains only the specified arguments. It was implemented to save you writing multiple calls to shouldContain().

Consider that ->getArray() returns [1, 2, 3], the following code in your spec would pass:

$this->getArray()->shouldContainOnly(1, 2, 3);

If any anything else was in the array would it would cause the spec to fail.

Similarly this can be negated with shouldNotContainOnly. Staying with the same example above, the following code would fail because there aren't any additional values in the array:

$this->getArray()->shouldNotContainOnly(1, 2, 3);

However if ->getArray() was to return [1, 2, 3, 4] then the above spec would pass.

containAnyOf matcher

The containAnyOf matcher is used when you want to ensure that an array contains at least one of the specified arguments.

Consider that ->getArray() returns [1, 2, 3] as above, the following assertion would hold true:

$this->getArray()->shouldContainAnyOf(3, 4, 5);

However the following example would not:

$this->getArray()->shouldContainAnyOf(5, 6);

Similarly this can be negated with shouldNotContainAnyOf. Staying with the sample example, the following code would fail:

$this->getArray()->shouldNotContainAnyOf(3, 7);

This is because it contains the value 3, which is one of the values we have said it should not contain.

containAllOf matcher

The containAllOf matcher will evaluate to true when the array contains all of the elements passed to the matcher.

If ->getArray() returns [1, 2, 3] then the following assertion would hold true:

$this->getArray()->shouldContainAllOf(2, 3);

However the following example would not:

$this->getArray()->shouldContainAllOf(2, 3, 4);

Similarly this can be negated with shouldNotContainAnyOf. Staying with the same example, the following code would fail:

$this->getArray()->shouldNotContainAllOf(2, 3)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固