diff --git a/tests/AssetTest.php b/tests/AssetTest.php index 08d0b4f..992022f 100644 --- a/tests/AssetTest.php +++ b/tests/AssetTest.php @@ -9,13 +9,16 @@ Asset\DateTimePickerAsset, Asset\DateTimePickerCdnAsset, Asset\JQueryProviderAsset, - DateTimePicker + DateTimePicker, + Tests\Support\TestSupport }; use Yii; use yii\web\AssetBundle; -final class AssetTest extends TestCase +final class AssetTest extends \PHPUnit\Framework\TestCase { + use TestSupport; + public function setup(): void { parent::setUp(); diff --git a/tests/DateTimePickerTest.php b/tests/DateTimePickerTest.php index cd33808..594abe6 100644 --- a/tests/DateTimePickerTest.php +++ b/tests/DateTimePickerTest.php @@ -5,11 +5,13 @@ namespace Yii2\Extensions\DateTimePicker\Tests; use PHPForge\{Html\Textual\I, Support\Assert}; -use Yii2\Extensions\DateTimePicker\{DateTimePicker, Tests\Support\DateTimePickerModel}; +use Yii2\Extensions\DateTimePicker\{DateTimePicker, Tests\Support\DateTimePickerModel, Tests\Support\TestSupport}; use Yii; -final class DateTimePickerTest extends TestCase +final class DateTimePickerTest extends \PHPUnit\Framework\TestCase { + use TestSupport; + public function setup(): void { parent::setUp(); diff --git a/tests/ExceptionTest.php b/tests/ExceptionTest.php index 0d42871..b28b939 100644 --- a/tests/ExceptionTest.php +++ b/tests/ExceptionTest.php @@ -7,7 +7,7 @@ use Yii2\Extensions\DateTimePicker\DateTimePicker; use yii\base\InvalidConfigException; -final class ExceptionTest extends TestCase +final class ExceptionTest extends \PHPUnit\Framework\TestCase { public function testWithoutModelWithoutName(): void { diff --git a/tests/Support/TestSupport.php b/tests/Support/TestSupport.php new file mode 100644 index 0000000..c180a6f --- /dev/null +++ b/tests/Support/TestSupport.php @@ -0,0 +1,71 @@ +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); + } +}