Download the PHP package chubbyphp/chubbyphp-mock without Composer

On this page you can find all versions of the php package chubbyphp/chubbyphp-mock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package chubbyphp-mock

chubbyphp-mock

CI Coverage Status Mutation testing badge Latest Stable Version Total Downloads Monthly Downloads

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

A strict mocking solution. It works with any testing framework; the examples below use PHPUnit.

A mock is defined as an ordered list of expected method calls. Every call made on the mock must match the next expectation in that list by method name and parameters, otherwise an exception is thrown. Missing calls are detected as well: a mock that still has unconsumed expectations when it is destroyed throws too.

Every exception carries a JSON message with the mocked class, the position of the failing call, the actual and expected values, and the file and line where the mock was created.

Requirements

Installation

Through Composer as chubbyphp/chubbyphp-mock.

Usage

Create a MockObjectBuilder and pass it the class or interface to mock together with the list of expected calls. Each expected call is an instance of one of the following mock methods:

Mock method Constructor Behaviour
WithoutReturn (string $name, array $parameters, bool $strict = true) Validates the call and returns nothing.
WithReturn (string $name, array $parameters, mixed $return, bool $strict = true) Validates the call and returns the given value.
WithReturnSelf (string $name, array $parameters, bool $strict = true) Validates the call and returns the mock itself (fluent APIs).
WithException (string $name, array $parameters, \Throwable $exception, bool $strict = true) Validates the call and throws the given exception.
WithCallback (string $name, callable $callback) Validates the method name and delegates to the callback with the actual parameters. Its return value is returned by the mock.

Parameters are compared with === by default. Pass $strict = false to compare by value instead; arrays are then compared entry by entry and objects property by property (or via __serialize / __sleep when available).

Use WithCallback whenever a parameter cannot be known in advance (for example a generated id or a timestamp) or when you want to assert on it inside the callback.

Other testing frameworks

chubbyphp-mock has no dependency on PHPUnit. A host framework only needs to provide a place to build the mocks, a way to assert inside a WithCallback, and a test scope that ends when the test ends.

Unconsumed expectations are reported from the mock's destructor. Keep mocks in local variables of the test and do not store them in long-lived properties, statics or shared setup, otherwise the check is delayed and the failure is attributed to the wrong place.

The examples below use the same PingRequestHandler scenario as the PHPUnit example above.

Pest

expect() replaces the PHPUnit assertion inside the callback, everything else stays the same.

Codeception

Codeception unit tests are PHPUnit test cases with a different base class, so the PHPUnit example works unchanged.

phpspec

phpspec injects lenient, unordered Prophecy collaborators by default. Building the mocks with chubbyphp-mock instead gives the spec a strict, ordered script of expected calls.

FAQ

Howto mock final classes/methods

Use the third party package dg/bypass-finals.

This does not remove the final keyword from internal (PHP core or extension) classes.

What Cannot Be Mocked

Special Handling

Please report if you find other restrictions / bugs.

Upgrade

Upgrade from 1.x

Copyright

2026 Dominik Zogg


All versions of chubbyphp-mock with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
nikic/php-parser Version ^5.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package chubbyphp/chubbyphp-mock contains the following files

Loading the files please wait ...