Download the PHP package timacdonald/callable-fake without Composer

On this page you can find all versions of the php package timacdonald/callable-fake. 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 callable-fake

Callable / Closure testing fake

If you have an interface who's public API allows a developer to pass a Closure / callable, but causes no internal or external side-effects, as these are left up to the developer using the interface, this package may assist in testing. This class adds some named assertions which gives you an API that is very much inspired by Laravel's service fakes. It may be a little more verbose, but it changes the language of the tests to better reflect what is going on.

It also makes it easy to assert the order of invocations, and how many times a callable has been invoked.

Installation

You can install the package using composer:

Basic usage

This packge requires you to be testing a pretty specfic type of API / interaction to be useful. Imagine you are developing a package that ships with the following interface...

This interface accepts a callback, and under the hood loops through all "dependecies" and passes each one to the callback for the developer to work with.

Before

Let's see what the a test for this method might look like...

After

Available assertions

All assertions are chainable.

assertCalled(callable $callback): self

assertNotCalled(callable $callback): self

assertCalledIndex(callable $callback, int|array $index): self

Ensure the callable was called in an explicit order, i.e. it was called as the 0th and 5th invocation.

assertCalledTimes(callable $callback, int $times): self

assertTimesInvoked(int $times): self

assertInvoked(): self

assertNotInvoked(): self

Non-assertion API

asClosure(): Closure

If the method is type-hinted with \Closure instead of callable, you can use this method to transform the callable to an instance of \Closure.

wasInvoked(): bool

wasNotInvoked(): bool

called(callable $callback): array

Specifying return values

If you need to specify return values, this could be an indicator that this is not the right tool for the job. But there are some cases where return values determine control flow, so it can be handy, in which case you can pass a "return resolver" to the named constructor withReturnResolver.

Credits

And a special (vegi) thanks to Caneco for the logo ✨

Thanksware

You are free to use this package, but I ask that you reach out to someone (not me) who has previously, or is currently, maintaining or contributing to an open source library you are using in your project and thank them for their work. Consider your entire tech stack: packages, frameworks, languages, databases, operating systems, frontend, backend, etc.


All versions of callable-fake with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
phpunit/phpunit Version ^10.0 || ^11.0
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 timacdonald/callable-fake contains the following files

Loading the files please wait ....