donatj/mock-duck

Sane mocking library

dev-master 2021-05-18 16:28 UTC

This package is auto-updated.

Last update: 2024-10-19 00:15:55 UTC


README

Latest Stable Version License

A Simple, Sane, Mock Builder for PHPUnit

Currently in a very early stage of development.

Requirements

Installing

Install the latest version with:

composer require 'donatj/mock-duck'

Documentation

Class: \donatj\MockDuck\Exceptions\MockBuilderRuntimeException

Exception thrown as a general runtime exception for the MockBuilder

Class: \donatj\MockDuck\Exceptions\MockMethodNotFoundException

Exception thrown by a method mock on invoke when it does not match the spec and wishes to indicate the parent should continue

Class: \donatj\MockDuck\InvokableMethodInterface

Class: \donatj\MockDuck\MethodCallFallthrough

Executes given invokables until one is successful

Undocumented Method: MethodCallFallthrough->__construct(callable ...$invokables)

Undocumented Method: MethodCallFallthrough->__invoke($args)

Class: \donatj\MockDuck\MethodCallOrdered

Allows setting method invocations on subsequent calls

This is one of the only parts of MockDuck that is not functionally pure and thus should be handled with special care

Undocumented Method: MethodCallOrdered->__construct(callable ...$invokables)

Undocumented Method: MethodCallOrdered->__invoke($args)

Class: \donatj\MockDuck\MethodCallParameterMatcher

Matches a given set of method parameters to a method invoker

Undocumented Method: MethodCallParameterMatcher->withEquality([ $equality = true])

Method: MethodCallParameterMatcher->withMethodParameterMatch

function withMethodParameterMatch(callable $invokable, $args) : self
Parameters:
  • callable $invokable - The method invokable
  • mixed $args - The arguments to match against. Accepts and matches against PHPUnit constraints
Returns:
  • $this

Undocumented Method: MethodCallParameterMatcher->__invoke($args)

Class: \donatj\MockDuck\MethodCallReturns

Method: MethodCallReturns->__construct

function __construct($value)
Parameters:
  • mixed $value - The value to return

Undocumented Method: MethodCallReturns->__invoke($args)

Class: \donatj\MockDuck\MockBuilder

Method: MockBuilder->__construct

function __construct(string $className [, ?\PHPUnit\Framework\Assert $asserter = null])

MockBuilder constructor.

Undocumented Method: MockBuilder->withMethodsExcluded(string ...$methods)

Method: MockBuilder->withDisabledConstructor

function withDisabledConstructor(bool $disable) : self

Enable or disable the original constructor

Returns:
  • $this

Method: MockBuilder->withMockMethod

function withMockMethod(string $method, callable $invokable) : self
Returns:
  • $this

Method: MockBuilder->buildMockClass

function buildMockClass() : string

Build the requested mock to the given spec

Returns:
  • string - The fully qualified class name of the new mock object

Method: MockBuilder->buildMock

function buildMock($constructorArgs) : object

Build the requested mock to the given spec and instantiate it

Parameters:
  • mixed $constructorArgs - The arguments to pass to the constructor
Returns:
  • object - The instance of the Mock