generated from yii2-extensions/template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tests and add TestSupport trait.
- Loading branch information
1 parent
e1c13d1
commit 70abbf2
Showing
4 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yii2\Extensions\DateTimePicker\Tests\Support; | ||
|
||
use PHPForge\Support\Assert; | ||
use Yii; | ||
use yii\{di\Container, i18n\PhpMessageSource, web\Application, web\View}; | ||
|
||
trait TestSupport | ||
{ | ||
protected View $view; | ||
|
||
/** | ||
* Clean up after test. | ||
* By default the application created with [[mockApplication]] will be destroyed. | ||
*/ | ||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
$this->destroyApplication(); | ||
} | ||
|
||
protected function mockApplication(): void | ||
{ | ||
new Application( | ||
[ | ||
'id' => 'testapp', | ||
'aliases' => [ | ||
'@root' => dirname(__DIR__, 2), | ||
'@bower' => '@vendor/bower-asset', | ||
'@npm' => '@vendor/npm-asset', | ||
], | ||
'basePath' => dirname(__DIR__, 2), | ||
'components' => [ | ||
'assetManager' => [ | ||
'appendTimestamp' => false, | ||
'basePath' => __DIR__ . '/runtime', | ||
'baseUrl' => '/', | ||
], | ||
'i18n' => [ | ||
'translations' => [ | ||
'yii2.extensions.datetime.picker' => [ | ||
'class' => PhpMessageSource::class, | ||
'basePath' => dirname(__DIR__, 2) . '/resource/message', | ||
], | ||
], | ||
], | ||
'request' => [ | ||
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', | ||
'scriptFile' => __DIR__ . '/index.php', | ||
'scriptUrl' => '/index.php', | ||
], | ||
], | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* Destroys application in Yii::$app by setting it to null. | ||
*/ | ||
protected function destroyApplication() | ||
{ | ||
Yii::$app = null; | ||
Yii::$container = new Container(); | ||
Assert::removeFilesFromDirectory(__DIR__ . '/runtime'); | ||
|
||
unset($this->view); | ||
} | ||
} |