Total Complexity | 5 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | abstract class TestCase extends \PHPUnit\Framework\TestCase |
||
17 | { |
||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | protected function setUp(): void |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | protected function tearDown(): void |
||
32 | { |
||
33 | parent::tearDown(); |
||
34 | |||
35 | static::destroyApplication(); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Populates Yii::$app with a new application. |
||
40 | * The application will be destroyed on tearDown() automatically. |
||
41 | * @param array $config the application configuration, if needed |
||
42 | * @param string $appClass name of the application class to create |
||
43 | */ |
||
44 | protected static function mockApplication(array $config = [], string $appClass = Application::class) |
||
45 | { |
||
46 | $localConfigFile = __DIR__ . '/config/main-local.php'; |
||
47 | new $appClass( |
||
48 | ArrayHelper::merge( |
||
49 | require __DIR__ . '/config/main.php', |
||
50 | is_file($localConfigFile) ? require $localConfigFile : [], |
||
51 | $config |
||
52 | ) |
||
53 | ); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Destroys application in Yii::$app by setting it to null. |
||
58 | */ |
||
59 | protected static function destroyApplication() |
||
62 | } |
||
63 | } |
||
64 |