2017 © Pedro Peláez
 

library php-extra-mocks

ExtraMocks are a tools that give extra functionality for Mocks.

image

cheprasov/php-extra-mocks

ExtraMocks are a tools that give extra functionality for Mocks.

  • Saturday, January 28, 2017
  • by cheprasov
  • Repository
  • 1 Watchers
  • 1 Stars
  • 119 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 32 % Grown

The README.md

MIT license, (*1)

ExtraMocks v1.0.0 for PHP >= 5.5

About

ExtraMocks are a tools that give extra functionality for Mocks., (*2)

Main features

  • Allow to redefine global function in namespaces.

Usage

#### \ExtraMocks\Mocks :: mockGlobalFunction ( string $fullName , mixed|callable $result [, int|null $count = null ] )

Redefine global function., (*3)

Method Pameters
  1. string $fullName - name with namespace of function for redefine
  2. mixed|callable $result - new function or result
  3. int|null $count, default = null. Count of mocked calls

#### \ExtraMocks\Mocks :: getCountCalls ( string $fullName )

Get count of mocked calls, (*4)

Method Pameters
  1. string $fullName - fullname of redefined function

Examples

namespace A;

class A
{
    public static function string_length($str)
    {
        return strlen($str);
    }
}
namespace B;

class B {

    public static function string_length($str)
    {
        return strlen($str);
    }
}
namespace Example;

require (__DIR__ . '/../src/autoloader.php');

use ExtraMocks\Mocks;

// 1. Redefine Global Function by Function

\ExtraMocks\Mocks::mockGlobalFunction(
    '\A\strlen',
    function($s) {
        return strlen($s) * 5;
    }
);

echo \A\A::string_length('foo') . PHP_EOL; // 15
echo \B\B::string_length('foo') . PHP_EOL; // 3;

// 2. Redefine Global Function by Result

\ExtraMocks\Mocks::mockGlobalFunction('\A\strlen', 42);

echo \A\A::string_length('foo') . PHP_EOL; // 42;
echo \B\B::string_length('foo') . PHP_EOL; // 3;

// 3. Redefine Global Function by Result once

\ExtraMocks\Mocks::mockGlobalFunction('\A\strlen', 42, 1);

echo \A\A::string_length('foo') . PHP_EOL; // 42;
echo \A\A::string_length('foo') . PHP_EOL; // 3;
echo \B\B::string_length('foo') . PHP_EOL; // 3;

// 3. Get count of calls mocked function

\ExtraMocks\Mocks::mockGlobalFunction('\A\strlen', 42);

echo Mocks::getCountCalls('\A\strlen') . PHP_EOL; // 0
echo \A\A::string_length('foo') . PHP_EOL;        // 42;
echo Mocks::getCountCalls('\A\strlen') . PHP_EOL; // 1
echo \A\A::string_length('foo') . PHP_EOL;        // 42;
echo Mocks::getCountCalls('\A\strlen') . PHP_EOL; // 2

Installation

Composer

Download composer:, (*5)

wget -nc http://getcomposer.org/composer.phar

and add dependency to your project:, (*6)

php composer.phar require cheprasov/php-extra-mocks

Running tests

  1. To run tests type in console:, (*7)

    ./vendor/bin/phpunit, (*8)

Something doesn't work

Feel free to fork project, fix bugs and finally request for pull, (*9)

The Versions

28/01 2017

dev-master

9999999-dev http://github.com/cheprasov/php-extra-mocks

ExtraMocks are a tools that give extra functionality for Mocks.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

28/01 2017

1.0.0

1.0.0.0 http://github.com/cheprasov/php-extra-mocks

ExtraMocks are a tools that give extra functionality for Mocks.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov