承接 eloquent/phony-peridot 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

eloquent/phony-peridot

最新稳定版本:3.0.0

Composer 安装命令:

composer require eloquent/phony-peridot

包简介

Phony integration for Peridot.

README 文档

README

No longer maintained

This package is no longer maintained. See [this statement] for more info.

[this statement]: https://gist.github.com/ezzatron/713a548735febe3d76f8ca831bc895c0# Phony for PHPUnit

Phony for Peridot

Current version image

Installation

composer require --dev eloquent/phony-peridot

See also

What is Phony for Peridot?

Phony for Peridot is a plugin for the Peridot testing framework that provides auto-wired test dependencies via the Phony mocking framework.

In other words, if a Peridot test (or suite) requires a mock object, it can be defined to have a parameter with an appropriate type declaration, and it will automatically receive a mock of that type as an argument when run.

Stubs for callable types, and "empty" values for other type declarations are also supported.

Plugin installation

The plugin must be installed in the Peridot configuration file:

use Eloquent\Phony\Peridot\PeridotPhony;
use Evenement\EventEmitterInterface;

return function (EventEmitterInterface $emitter) {
    PeridotPhony::install($emitter);
};

Dependency injection

Once the plugin is installed, any tests or suites that are defined with parameters will be supplied with matching arguments when run:

describe('Phony for Peridot', function () {
    it('Auto-wires test dependencies', function (PDO $db) {
        expect($db)->to->be->an->instanceof('PDO');
    });
});

Injected mock objects

Phony for Peridot supports automatic injection of mock objects. Because Phony doesn't alter the interface of mocked objects, it is necessary to use on() to retrieve the mock handle in order to perform stubbing and verification:

use function Eloquent\Phony\on;

describe('Phony for Peridot', function () {
    it('Supports stubbing', function (PDO $db) {
        on($db)->exec->with('DELETE FROM users')->returns(111);

        expect($db->exec('DELETE FROM users'))->to->equal(111);
    });

    it('Supports verification', function (PDO $db) {
        $db->exec('DROP TABLE users');

        on($db)->exec->calledWith('DROP TABLE users');
    });
});

Injected stubs

Phony for Peridot supports automatic injection of stubs for parameters with a callable type declaration:

describe('Phony for Peridot', function () {
    it('Supports callable stubs', function (callable $stub) {
        $stub->with('a', 'b')->returns('c');
        $stub('a', 'b');

        $stub->calledWith('a', 'b')->firstCall()->returned('c');
    });
});

Supported types

The following table lists the supported type declarations, and the value supplied for each:

Parameter type Supplied value
(none) null
bool false
int 0
float .0
string ''
array []
stdClass (object) []
callable stub()
Closure function () {}
Generator (function () {return; yield;})()

When using a type declaration that is not listed above, the supplied value will be a mock of the specified type.

By necessity, the supplied value will not be wrapped in a mock handle. In order to obtain a handle, simply use on():

use function Eloquent\Phony\on;

it('Example mock handle retrieval', function (ClassA $mock) {
    $handle = on($mock);
});

License

For the full copyright and license information, please view the LICENSE file.

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-24