Completed
Pull Request — master (#36)
by Alexander
04:00
created

MockHelper::resetMocks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Yiisoft\Cache\Tests;
4
5
class MockHelper
6
{
7
    /**
8
     * @var int virtual time to be returned by mocked time() function.
9
     * null means normal time() behavior.
10
     */
11
    public static $mock_time;
12
    /**
13
     * @var string|false value to be returned by mocked json_encode() function.
14
     * null means normal json_encode() behavior.
15
     */
16
    public static $mock_json_encode;
17
18
    public static function resetMocks(): void
19
    {
20
        static::$mock_time = null;
21
        static::$mock_json_encode = null;
22
    }
23
}
24
25
namespace Yiisoft\Cache;
26
27
use Yiisoft\Cache\Tests\MockHelper;
28
29
/**
30
 * Mock for the time() function
31
 * @return int
32
 */
33
function time(): int
34
{
35
    return MockHelper::$mock_time ?? \time();
36
}
37
38
/**
39
 * Mock for the json_encode() function
40
 * @return string|false
41
 */
42
function json_encode($value, $options = 0, $depth = 512)
43
{
44
    return MockHelper::$mock_json_encode ?? \json_encode($value, $options, $depth);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Yiisoft\Cache\Tes...alue, $options, $depth) also could return the type boolean which is incompatible with the documented return type false|string.
Loading history...
45
}
46
47
namespace Yiisoft\Cache\Dependency;
48
49
use Yiisoft\Cache\Tests\MockHelper;
50
51
/**
52
 * Mock for the json_encode() function
53
 * @return string|false
54
 */
55
function json_encode($value, $options = 0, $depth = 512)
56
{
57
    return MockHelper::$mock_json_encode ?? \json_encode($value, $options, $depth);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Yiisoft\Cache\Tes...alue, $options, $depth) also could return the type boolean which is incompatible with the documented return type false|string.
Loading history...
58
}
59