项目作者: php-mock

项目描述 :
Mock built-in PHP functions (e.g. time()) with Prophecy (phpspec).
高级语言: PHP
项目地址: git://github.com/php-mock/php-mock-prophecy.git
创建时间: 2015-10-31T23:49:21Z
项目社区:https://github.com/php-mock/php-mock-prophecy

开源协议:Do What The F*ck You Want To Public License

下载


Mock PHP built-in functions with Prophecy

This package integrates the function mock library
PHP-Mock with Prophecy.

Installation

Use Composer:

  1. composer require --dev php-mock/php-mock-prophecy

Usage

Build a new PHPProphet
and create function prophecies for a given namespace
with PHPProphet::prophesize():

  1. namespace foo;
  2. use phpmock\prophecy\PHPProphet;
  3. $prophet = new PHPProphet();
  4. $prophecy = $prophet->prophesize(__NAMESPACE__);
  5. $prophecy->time()->willReturn(123);
  6. $prophecy->reveal();
  7. assert(123 == time());
  8. $prophet->checkPredictions();

Restrictions

This library comes with the same restrictions as the underlying
php-mock:

  • Only unqualified function calls in a namespace context can be prophesized.
    E.g. a call for time() in the namespace foo is prophesizable,
    a call for \time() is not.

  • The mock has to be defined before the first call to the unqualified function
    in the tested class. This is documented in Bug #68541.
    In most cases you can ignore this restriction. But if you happen to run into
    this issue you can call PHPProphet::define()
    before that first call. This would define a side effectless namespaced function.

  • Additionally it shares restrictions from Prophecy as well:
    Prophecy doesn’t support pass-by-reference.
    If you need pass-by-reference in prophecies, consider using another framework
    (e.g. php-mock-phpunit).

License and authors

This project is free and under the WTFPL.
Responsable for this project is Markus Malkusch markus@malkusch.de.

Donations

If you like this project and feel generous donate a few Bitcoins here:
1335STSwu9hST4vcMRppEPgENMHD2r1REK