Download the PHP package crashuxx/phockito without Composer

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

Phockito - Mockito for PHP

Mocking framework inspired by Mockito for Java

Checkout the original's website for the philosophy behind the API and more examples (although be aware that this is only a partial implementation for now)

Thanks to the developers of Mockito for the inspiration, and hamcrest-php for making this easy.

Example mocking:

If PHPUnit is available, on failure verify throws a PHPUnit_Framework_AssertionFailedError (looks like an assertion failure), otherwise just throws an Exception

Example stubbing:

Alternative API, jsMockito style

Spies

Mocks are full mocks - method calls to unstubbed function always return null, and never call the parent function.

You can also create partial mocks by calling spy instead of mock. With spies, method calls to unstubbed functions call the parent function.

Because spies are proper subclasses, this lets you stub in methods that are called by other methods in a class

Argument matching

Phockito allows the use of Hamcrest matchers on any argument. Hamcrest is a library of "matching functions" that, given a value, return true if that value matches some rule.

Hamcrest matchers are not included by default, so the first step is to call Phockito::include_hamcrest(); immediately after including Phockito. Note that this will import the Hamcrest matchers as global functions - passing false as an argument will keep your namespace clean by making all matchers only available as static methods of Hamcrest (at the expense of worse looking test code).

Once included you can pass a Hamcrest matcher as an argument in your when or verify rule, eg:

Some common Hamcrest matchers:

Differences from Mockito

Stubbing methods more flexible

In Mockito, the methods when building a stub are limited to thenReturns, thenThrows. In Phockito, you can use any method as long as it has 'return' or 'throw' in it, so Phockito::when(...)->return(1)->thenReturn(2) is fine.

Type-safe argument matching

In Mockito, to use a Hamcrest matcher, the argThat method is used to satisfy the type checker. In PHP, a little extra help is needed. Phockito provides the argOfTypeThat for provided Hamcrest matchers to type-hinted parameters:

It's also possible to pass a mock to 'when', rather than the result of a method call on a mock, e.g. Phockito::when($mock)->methodToStub(...)->thenReturn(...). This side-steps the type system entirely.

Note that argOfTypeThat is only compatible with object type-hints; arguments with array or callable type-hints cannot be handled in a type-safe way.

Verify 'times' argument changed

In Mockito, the 'times' argument to verify is an object of interface VerificationMode. Phockito only supports a subset of Mockito's VerificationMode implementations: times(), never(), atLeast(), atLeastOnce(), atMost(), only().

The verification modes in Phockito's global functions are named as calledX (e.g. calledAtLeastOnce(), as opposed to Phockito::atLeastOnce()) to avoid conflicts with other global functions (such as those provided by Hamcrest).

Additionally, the 'times' argument can also take either an integer (equivalent to times()), or an integer followed by '+' (equivalent to atLeast()).

Callback instead of answers

In Mockito, you can return dynamic results from a stubbed method by calling thenAnswer with an instance of an object that has a specific method. In Phockito you call thenCallback with a callback argument, which gets called with the arguments the stubbed method was called with.

Default arguments

PHP has default arguments, unlike Java. If you don't specify a default argument in your stub or verify matcher, it'll match the default argument.

Return typing

Mockito returns a type-compatible false, based on the declared return type. We don't have defined type values in PHP, so we always return null. TODO: Support using phpdoc @return when declared.

TODO

License

Copyright (C) 2012 Hamish Friedlander / SilverStripe.

Distributable under either the same license as SilverStripe or the Apache Public License V2 (http://www.apache.org/licenses/LICENSE-2.0.html) at your choice

You don’t have to do anything special to choose one license or the other and you don’t have to notify anyone which license you are using.

Hamcrest-php is under it's own license - see hamcrest-php/LICENSE.txt.


All versions of phockito with dependencies

PHP Build Version
Package Version
No informations.
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 crashuxx/phockito contains the following files

Loading the files please wait ....