SearchableTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testBootable() 0 5 1
A testMakeSearchable() 0 14 1
A testDeleteSearchable() 0 13 1
A testDeleteAllFromSearch() 0 7 1
A testSearchMode() 0 10 1
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/yii2-searchable
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace vxm\test\unit\searchable;
9
10
use Yii;
11
12
/**
13
 * Class SearchableTest
14
 *
15
 * @author Vuong Minh <[email protected]>
16
 * @since 1.0.0
17
 */
18
class SearchableTest extends TestCase
19
{
20
21
    public function testBootable()
22
    {
23
        $this->assertNotNull(Yii::$app->get('searchable', false));
24
        $this->assertTrue(isset(Yii::$app->controllerMap['searchable']));
25
    }
26
27
    public function testMakeSearchable()
28
    {
29
        Model::deleteAllFromSearch();
30
        Model::makeAllSearchable();
31
32
        $this->assertTrue(file_exists(Model::getSearchable()->storagePath . '/articles.index'));
33
34
        $models = Model::find()->limit(5)->all();
35
36
        Model::deleteAllFromSearch();
37
        Model::makeSearchable($models);
38
39
        $this->assertTrue(file_exists(Model::getSearchable()->storagePath . '/articles.index'));
40
    }
41
42
    public function testDeleteSearchable()
43
    {
44
        Model::makeAllSearchable();
45
        $model = new Model([
46
            'title' => 'deleteSearchable',
47
            'article' => 'deleteSearchable'
48
        ]);
49
        $model->save();
50
        $this->assertNotEmpty(Model::searchIds('deleteSearchable'));
51
        Model::deleteSearchable($model);
52
        $this->assertEmpty(Model::searchIds('deleteSearchable'));
53
        $model->delete();
54
    }
55
56
    public function testDeleteAllFromSearch()
57
    {
58
        Model::makeAllSearchable();
59
        Model::deleteAllFromSearch();
60
61
        $this->assertFalse(file_exists(Model::getSearchable()->storagePath . '/articles.index'));
62
    }
63
64
    public function testSearchMode()
65
    {
66
        Model::deleteAllFromSearch();
67
        Model::makeAllSearchable();
68
69
        $booleanIds = Model::searchIds('romeo or hamlet', 'boolean');
70
        $fuzzyIds = Model::searchIds('romeo or hamlet', 'fuzzy', ['fuzziness' => true]);
71
72
        $this->assertNotEquals($fuzzyIds, $booleanIds);
73
    }
74
75
}
76