1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core_cache;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* PHPunit tests for the cache_helper class.
|
|
|
21 |
*
|
|
|
22 |
* @package core
|
|
|
23 |
* @category cache
|
|
|
24 |
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
* @coversDefaultClass \cache_helper
|
|
|
27 |
*/
|
|
|
28 |
class cache_helper_test extends \advanced_testcase {
|
|
|
29 |
/**
|
|
|
30 |
* Test the result_found method.
|
|
|
31 |
*
|
|
|
32 |
* @param mixed $value
|
|
|
33 |
* @param bool $expected
|
|
|
34 |
* @dataProvider result_found_provider
|
|
|
35 |
* @covers ::result_found
|
|
|
36 |
*/
|
|
|
37 |
public function test_result_found($value, bool $expected): void {
|
|
|
38 |
$this->assertEquals($expected, \cache_helper::result_found($value));
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Data provider for result_found tests.
|
|
|
43 |
*
|
|
|
44 |
* @return array
|
|
|
45 |
*/
|
|
|
46 |
public function result_found_provider(): array {
|
|
|
47 |
return [
|
|
|
48 |
// Only false values are considered as not found.
|
|
|
49 |
[false, false],
|
|
|
50 |
|
|
|
51 |
// The rest are considered valid values.
|
|
|
52 |
[null, true],
|
|
|
53 |
[0, true],
|
|
|
54 |
['', true],
|
|
|
55 |
[[], true],
|
|
|
56 |
[new \stdClass(), true],
|
|
|
57 |
[true, true],
|
|
|
58 |
[1, true],
|
|
|
59 |
['a', true],
|
|
|
60 |
[[1], true],
|
|
|
61 |
[new \stdClass(), true],
|
|
|
62 |
];
|
|
|
63 |
}
|
|
|
64 |
}
|