Download the PHP package ernestmarcinko/mockutils without Composer

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

Mock Utility tools for PHPUnit TestCase

tests

This package provides ome utility functions for PHPUnit TestCase class (and descendants) via the MockUtils trait:

Installation & Inclusion

To install the package:

Including in your tests

There are two ways, one is using a trait to extend your TestCase functionality (recommended):

..or use the MockUtilsTestCase class instead of TestCase:

MockUtilsTestCase is only an empty class extending TestCase and using MockUtils.

Global Mocks

The trait adds two utility functions to setGlobalMocks() and unsetGlobalMocks() to set and unset global mocks.

setGlobalMocks

Sets global mocks to the given namespace.

Parameters

Param Type Description Required Extra info
$global_mocks array<string,mixed\|callable> Array of global function name and return value or callable true
$namespace string The namespace of the code where the global function should be set false Make sure to use the code namespace, not the test code namespace

Example

Say you have a service, which uses curl_exec to get a response from an API. During testing you want to mock it and avoid actual connection to the API and instead test with pre-defined responses.

In the test we need the curl_exec to return 'response' for the mock, to do that:

It's also possible to define a callable instead of a static response:

unsetGlobalMocks

Unsets the given global mocks or all global mocks previously defined.

Parameters

Param Type Description Required Extra info
$global_mocks array<string> Array of global function names false

Examples

Exception Assertion

expectCatchException

Checks if the exception was thrown without execution termination.

Compared to PHPUnit core TestCase::expectException this function will not terminate the test execution. The function to test must be however passed in as a closure, ex.: expectCatchException(fn()=>$o->myMethod(), ...)

Parameters

Param Type Description Required Extra info
$fn callable Function to test true Use closure fn()=>{$myObj->myMethod();} to pass in any method
$throwable class-string<Throwable> Expected exception class name true
$message string The expected error message false (optional) If set, then the function will also check the Exception message.

Return values

The function is void, does not return anything, however:

expectCatchException will trigger TestCase::fail() if no exception was thrown, or any of the criteria was not met.

Example


All versions of mockutils with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
phpunit/phpunit Version 11.*
php-mock/php-mock Version ^2.5
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 ernestmarcinko/mockutils contains the following files

Loading the files please wait ....