All Projects → php-mock → php-mock-mockery

php-mock / php-mock-mockery

Licence: WTFPL License
Mock non deterministic built-in PHP functions (e.g. time() or rand()) with Mockery.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-mock-mockery

php-mock-prophecy
Mock built-in PHP functions (e.g. time()) with Prophecy (phpspec).
Stars: ✭ 16 (-51.52%)
Mutual labels:  builtin-functions, php-mock
04 Python Functions
The function is a block of code defined with a name. We use functions whenever we need to perform the same task multiple times without writing the same code again. It can take arguments and returns the value.
Stars: ✭ 204 (+518.18%)
Mutual labels:  builtin-functions
php-test-generator
Generate test cases for existing PHP files
Stars: ✭ 47 (+42.42%)
Mutual labels:  mockery
go-echo-boilerplate
The fastest way to build a restful API with golang and echo framework. Includes common required features for modern web applications. A boilerplate project with golang and Echo.
Stars: ✭ 53 (+60.61%)
Mutual labels:  mockery
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).
Stars: ✭ 10,048 (+30348.48%)
Mutual labels:  mockery
mockery-example
Advanced Example for mockery
Stars: ✭ 33 (+0%)
Mutual labels:  mockery

.github/workflows/tests.yml

Mock PHP built-in functions with Mockery

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

Installation

Use Composer:

composer require --dev php-mock/php-mock-mockery

Usage

PHPMockery::mock() let's you build a function mock which can be equiped with Mockery's expectations. After your test you'll have to disable all created function mocks by calling Mockery::close().

Example

namespace foo;

use phpmock\mockery\PHPMockery;

$mock = PHPMockery::mock(__NAMESPACE__, "time")->andReturn(3);
assert (3 == time());

\Mockery::close();

Restrictions

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

  • Only unqualified function calls in a namespace context can be mocked. E.g. a call for time() in the namespace foo is mockable, 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 PHPMockery::define() before that first call. This would define a side effectless namespaced function.

License and authors

This project is free and under the WTFPL. Responsable for this project is Markus Malkusch [email protected].

Donations

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].