2017 © Pedro Peláez
 

library phony-kahlan

Phony for Kahlan.

image

eloquent/phony-kahlan

Phony for Kahlan.

  • Friday, June 8, 2018
  • by ezzatron
  • Repository
  • 1 Watchers
  • 3 Stars
  • 3,929 Installations
  • PHP
  • 45 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 33 % Grown

The README.md

Phony for Kahlan

![Current version image][version-image] Current build status image Current Windows build status image ![Current coverage status image][coverage-image], (*1)

Installation and documentation

What is Phony for Kahlan?

Phony for Kahlan is a plugin for the Kahlan testing framework that provides general integration with the Phony mocking framework, as well as optional auto-wired test dependencies., (*2)

In other words, if a Kahlan test (or suite) requires a mock object, it can be defined to have a parameter with an appropriate type declaration, and it will automatically receive a mock of that type as an argument when run., (*3)

Stubs for callable types, and "empty" values for other type declarations are also supported., (*4)

Plugin installation

Installation is only required when using the dependency injection features of the plugin. The plugin can be installed in the Kahlan configuration file like so:, (*5)

<?php // kahlan-config.php

// disable monkey-patching for Phony classes
$this->commandLine()->set('exclude', ['Eloquent\Phony']);

// install the plugin once autoloading is available
Kahlan\Filter\Filters::apply($this, 'run', function (callable $chain) {
    Eloquent\Phony\Kahlan\install();

    return $chain();
});

Dependency injection

Once the plugin is installed, any tests or suites that are defined with parameters will be supplied with matching arguments when run:, (*6)

describe('Phony for Kahlan', function () {
    it('Auto-wires test dependencies', function (PDO $db) {
        expect($db)->toBeAnInstanceOf(PDO::class);
    });
});

Injected mock objects

Phony for Kahlan supports automatic injection of mock objects. Because Phony doesn't alter the interface of mocked objects, it is necessary to use [on()] to retrieve the mock handle in order to perform stubbing and verification:, (*7)

use function Eloquent\Phony\Kahlan\on;

describe('Phony for Kahlan', function () {
    it('Supports stubbing', function (PDO $db) {
        on($db)->exec->with('DELETE FROM users')->returns(111);

        expect($db->exec('DELETE FROM users'))->toBe(111);
    });

    it('Supports verification', function (PDO $db) {
        $db->exec('DROP TABLE users');

        on($db)->exec->calledWith('DROP TABLE users');
    });
});

Injected stubs

Phony for Kahlan supports automatic injection of stubs for parameters with a callable type declaration:, (*8)

describe('Phony for Kahlan', function () {
    it('Supports callable stubs', function (callable $stub) {
        $stub->with('a', 'b')->returns('c');
        $stub('a', 'b');

        $stub->calledWith('a', 'b')->firstCall()->returned('c');
    });
});

Supported types

The following table lists the supported type declarations, and the value supplied for each:, (*9)

Parameter type Supplied value
(none) null
bool false
int 0
float .0
string ''
array []
iterable []
object (object) []
stdClass (object) []
callable [stub()]
Closure function () {}
Generator (function () {return; yield;})()

When using a type declaration that is not listed above, the supplied value will be a mock of the specified type., (*10)

By necessity, the supplied value will not be wrapped in a mock handle. In order to obtain a handle, simply use [on()]:, (*11)

use function Eloquent\Phony\Kahlan\on;

it('Example mock handle retrieval', function (ClassA $mock) {
    $handle = on($mock);
});

License

For the full copyright and license information, please view the LICENSE file., (*12)

The Versions

08/06 2018

dev-master

9999999-dev http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy

08/06 2018

2.0.0

2.0.0.0 http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy

08/06 2018

dev-pmall-phony-3

dev-pmall-phony-3 http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy

17/10 2017

dev-fix-config-autoloading

dev-fix-config-autoloading http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy

17/10 2017

1.0.1

1.0.1.0 http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy

05/10 2017

1.0.0

1.0.0.0 http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy

29/09 2017

0.3.0

0.3.0.0 http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy

17/08 2017

0.2.0

0.2.0.0 http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy

13/07 2017

0.1.0

0.1.0.0 http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy

13/07 2017

dev-injection

dev-injection http://eloquent-software.com/phony/

Phony for Kahlan.

  Sources   Download

MIT

The Requires

 

The Development Requires

test mock stub mocking double dummy fake stubbing spy