ilya-sp/stub

An extension of Spy that provides function and method stubs.


Keywords
testing, stub, stubs
License
MIT

Documentation

Stub 4 (PHP 7+)

Stub provides the ability to replace (and restore if needed) behavior of functions and methods (both static and non-static) with stubs at runtime.

You can always use class stubs (as long as the eval function is enabled). But if you also want function stubs, you need to install the runkit extension first.

Installation

Add Stub to your project via Composer:

composer require ilya-sp/stub

Usage

Too lazy to write docs.

Helpers

  • function_stub($name): Ilya\Stub\FunctionStubManager
  • class_stub($class, $useRunkit = true): Ilya\Stub\ClassStubManager
  • stub(...$args): Ilya\Stub\StubManager

API

Ilya\Stub\Stub:

  • times($value): void
  • always(): void

Ilya\Stub\StubManager:

  • actAs(callable $stub): Ilya\Stub\Stub
  • actAsSelf(): void
  • kill(): void

Ilya\Stub\ClassStubManager:

  • forMethods(...$patterns): self
  • methods(): array
  • className(): string
  • newInstance(...$args): object
  • callStatic($method, array $args): mixed

Additional Information

Published under the MIT license.