Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
22.78% covered (danger)
22.78%
18 / 79
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_cache_memory_test
22.78% covered (danger)
22.78%
18 / 79
75.00% covered (warning)
75.00%
3 / 4
29.56
0.00% covered (danger)
0.00%
0 / 1
 getDataSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setUp
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 cache_single_query_data
0.00% covered (danger)
0.00%
0 / 61
0.00% covered (danger)
0.00%
0 / 1
2
 test_cache_single_query
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14require_once __DIR__ . '/cache_memory.php';
15
16class phpbb_cache_memory_test extends phpbb_database_test_case
17{
18    protected $cache;
19    protected $db;
20
21    public function getDataSet()
22    {
23        return $this->createXMLDataSet(__DIR__.'/fixtures/cache_memory.xml');
24    }
25
26    protected function setUp(): void
27    {
28        global $db;
29        parent::setUp();
30
31        $this->cache = new phpbb_cache_memory();
32        $db = $this->new_dbal();
33        $this->db = $db;
34    }
35
36    static public function cache_single_query_data()
37    {
38        return array(
39            array(
40                array(
41                    array(
42                        'SELECT * FROM ' . POSTS_TABLE,
43                        3,
44                    ),
45                ),
46                POSTS_TABLE,
47            ),
48            array(
49                array(
50                    array(
51                        'SELECT * FROM ' . POSTS_TABLE,
52                        3,
53                    ),
54                    array(
55                        'SELECT * FROM ' . POSTS_TABLE . ' p
56                            LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
57                        3,
58                    ),
59                ),
60                POSTS_TABLE,
61            ),
62            array(
63                array(
64                    array(
65                        'SELECT * FROM ' . POSTS_TABLE,
66                        3,
67                    ),
68                    array(
69                        'SELECT * FROM ' . POSTS_TABLE . ' p
70                            LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
71                        3,
72                    ),
73                    array(
74                        'SELECT * FROM ' . POSTS_TABLE . ' p
75                            LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
76                            LEFT JOIN ' . USERS_TABLE . ' u ON p.poster_id = u.user_id',
77                        3,
78                    ),
79                ),
80                POSTS_TABLE,
81            ),
82            array(
83                array(
84                    array(
85                        'SELECT * FROM ' . POSTS_TABLE . ' p
86                            LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
87                        3,
88                    ),
89                    array(
90                        'SELECT * FROM ' . POSTS_TABLE . ' p
91                            LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
92                            LEFT JOIN ' . USERS_TABLE . ' u ON p.poster_id = u.user_id',
93                        3,
94                    ),
95                ),
96                TOPICS_TABLE,
97            ),
98        );
99    }
100
101    /**
102    * @dataProvider cache_single_query_data
103    */
104    public function test_cache_single_query($sql_queries, $table)
105    {
106        foreach ($sql_queries as $query)
107        {
108            $sql_request_res = $this->db->sql_query($query[0]);
109
110            $this->cache->sql_save($this->db, $query[0], $sql_request_res, 1);
111
112            $results = array();
113            $query_id = $this->cache->sql_load($query[0]);
114            while ($row = $this->cache->sql_fetchrow($query_id))
115            {
116                $results[] = $row;
117            }
118            $this->cache->sql_freeresult($query_id);
119            $this->assertEquals($query[1], count($results));
120        }
121
122        $this->cache->destroy('sql', $table);
123
124        foreach ($sql_queries as $query)
125        {
126            $this->assertFalse($this->cache->sql_load($query[0]));
127        }
128    }
129}