PHP code example of jced-artem / uopz

1. Go to this page and download the library: Download jced-artem/uopz library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jced-artem / uopz example snippets


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

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

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');
}

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
    );
}

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

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

$this->uopzBackup('functionName');

$this->uopzRestore('functionName');

$this->uopzMuteFunction('functionName');

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