2017 © Pedro Peláez
 

library php-native-mock

PHP Native Mock is a helper class that allows for easy mocking of native PHP functions and class methods in unit tests using the UOPZ extension.

image

betterphp/php-native-mock

PHP Native Mock is a helper class that allows for easy mocking of native PHP functions and class methods in unit tests using the UOPZ extension.

  • Wednesday, August 2, 2017
  • by jacekkuzemczak
  • Repository
  • 1 Watchers
  • 0 Stars
  • 585 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 3 Versions
  • 117 % Grown

The README.md

PHP Native Mock

Helper class to mock or redefine native PHP functions in unit tests. Works using the UOPZ module, developed and tested against the master branch., (*1)

Build Status, (*2)

This is largely a wrapper around the uopz functions with some extra bits thrown in to make it a bit easier in tests. It basically relies on dark magic and, like all magic, should only be used very carefully. Creating weird behaviour in applications is very easy, for example, (*3)

$this->redefineFunction('substr', function () {
    return 'Doge';
});

would have some very strange effects., (*4)

Most of the time when redefining a function sounds like a good idea - it's probably not, make sure there is no way a "normal" mocking approach won't work first., (*5)

Installation

The library can be included via composer, (*6)

{
    "require-dev": {
        "betterphp/php-native-mock": "~1"
    }
}

Documentation

Jenkins publishes a phpdoc here, (*7)

Testing

We use phpcs and phpunit for testing, run both before commiting anything, (*8)

./vendor/bin/phpcs -p --standard=./ruleset.xml .
./vendor/bin/phpunit -c ./phpunit.xml

phpunit will do code coverage checking which requires xdebug, if it's not installed this will fail gracefully - not to worry., (*9)

A report of the test coverage is published here by Jenkins, (*10)

The Versions

02/08 2017

1.1.0

1.1.0.0

PHP Native Mock is a helper class that allows for easy mocking of native PHP functions and class methods in unit tests using the UOPZ extension.

  Sources   Download

GPL-3.0

The Requires

  • php >= 7.0.0
  • ext-uopz *

 

The Development Requires

test mock function native unit test redefine

02/08 2017

dev-master

9999999-dev

PHP Native Mock is a helper class that allows for easy mocking of native PHP functions and class methods in unit tests using the UOPZ extension.

  Sources   Download

GPL-3.0

The Requires

  • php >= 7.0.0
  • ext-uopz *

 

The Development Requires

test mock function native unit test redefine

06/05 2017

1.0.0

1.0.0.0

  Sources   Download

GPL-3.0

The Requires

  • php >= 7.0.0
  • ext-uopz *

 

The Development Requires