1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiiviet/yii2-payment |
4
|
|
|
* @copyright Copyright (c) 2017 Yii2VN |
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
|
|
|
use yii\helpers\ArrayHelper; |
13
|
|
|
use yii\helpers\FileHelper; |
14
|
|
|
|
15
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class TestCase |
19
|
|
|
* |
20
|
|
|
* @author Vuong Minh <[email protected]> |
21
|
|
|
* @since 1.0 |
22
|
|
|
*/ |
23
|
|
|
class TestCase extends BaseTestCase |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
public function setUp(): void |
28
|
|
|
{ |
29
|
|
|
parent::setUp(); |
30
|
|
|
|
31
|
|
|
$this->mockApplication(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function tearDown(): void |
35
|
|
|
{ |
36
|
|
|
parent::tearDown(); |
37
|
|
|
|
38
|
|
|
$this->destroyApplication(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Populates Yii::$app with a new application |
43
|
|
|
* The application will be destroyed on tearDown() automatically. |
44
|
|
|
* @param array $config The application configuration, if needed |
45
|
|
|
* @param string $appClass name of the application class to create |
46
|
|
|
*/ |
47
|
|
|
protected function mockApplication($config = [], $appClass = '\yii\console\Application') |
48
|
|
|
{ |
49
|
|
|
$file = FileHelper::normalizePath(dirname(__DIR__) . '/vendor/teamtnt/tntsearch/tests/_files/articles.sqlite'); |
50
|
|
|
|
51
|
|
|
new $appClass(ArrayHelper::merge([ |
52
|
|
|
'id' => 'test', |
53
|
|
|
'basePath' => __DIR__, |
54
|
|
|
'bootstrap' => ['vxm\searchable\Bootstrap'], |
55
|
|
|
'vendorPath' => dirname(__DIR__) . '/vendor', |
56
|
|
|
'components' => [ |
57
|
|
|
'db' => [ |
58
|
|
|
'class' => 'yii\db\Connection', |
59
|
|
|
'dsn' => 'sqlite:' . $file, |
60
|
|
|
'username' => 'testUser', |
61
|
|
|
'password' => 'testPass' |
62
|
|
|
] |
63
|
|
|
] |
64
|
|
|
], $config)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Destroys application in Yii::$app by setting it to null. |
69
|
|
|
*/ |
70
|
|
|
protected function destroyApplication() |
71
|
|
|
{ |
72
|
|
|
Yii::$app = null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|