2017 © Pedro Peláez
 

library uopz

Wrapper for php uopz library's functions. Useful for unit testing for changing function's behavior in runtime

image

jced-artem/uopz

Wrapper for php uopz library's functions. Useful for unit testing for changing function's behavior in runtime

  • Tuesday, December 6, 2016
  • by jced_artem
  • Repository
  • 2 Watchers
  • 2 Stars
  • 36 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 13 % Grown

The README.md

uopz

Wrapper for php uopz library's functions. Very useful for unit testing for changing function's behavior in runtime., (*1)

Requirements

oupz library

You can install it: - for php-7: pecl install uopz - for php-5.6: pecl install uopz-2.0.7, (*2)

Install

composer require jced-artem/uopz

Usage

class yourClass
{
    use Jced\UopzTrait;
    // ...
}

Hook non-return third-party-called function to get return from it

public function foo($data) {
    return Database::insert($data);
}
public function bar() {
    $data = ['field' => 'value'];
    foo($data);
}

Sometime when you testing bar() you may want to know what happend in foo(), (*3)

public function testBar() {
    $this->uopzFunctionHook(
        'foo',
        function ($data) {
            return $data;
        },
        $fooResult
    );
    bar();
    $this->assertEqual(['field' => 'value'], $fooResult);
}

Replace function's return value using list of conditions.

Source function cant be redefined or defined as closure before using this method., (*4)

public function selectAll($table) {
    return $db->select()->from($table)->fetchAll();
}
public function foo() {
    $result1 = $this->selectAll('user');
    // do something
    $result2 = $this->selectAll('article');
    // do something
    $result3 = $this->selectAll('post');
}

You can mock all calls just doing:, (*5)

public function testFoo() {
    $this->uopzFunctionConditionReturn(
        'selectAll',
        [
            ['table', 'user', [0 => 'user1', 2 => 'user3']],
            ['table', 'post', function () { return 'some other result here'; }],
        ],
        null // for all other queries
    );
}

Consistent return

public function testFoo() {
    $this->uopzFunctionConditionReturn(
        'selectAll',
        [
            [0 => 'user1', 2 => 'user3'],
            'some other result here',
        ]
    );
}

Replace one function with another

$this->uopzFunctionReplace(['mysqli', 'query'], 'mysql_query'); // downgrade :)

Simple return

Just return something, nothing more, (*6)

$this->uopzFunctionSimpleReturn('functionName', 'return string');

Backup function

$this->uopzBackup('functionName');

Restore function

$this->uopzRestore('functionName');

Mute function

Ask function to do nothing :), (*7)

$this->uopzMuteFunction('functionName');

Aliases

// uops_function
    public function uopzFunction($function, Closure $closure, $backup = false);
// uops_redefine
    public function uopzRedefine($constant, $value);
// uops_flags
    public function uopzFlags($function, $flags);

The Versions

06/12 2016

dev-master

9999999-dev https://github.com/jced-artem

Wrapper for php uopz library's functions. Useful for unit testing for changing function's behavior in runtime

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Artem Jced

testing php unit uopz runtime

06/12 2016

1.0.6

1.0.6.0 https://github.com/jced-artem

Wrapper for php uopz library's functions. Useful for unit testing for changing function's behavior in runtime

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Artem Jced

testing php unit uopz runtime

06/12 2016

1.0.5

1.0.5.0 https://github.com/jced-artem

Wrapper for php uopz library's functions. Useful for unit testing for changing function's behavior in runtime

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Artem Jced

testing php unit uopz runtime

01/12 2016

1.0.4

1.0.4.0 https://github.com/jced-artem

Wrapper for php uopz library's functions. Useful for unit testing for changing function's behavior in runtime

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Artem Jced

testing php unit uopz runtime

01/12 2016

1.0.3

1.0.3.0 https://github.com/jced-artem

Wrapper for php uopz library's functions. Useful for unit testing for changing function's behavior in runtime

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

by Artem Jced

testing php unit uopz runtime

30/11 2016

1.0.2

1.0.2.0 https://github.com/jced-artem

Wrapper for php uopz library's functions. Very useful for unit testing for changing function's behaviour in runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

  • php >=5.3.0

by Artem Jced

testing uopz

30/11 2016

1.0.1

1.0.1.0 https://github.com/jced-artem

Wrapper for php uopz library's functions. Very useful for unit testing for changing function's behaviour in runtime.

  Sources   Download

The Requires

  • php >=5.3.0

 

The Development Requires

  • php >=5.3.0

by Artem Jced

testing uopz

30/11 2016

1.0.0

1.0.0.0 https://github.com/jced-artem

Wrapper for php uopz library's functions. Very useful for unit testing for changing function's behaviour in runtime.

  Sources   Download

The Requires

  • php >=5.3.0

 

The Development Requires

  • php >=5.3.0

by Artem Jced

testing uopz