diff --git a/tests/AssetTest.php b/tests/AssetTest.php index be2868a..5dc06cb 100644 --- a/tests/AssetTest.php +++ b/tests/AssetTest.php @@ -11,42 +11,43 @@ use Yii2\Extensions\Selectize\Selectize; use yii\web\AssetBundle; use yii\web\JqueryAsset; -use yii\web\View; final class AssetTest extends TestCase { - public function testSelectizeAssetSimpleDependency(): void + public function setup(): void { + parent::setUp(); $this->mockApplication(); - $view = Yii::$app->getView(); + Selectize::$counter = 0; + + $this->view = Yii::$app->getView(); + } - $this->assertEmpty($view->assetBundles); + public function testSelectizeAssetSimpleDependency(): void + { + $this->assertEmpty($this->view->assetBundles); - SelectizeAsset::register($view); + SelectizeAsset::register($this->view); - $this->assertCount(4, $view->assetBundles); + $this->assertCount(4, $this->view->assetBundles); - $this->assertArrayHasKey(SelectizeAsset::class, $view->assetBundles); - $this->assertArrayHasKey(BootstrapAsset::class, $view->assetBundles); - $this->assertArrayHasKey(BootstrapPluginAsset::class, $view->assetBundles); - $this->assertArrayHasKey(JqueryAsset::class, $view->assetBundles); + $this->assertArrayHasKey(SelectizeAsset::class, $this->view->assetBundles); + $this->assertArrayHasKey(BootstrapAsset::class, $this->view->assetBundles); + $this->assertArrayHasKey(BootstrapPluginAsset::class, $this->view->assetBundles); + $this->assertArrayHasKey(JqueryAsset::class, $this->view->assetBundles); } public function testFileSelectizeAssetRegister(): void { - $this->mockApplication(); - - $view = new View(); - - $this->assertEmpty($view->assetBundles); + $this->assertEmpty($this->view->assetBundles); - SelectizeAsset::register($view); + SelectizeAsset::register($this->view); - $this->assertCount(4, $view->assetBundles); - $this->assertInstanceOf(AssetBundle::class, $view->assetBundles[SelectizeAsset::class]); + $this->assertCount(4, $this->view->assetBundles); + $this->assertInstanceOf(AssetBundle::class, $this->view->assetBundles[SelectizeAsset::class]); - $result = $view->renderFile( + $result = $this->view->renderFile( __DIR__ . '/Support/main.php', ['widget' => Selectize::widget(['name' => 'tags', 'id' => 'tests-id'])], ); diff --git a/tests/SelectizeTest.php b/tests/SelectizeTest.php index 7b2a8e6..8301c69 100644 --- a/tests/SelectizeTest.php +++ b/tests/SelectizeTest.php @@ -8,12 +8,9 @@ use Yii; use Yii2\Extensions\Selectize\Selectize; use Yii2\Extensions\Selectize\Tests\Support\SelectizeModel; -use yii\web\View; final class SelectizeTest extends TestCase { - private View $view; - public function setup(): void { parent::setUp(); diff --git a/tests/TestCase.php b/tests/TestCase.php index a8b234a..d989681 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,12 +8,15 @@ use Yii; use yii\di\Container; use yii\web\Application; +use yii\web\View; /** * This is the base class for all yii framework unit tests. */ abstract class TestCase extends \PHPUnit\Framework\TestCase { + protected View $view; + /** * Clean up after test. * By default the application created with [[mockApplication]] will be destroyed. @@ -58,5 +61,7 @@ protected function destroyApplication() Yii::$app = null; Yii::$container = new Container(); Assert::removeFilesFromDirectory(__DIR__ . '/Support/runtime'); + + unset($this->view); } }