2017 © Pedro Peláez
 

library doublit

Doublit : Double and test any PHP class easily in PhpUnit

image

gealex/doublit

Doublit : Double and test any PHP class easily in PhpUnit

  • Thursday, July 26, 2018
  • by gealex
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Doublit - Double and test PHP classes easily in PhpUnit

Build Status, (*1)

Doublit can help you to test your PHP classes by generating doubles that look like the original classes but can be manipulated and tested (sort of a copy of a class). These doubles then can then be used instead of the original classes for your test. Doublit can create doubles of any kind of class, interface or trait., (*2)

See full documentation at https://getdoublit.com, (*3)

Installation

Add the line "gealex/doublit": "~2.1.0" in the "require-dev" section of your composer.json file :, (*4)

{
    "require-dev": {
        "gealex/doublit": "~2.1.0"
    }
}

And run the following command :, (*5)

$ composer update

This will install the latest version of Doublit with the required PhpUnit package., (*6)

Creating a double

A double is called a "dummy" when all the methods of the original class are overwritten to return null. To get a "dummy" double instance, use the dummy method :, (*7)

```php
// Get a double instance of type "dummy" for class "MyClass"
$my_double = Doublit::dummy(MyClass::class)->getInstance();
```

A double is called a "mock" when all the methods of the original class are overwritten to behave the same as in the original class. To get a "mock" double instance, use the mock method :, (*8)

```php
// Get a double instance of type "mock" for class "MyClass"
$my_double = Doublit::mock(MyClass::class)->getInstance();
```

For more details : Read the doc on creating doubles, (*9)

Testing a double

To test how many times a double method is called, use the count method :, (*10)

```php
// Test that the method "myMethod" is called a least one time
$double::_method('myMethod')->count('>=1');
```

To test the values of the arguments passed to a double method, use the args method :, (*11)

```php
// Test that the arguments passed to method "myMethod" are "value1" and "value2"
$double::_method('myMethod')->args(['value1', 'value2']);
```

To change the return value of a method, use the stub method. :, (*12)

```php
// Make method "myMethod" return "hello"
$my_double::_method('myMethod')->stub('hello');
```

For more details : Read the doc on testing doubles, (*13)

Configuration

You define the configuration for a specific double using the 2nd argument of the dummy and mock methods :, (*14)

```php
// Get double instance with config
$my_double = Doublit::dummy(MyClass::class, [
    'allow_final_doubles' => true,
    'allow_non_existent_classes' => true
])->getInstance();
```

Here is a list of all available config parameters :, (*15)

  • allow_final_doubles : Set this parameter to false to stop Doublit from trying to make doubles of final classes/methods.
  • allow_protected_methods : Set this parameter to false to disallow testing protected methods.
  • allow_non_existent_classes : Set this parameter to false to disallow alias doubles of non existent classes.
  • test_unexpected_methods : Set this parameter to true to automatically receive an assertion error whenever an unexpected method is called.

For more details : Read the doc on configuration, (*16)

About

License

Doublit is licensed under the MIT license., (*17)

Author

Alexandre Geiswiller - alexandre.geiswiller@gmail.com., (*18)

For more details : Read the doc on about, (*19)

The Versions

26/07 2018

dev-master

9999999-dev https://github.com/gealex/doublit

Doublit : Double and test any PHP class easily in PhpUnit

  Sources   Download

MIT

The Requires

 

by Alexandre GEISWILLER

test mock phpunit testing unit-testing test-doubles

26/07 2018

v1.0.3

1.0.3.0 https://github.com/gealex/doublit

Doublit : Double and test any PHP class easily in PhpUnit

  Sources   Download

MIT

The Requires

 

by Alexandre GEISWILLER

test mock phpunit testing unit-testing test-doubles

25/07 2018

v1.0.2

1.0.2.0 https://github.com/gealex/doublit

Doublit : Double and test any PHP class easily in PhpUnit

  Sources   Download

MIT

The Requires

 

by Alexandre GEISWILLER

test mock phpunit testing unit-testing test-doubles

24/07 2018

v1.0.1

1.0.1.0 https://github.com/gealex/doublit

Doublit : Double any PHP class easily for test in PhpUnit

  Sources   Download

MIT

The Requires

 

by Alexandre GEISWILLER

bdd tdd test mock stub testing double dummy

21/07 2018

v1.0

1.0.0.0 https://github.com/gealex/doublit

Doublit : Double any PHP class easily for test in PhpUnit

  Sources   Download

MIT

The Requires

 

by Alexandre GEISWILLER

tdd test mock stub testing double dummy