Passed
Push — master ( f5d81f...40d5c1 )
by Alexander
01:47
created

MockHelper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 17
rs 10
c 1
b 0
f 0
wmc 1
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
    /**
26
     * Mock for the time() function
27
     * @return int
28
     */
29
    function time(): int
30
    {
31
        return MockHelper::$mock_time ?? \time();
32
    }
33
34
    /**
35
     * Mock for the json_encode() function
36
     * @return string|false
37
     */
38
    function json_encode($value, $options = 0, $depth = 512)
39
    {
40
        return MockHelper::$mock_json_encode ?? \json_encode($value, $options, $depth);
41
    }
42
}
43
44
namespace Yiisoft\Cache {
45
    function time(): int
46
    {
47
        return \Yiisoft\Cache\Tests\time();
48
    }
49
50
    function json_encode($value, $options = 0, $depth = 512)
51
    {
52
        return \Yiisoft\Cache\Tests\json_encode($value, $options, $depth);
53
    }
54
}
55
56
namespace Yiisoft\Cache\Dependency {
57
    function json_encode($value, $options = 0, $depth = 512)
58
    {
59
        return \Yiisoft\Cache\Tests\json_encode($value, $options, $depth);
60
    }
61
}
62