File: SearchTest.php

package info (click to toggle)
mariadb-mysql-kbs 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 7,516 kB
  • sloc: php: 1,038; javascript: 388; sh: 220; xml: 57; makefile: 8
file content (206 lines) | stat: -rw-r--r-- 5,961 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php

declare(strict_types = 1);

namespace Williamdes\MariaDBMySQLKBS\Test;

use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
use Williamdes\MariaDBMySQLKBS\SlimData;
use Williamdes\MariaDBMySQLKBS\Search;
use Williamdes\MariaDBMySQLKBS\KBException;

class SearchTest extends TestCase
{

    /**
     * Load slim data
     *
     * @return void
     */
    public static function setUpBeforeClass(): void
    {
        $sd = new SlimData();
        $sd->addVariable('variable-1', 'boolean', true);
        $sd->addVariable('variable-2', null, null);
        $sd->addVariable('variable-3', null, true);
        $variable4 = $sd->addVariable('variable-4', null, false);
        $variable4->addDocumentation('https://mariadb.com/testurl/for/variable/4', 'myanchor');
        $variable4->addDocumentation('https://dev.mysql.com/testurl_for-variable/4', 'my_anchor');
        $variable5 = $sd->addVariable('variable-5', null, false);
        $variable5->addDocumentation('https://docs.aws.amazon.com/testurl/for/variable/5#myanchor', null);

        Search::loadTestData($sd);
    }

    /**
     * test get by name
     *
     * @return void
     */
    public function testGetByName(): void
    {
        $found = Search::getByName('variable-4');
        $this->assertEquals('https://mariadb.com/testurl/for/variable/4#myanchor', $found);
    }

    /**
     * test get by name for MySQL
     *
     * @return void
     */
    public function testGetByNameMYSQL(): void
    {
        $found = Search::getByName('variable-4', Search::MYSQL);
        $this->assertEquals('https://dev.mysql.com/testurl_for-variable/4#my_anchor', $found);
    }

    /**
     * test get by name for Aurora MySQL
     */
    public function testGetByNameMYSQLAurora(): void
    {
        $found = Search::getByName('variable-5', Search::AURORA_MYSQL);
        $this->assertEquals('https://docs.aws.amazon.com/testurl/for/variable/5#myanchor', $found);
    }

    /**
     * test get by name for Aurora MySQL but the engine is MYSQL
     */
    public function testGetByNameMYSQLAuroraEngineMySQL(): void
    {
        $found = Search::getByName('variable-5', Search::MYSQL);
        $this->assertEquals('https://docs.aws.amazon.com/testurl/for/variable/5#myanchor', $found);
    }

    /**
     * test get by name for MARIADB
     *
     * @return void
     */
    public function testGetByNameMARIADB(): void
    {
        $found = Search::getByName('variable-4', Search::MARIADB);
        $this->assertEquals('https://mariadb.com/testurl/for/variable/4#myanchor', $found);
    }

    /**
     * test get by name
     *
     *
     * @return void
     */
    public function testException(): void
    {
        $this->expectException(KBException::class);
        $this->expectExceptionCode(0);
        $varName = 'variable-3';
        $this->expectExceptionMessage($varName . ' does not exist for this type of documentation !');
        Search::getByName($varName, Search::MARIADB);
    }

    /**
     * test get by name not found variable
     *
     *
     * @return void
     */
    public function testExceptionNoFoundGetVariableType(): void
    {
        $this->expectException(KBException::class);
        $this->expectExceptionCode(0);
        $varType = 'acbdefghi0202';
        $this->expectExceptionMessage($varType . ' does not exist !');
        Search::getVariableType($varType);
    }

    /**
     * test get by name not found variable
     *
     *
     * @return void
     */
    public function testExceptionNoFound(): void
    {
        $this->expectException(KBException::class);
        $this->expectExceptionCode(0);
        $varName = 'acbdefghi0202';
        $this->expectExceptionMessage($varName . ' does not exist !');
        Search::getByName($varName, Search::MARIADB);
    }

    /**
     * test get by name not found variable
     *
     *
     * @return void
     */
    public function testExceptionNoFoundGetVariable(): void
    {
        $this->expectException(KBException::class);
        $this->expectExceptionCode(0);
        $varName = 'acbdefghi0202';
        $this->expectExceptionMessage($varName . ' does not exist !');
        Search::getVariable($varName);
    }

    /**
     * test load data fail
     *
     * @return void
     */
    #[RunInSeparateProcess]
    public function testExceptionLoadData(): void
    {
        $this->expectException(KBException::class);
        $this->expectExceptionCode(0);
        $this->expectExceptionMessage('.merged-ultraslim.json does not exist !');
        Search::$DATA_DIR = '.';
        Search::$loaded   = false;
        Search::loadData();
    }

    /**
     * test get variables with dynamic status
     *
     * @return void
     */
    public function testGetVariablesWithDynamic(): void
    {
        $dynamic = Search::getVariablesWithDynamic(true);
        $this->assertEquals($dynamic, Search::getDynamicVariables());
        $static = Search::getVariablesWithDynamic(false);
        $this->assertEquals($static, Search::getStaticVariables());
        $this->assertEquals(2, count($dynamic));
        $this->assertEquals(2, count($static));
        $common = \array_intersect($dynamic, $static);
        $this->assertEquals(0, count($common));// Impossible to be dynamic and not
    }

    /**
     * test Exception get variable type has no type
     *
     *
     * @return void
     */
    public function testExceptionGetVariableType(): void
    {
        $this->expectException(KBException::class);
        $this->expectExceptionCode(0);
        $varType = 'variable-2';
        $this->expectExceptionMessage($varType . ' does have a known type !');
        Search::getVariableType($varType);
    }

    /**
     * test get variable type
     *
     * @return void
     */
    public function testGetVariableType(): void
    {
        $type = Search::getVariableType('variable-1');
        $this->assertEquals('boolean', $type);
    }

}