All Projects → php-mock → php-mock-prophecy

php-mock / php-mock-prophecy

Licence: WTFPL License
Mock built-in PHP functions (e.g. time()) with Prophecy (phpspec).

Programming Languages

PHP
23972 projects - #3 most used programming language

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

php-mock-mockery
Mock non deterministic built-in PHP functions (e.g. time() or rand()) with Mockery.
Stars: ✭ 33 (+106.25%)
Mutual labels:  builtin-functions, php-mock
mock-req-res
Extensible mock req / res objects for use in unit tests of Express controller and middleware functions.
Stars: ✭ 39 (+143.75%)
Mutual labels:  mock
Retromock
Java library for mocking responses in a Retrofit service.
Stars: ✭ 48 (+200%)
Mutual labels:  mock
elasticmock
Python Elasticsearch Mock for test purposes
Stars: ✭ 98 (+512.5%)
Mutual labels:  mock
ng-apimock
Node plugin that provides the ability to use scenario based api mocking: for local development for protractor testing
Stars: ✭ 102 (+537.5%)
Mutual labels:  mock
smart-cloud
基于springboot && springcloud的脚手架,支持服务合并部署与拆分部署、接口加解密签名、日志数据 脱敏、接口数据mock、接口文档自动生成、请求幂等校验、接口日志&&sql日志切面打印、分表分库分布式事务、国际化语言等
Stars: ✭ 167 (+943.75%)
Mutual labels:  mock
mswjs.io
Official website and documentation for the Mock Service Worker library.
Stars: ✭ 77 (+381.25%)
Mutual labels:  mock
automock
A library for testing classes with auto mocking capabilities using jest-mock-extended
Stars: ✭ 26 (+62.5%)
Mutual labels:  mock
mockrequire
Simple module for mocking required dependencies. Works with any testing suite.
Stars: ✭ 17 (+6.25%)
Mutual labels:  mock
Raccoon
Raccoon is a lightweight response mocking framework that can be easily integrated into the Android UI tests.
Stars: ✭ 47 (+193.75%)
Mutual labels:  mock
httpmock
Lightweight HTTP mocking in Go (aka golang)
Stars: ✭ 75 (+368.75%)
Mutual labels:  mock
stub-server
Stub server for REST APIs
Stars: ✭ 14 (-12.5%)
Mutual labels:  mock
Lol-Mock-API
Mock API Tool
Stars: ✭ 15 (-6.25%)
Mutual labels:  mock
msw-storybook-addon
Mock API requests in Storybook with Mock Service Worker.
Stars: ✭ 168 (+950%)
Mutual labels:  mock
egg-datahub
Macaca DataHub plugin for Egg.js
Stars: ✭ 19 (+18.75%)
Mutual labels:  mock
elixir mock
Creates clean, concurrent, inspectable mocks from elixir modules
Stars: ✭ 21 (+31.25%)
Mutual labels:  mock
mongo mock go example
How to mock MongoDB in Golang
Stars: ✭ 30 (+87.5%)
Mutual labels:  mock
amoss
Amoss - Apex Mock Objects, Spies and Stubs - A Simple Mocking framework for Apex (Salesforce)
Stars: ✭ 55 (+243.75%)
Mutual labels:  mock
tdd-demo-forumphp2020
Live coding examples used during Forum PHP 2020 talk "Too many mocks killed the test: What Hexagonal Architecture has changed"
Stars: ✭ 25 (+56.25%)
Mutual labels:  prophecy
DeepfakeHTTP
DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.
Stars: ✭ 373 (+2231.25%)
Mutual labels:  mock

Mock PHP built-in functions with Prophecy

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

Installation

Use Composer:

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

Usage

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

namespace foo;

use phpmock\prophecy\PHPProphet;

$prophet = new PHPProphet();

$prophecy = $prophet->prophesize(__NAMESPACE__);
$prophecy->time()->willReturn(123);
$prophecy->reveal();

assert(123 == time());
$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 [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].