Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea -...
17
namespace cachestore_redis;
-
 
18
 
-
 
19
use cache_definition;
17
namespace cachestore_redis;
-
 
18
 
-
 
19
use cachestore_redis;
Línea 20... Línea 20...
20
use cache_store;
20
use core_cache\definition;
21
use cachestore_redis;
21
use core_cache\store;
Línea 22... Línea 22...
22
 
22
 
Línea 34... Línea 34...
34
 * @package   cachestore_redis
34
 * @package   cachestore_redis
35
 * @author    Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
35
 * @author    Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
36
 * @copyright 2018 Catalyst IT Australia {@link http://www.catalyst-au.net}
36
 * @copyright 2018 Catalyst IT Australia {@link http://www.catalyst-au.net}
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
38
 */
39
class compressor_test extends \advanced_testcase {
39
final class compressor_test extends \advanced_testcase {
-
 
40
    /** @var null|\cachestore_redis */
-
 
41
    protected ?cachestore_redis $store = null;
Línea 40... Línea -...
40
 
-
 
41
    /**
42
 
42
     * Test set up
-
 
43
     */
43
    #[\Override]
44
    public function setUp(): void {
44
    public function setUp(): void {
45
        if (!cachestore_redis::are_requirements_met() || !defined('TEST_CACHESTORE_REDIS_TESTSERVERS')) {
45
        if (!cachestore_redis::are_requirements_met() || !defined('TEST_CACHESTORE_REDIS_TESTSERVERS')) {
46
            $this->markTestSkipped('Could not test cachestore_redis. Requirements are not met.');
46
            $this->markTestSkipped('Could not test cachestore_redis. Requirements are not met.');
Línea 47... Línea 47...
47
        }
47
        }
48
 
48
 
Línea -... Línea 49...
-
 
49
        parent::setUp();
-
 
50
    }
-
 
51
 
-
 
52
    #[\Override]
-
 
53
    protected function tearDown(): void {
-
 
54
        parent::tearDown();
-
 
55
 
-
 
56
        if ($this->store !== null) {
-
 
57
            $this->store->purge();
-
 
58
            $this->store = null;
49
        parent::setUp();
59
        }
50
    }
60
    }
51
 
61
 
52
    /**
62
    /**
53
     * Create a cachestore.
63
     * Create a cachestore.
54
     *
64
     *
55
     * @param int $compressor
65
     * @param int $compressor
56
     * @param int $serializer
66
     * @param int $serializer
57
     * @return cachestore_redis
67
     * @return cachestore_redis
58
     */
68
     */
59
    public function create_store($compressor, $serializer) {
69
    public function create_store($compressor, $serializer) {
60
        /** @var cache_definition $definition */
70
        /** @var definition $definition */
61
        $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_redis', 'phpunit_test');
71
        $definition = definition::load_adhoc(store::MODE_APPLICATION, 'cachestore_redis', 'phpunit_test');
62
        $config = cachestore_redis::unit_test_configuration();
72
        $config = cachestore_redis::unit_test_configuration();
63
        $config['compressor'] = $compressor;
73
        $config['compressor'] = $compressor;
-
 
74
        $config['serializer'] = $serializer;
Línea 64... Línea 75...
64
        $config['serializer'] = $serializer;
75
        $store = new cachestore_redis('Test', $config);
65
        $store = new cachestore_redis('Test', $config);
76
        $store->initialise($definition);
Línea 66... Línea 77...
66
        $store->initialise($definition);
77
        $this->store = $store;
Línea 103... Línea 114...
103
    /**
114
    /**
104
     * A provider for test_works_with_different_types
115
     * A provider for test_works_with_different_types
105
     *
116
     *
106
     * @return array
117
     * @return array
107
     */
118
     */
108
    public function provider_for_test_it_works_with_different_types() {
119
    public static function provider_for_test_it_works_with_different_types(): array {
109
        $object = new \stdClass();
120
        $object = new \stdClass();
110
        $object->field = 'value';
121
        $object->field = 'value';
Línea 111... Línea 122...
111
 
122
 
112
        return [
123
        return [
Línea 145... Línea 156...
145
     * Test it works with different types for many.
156
     * Test it works with different types for many.
146
     */
157
     */
147
    public function test_it_works_with_different_types_for_many(): void {
158
    public function test_it_works_with_different_types_for_many(): void {
148
        $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, \Redis::SERIALIZER_PHP);
159
        $store = $this->create_store(cachestore_redis::COMPRESSOR_PHP_GZIP, \Redis::SERIALIZER_PHP);
Línea 149... Línea 160...
149
 
160
 
150
        $provider = $this->provider_for_test_it_works_with_different_types();
161
        $provider = self::provider_for_test_it_works_with_different_types();
151
        $keys = [];
162
        $keys = [];
152
        $values = [];
163
        $values = [];
153
        $expected = [];
164
        $expected = [];
154
        foreach ($provider as $item) {
165
        foreach ($provider as $item) {
Línea 164... Línea 175...
164
    /**
175
    /**
165
     * Provider for set/get combination tests.
176
     * Provider for set/get combination tests.
166
     *
177
     *
167
     * @return array
178
     * @return array
168
     */
179
     */
169
    public function provider_for_tests_setget() {
180
    public static function provider_for_tests_setget(): array {
170
        if (!cachestore_redis::are_requirements_met()) {
-
 
171
            // Even though we skip all tests in this case, this provider can still show warnings about non-existing class.
-
 
172
            return [];
-
 
173
        }
-
 
174
 
-
 
175
        $data = [
181
        $data = [
176
            ['none, none',
182
            ['none, none',
177
                \Redis::SERIALIZER_NONE, cachestore_redis::COMPRESSOR_NONE,
183
                \Redis::SERIALIZER_NONE, cachestore_redis::COMPRESSOR_NONE,
178
                'value1', 'value2'],
184
                'value1', 'value2'],
179
            ['none, gzip',
185
            ['none, gzip',
Línea 226... Línea 232...
226
 
232
 
227
    /**
233
    /**
228
     * Test we can use get and set with all combinations.
234
     * Test we can use get and set with all combinations.
229
     *
235
     *
-
 
236
     * @dataProvider provider_for_tests_setget
230
     * @dataProvider provider_for_tests_setget
237
     * @requires extension Redis
231
     * @param string $name
238
     * @param string $name
232
     * @param int $serializer
239
     * @param int $serializer
233
     * @param int $compressor
240
     * @param int $compressor
234
     * @param string $rawexpected1
241
     * @param string $rawexpected1
Línea 250... Línea 257...
250
 
257
 
251
    /**
258
    /**
252
     * Test we can use get and set many with all combinations.
259
     * Test we can use get and set many with all combinations.
253
     *
260
     *
-
 
261
     * @dataProvider provider_for_tests_setget
254
     * @dataProvider provider_for_tests_setget
262
     * @requires extension Redis
255
     * @param string $name
263
     * @param string $name
256
     * @param int $serializer
264
     * @param int $serializer
257
     * @param int $compressor
265
     * @param int $compressor
258
     * @param string $rawexpected1
266
     * @param string $rawexpected1