2017 © Pedro Peláez
 

library phpunit-function-mocker

Allows mocking otherwise untestable PHP functions through the use of namespaces

image

lstrojny/phpunit-function-mocker

Allows mocking otherwise untestable PHP functions through the use of namespaces

  • Sunday, February 19, 2017
  • by lstrojny
  • Repository
  • 3 Watchers
  • 51 Stars
  • 189,813 Installations
  • PHP
  • 12 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 3 % Grown

The README.md

PHPUnit function mocker extension

Allows mocking otherwise untestable PHP functions through the use of namespaces., (*1)

Build Status, (*2)

<?php
namespace MyNamespace;

class Tool
{
    public function isString($string)
    {
        return strlen($string) > 0 && ctype_alpha($string);
    }
}
<?php

require_once 'PHPUnit/Extension/FunctionMocker.php';

class MyTestCase extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->php = PHPUnit_Extension_FunctionMocker::start($this, 'MyNamespace')
            ->mockFunction('strlen')
            ->mockFunction('ctype_alpha')
            ->getMock();
    }

    /** @runInSeparateProcess */
    public function testIsStringUsesStrlenAndCtypeAlpha()
    {
        $this->php
            ->expects($this->once())
            ->method('strlen')
            ->with('foo')
            ->will($this->returnValue(3))
        ;
        $this->php
            ->expects($this->once())
            ->method('ctype_alpha')
            ->with('foo')
            ->will($this->returnValue(false))
        ;

        $tool = new MyNamespace\Tool();
        $this->assertFalse($tool->isString('foo'));
    }
}

NOTE

Use @runInSeparateProcess annotation to make sure that the mocking is reliably working in PHP >=5.4, (*3)

The Versions

19/02 2017

dev-master

9999999-dev

Allows mocking otherwise untestable PHP functions through the use of namespaces

  Sources   Download

MIT

The Requires

  • php ~7

 

The Development Requires

19/02 2017

1.0.1

1.0.1.0

Allows mocking otherwise untestable PHP functions through the use of namespaces

  Sources   Download

MIT

The Requires

  • php ~7

 

The Development Requires

15/02 2017

1.0.0

1.0.0.0

Allows mocking otherwise untestable PHP functions through the use of namespaces

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

15/02 2017

0.4.1

0.4.1.0

Allows mocking otherwise untestable PHP functions through the use of namespaces

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

24/06 2016

0.4.0

0.4.0.0

Allows mocking otherwise untestable PHP functions through the use of namespaces

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

30/07 2015

0.3.0

0.3.0.0

Allows mocking otherwise untestable PHP functions through the use of namespaces

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

19/01 2014

0.2.0

0.2.0.0

Allows mocking otherwise untestable PHP functions through the use of namespaces

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires