Skip to content

Commit

Permalink
Simplify code. (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 19, 2024
1 parent 77983de commit 0bb6571
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
13 changes: 6 additions & 7 deletions src/BootstrapAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Yiisoft\Assets\AssetBundle;
use Yiisoft\Files\PathMatcher\PathMatcher;

use function array_merge;
use function defined;

/**
* Twitter Bootstrap 5 CSS bundle.
Expand All @@ -20,13 +20,12 @@ final class BootstrapAsset extends AssetBundle

public function __construct()
{
$filesPattern = YII_ENV === 'prod' ? ['**/css/bootstrap.min.css'] : ['**/css/bootstrap.css'];
$filesMap = YII_ENV === 'prod' ? ['**/css/bootstrap.min.css.map'] : ['**/css/bootstrap.css.map'];
$files = array_merge($filesPattern, $filesMap);

$pathMatcher = new PathMatcher();

$this->css = [YII_ENV === 'prod' ? 'bootstrap.min.css' : 'bootstrap.css'];
$this->publishOptions = ['filter' => $pathMatcher->only(...$files)];
$environment = defined('YII_ENV') ? YII_ENV : 'prod';
$cssFiles = $environment === 'prod' ? 'bootstrap.min.css' : 'bootstrap.css';

$this->css = [$cssFiles];
$this->publishOptions = ['filter' => $pathMatcher->only("**/css/{$cssFiles}", "**/css/{$cssFiles}.map")];
}
}
13 changes: 6 additions & 7 deletions src/BootstrapPluginAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Yiisoft\Assets\AssetBundle;
use Yiisoft\Files\PathMatcher\PathMatcher;

use function array_merge;
use function defined;

/**
* Twitter Bootstrap 5 JavaScript bundle.
Expand All @@ -21,13 +21,12 @@ final class BootstrapPluginAsset extends AssetBundle

public function __construct()
{
$filesPattern = YII_ENV === 'prod' ? ['**/js/bootstrap.bundle.min.js'] : ['**/js/bootstrap.bundle.js'];
$filesMap = YII_ENV === 'prod' ? ['**/js/bootstrap.bundle.min.js.map'] : ['**/js/bootstrap.bundle.js.map'];
$files = array_merge($filesPattern, $filesMap);

$pathMatcher = new PathMatcher();

$this->js = [YII_ENV === 'prod' ? 'bootstrap.bundle.min.js' : 'bootstrap.bundle.js'];
$this->publishOptions = ['filter' => $pathMatcher->only(...$files)];
$environment = defined('YII_ENV') ? YII_ENV : 'prod';
$jsFiles = $environment === 'prod' ? 'bootstrap.bundle.min.js' : 'bootstrap.bundle.js';

$this->js = [$jsFiles];
$this->publishOptions = ['filter' => $pathMatcher->only("**/js/{$jsFiles}", "**/js/{$jsFiles}.map")];
}
}
18 changes: 6 additions & 12 deletions tests/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ public function testBootstrapPluginCdnAssetRegister(): void
);
}

/**
* @depends testBootstrapAssetRegister
* @depends testBootstrapCdnAssetRegister
* @depends testBootstrapPluginAssetRegister
* @depends testBootstrapPluginCdnAssetRegister
*/
#[RequiresPhp('8.1')]
public function testProdBootstrapAssetRegister(): void
{
Expand All @@ -129,17 +123,15 @@ public function testProdBootstrapAssetRegister(): void
);
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.min.css');
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.min.css.map');

@runkit_constant_redefine('YII_ENV', 'test');
}

/**
* @depends testBootstrapAssetRegister
* @depends testBootstrapCdnAssetRegister
* @depends testBootstrapPluginAssetRegister
* @depends testBootstrapPluginCdnAssetRegister
*/
#[RequiresPhp('8.1')]
public function testProdBootstrapPluginAssetRegister(): void
{
@runkit_constant_redefine('YII_ENV', 'prod');

$this->assertFalse($this->assetManager->isRegisteredBundle(BootstrapPluginAsset::class));

$this->assetManager->register(BootstrapPluginAsset::class);
Expand All @@ -156,5 +148,7 @@ public function testProdBootstrapPluginAssetRegister(): void
);
$this->assertFileExists(__DIR__ . '/Support/runtime/16b8de20/bootstrap.bundle.min.js');
$this->assertFileExists(__DIR__ . '/Support/runtime/16b8de20/bootstrap.bundle.min.js.map');

@runkit_constant_redefine('YII_ENV', 'test');
}
}

0 comments on commit 0bb6571

Please sign in to comment.