From f1c3200c9bf828086e55bb1712bf5899255fcd74 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 20 Nov 2023 14:57:51 -0300 Subject: [PATCH 1/2] More clean code in tests. --- tests/AssetTest.php | 39 ++++++++++++++++++++------------------- tests/SelectizeTest.php | 3 --- tests/TestCase.php | 4 ++++ 3 files changed, 24 insertions(+), 22 deletions(-) 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..8a33046 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,12 +8,14 @@ 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 +60,7 @@ protected function destroyApplication() Yii::$app = null; Yii::$container = new Container(); Assert::removeFilesFromDirectory(__DIR__ . '/Support/runtime'); + + unset($this->view); } } From dc850ae9e984334813fa54b3de0a0596a9926ca4 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 20 Nov 2023 17:58:05 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- tests/TestCase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/TestCase.php b/tests/TestCase.php index 8a33046..d989681 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -16,6 +16,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { protected View $view; + /** * Clean up after test. * By default the application created with [[mockApplication]] will be destroyed.