2017 © Pedro Peláez
 

library phpunit-mock

PHPUnit extension to Mock PHP internal functions using Runkit.

image

lancerhe/phpunit-mock

PHPUnit extension to Mock PHP internal functions using Runkit.

  • Sunday, October 1, 2017
  • by lancerhe
  • Repository
  • 0 Watchers
  • 2 Stars
  • 621 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 5 Versions
  • 9 % Grown

The README.md

PHPUnit Mock Function

PHPUnit extension to Mock PHP internal functions using Runkit., (*1)

Requirements

*This is an optional requirement. Runkit doesn't currently support the override of internal functions (exit, die etc)., (*2)

Installation

Using composer, add the following to the composer.json file:, (*3)

{
   "require": {
       "lancerhe/phpunit-mock": "dev-master"
   }
}

Function Example

ExampleClass.php, (*4)

<?php
class ExampleClass {
    public function doExample() {
        return date();
    }
}

ExampleClassTest.php, (*5)

<?php
class ExampleClassTest extends \PHPUnit_Framework_TestCase {

    /**
     * @test
     */
    public function return_expected_value() {
        $param = 'Y-m-d H:i:s';
        $value = 'non date value';

        $mockFunction = new PHPUnit_Extensions_MockFunction('date', $this);
        $mockFunction->expects($this->once())
            ->with($this->equalTo($param))
            ->will($this->returnValue($value));

        $exampleClass = new ExampleClass();
        $this->assertEquals($value, $exampleClass->doExample($param));
    }
}

Class Example

ExampleClass.php, (*6)

<?php
class Calculate {
    public $a, $b;
    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }
    public function add() {
        return $this->a + $this->b;
    }

    public function minus() {
        return $this->a - $this->b;
    }
}

ExampleClassTest.php, (*7)

<?php
class PHPUnit_Extensions_MockClassTest extends \PHPUnit_Framework_TestCase {

    /**
     * @test
     */
    public function method_return_expected_value() {
        $value = 'non value';

        $mockClass = new PHPUnit_Extensions_MockClass('Calculate', ['add'], $this);
        $mockClass->expects($this->any())
            ->method('add')
            ->will($this->returnValue($value));

        $this->assertEquals($value, (new Calculate(4, 2))->add());
    }
}

The Versions

01/10 2017

dev-master

9999999-dev

PHPUnit extension to Mock PHP internal functions using Runkit.

  Sources   Download

MIT

The Requires

  • ext-runkit *

 

The Development Requires

by James Dempster
by Luke Richards

mock function phpunit testing runkit

01/10 2017

1.1.1

1.1.1.0

PHPUnit extension to Mock PHP internal functions using Runkit.

  Sources   Download

MIT

The Requires

  • ext-runkit *

 

The Development Requires

by James Dempster
by Luke Richards

mock function phpunit testing runkit

22/03 2017

1.1.0

1.1.0.0

PHPUnit extension to Mock PHP internal functions using Runkit.

  Sources   Download

MIT

The Requires

  • ext-runkit *

 

The Development Requires

by James Dempster
by Luke Richards

mock function phpunit testing runkit

22/04 2013

1.0.1

1.0.1.0

PHPUnit extension to Mock PHP internal functions using Runkit.

  Sources   Download

MIT

The Requires

  • ext-runkit *

 

by James Dempster
by Luke Richards

mock function phpunit testing runkit

22/04 2013

1.0.0

1.0.0.0

PHPUnit extension to Mock PHP internal functions using Runkit.

  Sources   Download

by James Dempster
by Luke Richards

mock function phpunit testing