Skip to content

Commit a07840b

Browse files
Allow install any version yii2. (#12)
1 parent 7d8d769 commit a07840b

13 files changed

+272
-213
lines changed

.github/workflows/build.yml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
with:
2828
composer-command: |
2929
composer require yiisoft/yii2:^2.2.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
30+
extensions: intl, runkit7
3031
os: >-
3132
['ubuntu-latest', 'windows-latest']
3233
php: >-

.github/workflows/compatibility.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
composer-command: |
2929
composer require yiisoft/yii2:^2.0.49 --prefer-dist --no-progress --no-interaction --no-scripts --ansi
30-
extensions: intl
30+
extensions: intl, runkit7
3131
os: >-
3232
['ubuntu-latest', 'windows-latest']
3333
php: >-

.github/workflows/mutation.yml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
with:
2828
composer-command: |
2929
composer require yiisoft/yii2:^2.2.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
30+
extensions: intl, runkit7
3031
os: >-
3132
['ubuntu-latest']
3233
php: >-

composer.json

+5-19
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
"require": {
1414
"php": ">=8.1",
1515
"npm-asset/bootstrap": "^5.3",
16-
"npm-asset/popperjs--core": "^2.11",
17-
"oomphinc/composer-installers-extender": "^2.0",
18-
"yiisoft/yii2": "*"
16+
"yiisoft/yii2": "^2.0.49 || ^2.2"
1917
},
2018
"require-dev": {
21-
"maglnet/composer-require-checker": "^4.6",
22-
"php-forge/support": "dev-main",
23-
"phpunit/phpunit": "^10.2",
24-
"roave/infection-static-analysis-plugin": "^1.32",
19+
"maglnet/composer-require-checker": "^4.7",
20+
"php-forge/support": "^0.1",
21+
"phpunit/phpunit": "^10.5.7",
22+
"roave/infection-static-analysis-plugin": "^1.34",
2523
"yii2-extensions/phpstan": "dev-main"
2624
},
2725
"autoload": {
@@ -37,24 +35,12 @@
3735
"extra": {
3836
"branch-alias": {
3937
"dev-main": "1.0.x-dev"
40-
},
41-
"installer-types": [
42-
"bower-asset",
43-
"npm-asset"
44-
],
45-
"installer-paths": {
46-
"./node_modules/{$name}": [
47-
"type:bower-asset",
48-
"type:npm-asset"
49-
]
5038
}
5139
},
5240
"config": {
5341
"sort-packages": true,
5442
"allow-plugins": {
5543
"yiisoft/yii2-composer": true,
56-
"composer/installers": true,
57-
"oomphinc/composer-installers-extender": true,
5844
"infection/extension-installer": true
5945
}
6046
},

phpunit.xml.dist

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
5-
bootstrap="tests/Support/bootstrap.php"
6-
cacheDirectory=".phpunit.cache"
7-
colors="true"
8-
executionOrder="depends,defects"
9-
failOnRisky="true"
10-
failOnWarning="true"
11-
stopOnFailure="false"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
5+
bootstrap="tests/Support/bootstrap.php"
6+
cacheDirectory=".phpunit.cache"
7+
colors="true"
8+
executionOrder="depends,defects"
9+
failOnRisky="true"
10+
failOnWarning="true"
11+
stopOnFailure="false"
1212
>
13-
<testsuites>
14-
<testsuite name="Yii2-Asset-Bootstrap5">
15-
<directory>tests</directory>
16-
</testsuite>
17-
</testsuites>
13+
<testsuites>
14+
<testsuite name="Asset-Bootstrap5">
15+
<directory>tests</directory>
16+
</testsuite>
17+
</testsuites>
1818

19-
<source>
20-
<include>
21-
<directory suffix=".php">./src</directory>
22-
</include>
23-
</source>
19+
<source>
20+
<include>
21+
<directory suffix=".php">./src</directory>
22+
</include>
23+
</source>
2424
</phpunit>

src/BootstrapAsset.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ final class BootstrapAsset extends AssetBundle
1616
*/
1717
public $sourcePath = '@npm/bootstrap/dist/css';
1818

19-
public function init(): void
19+
public function __construct()
2020
{
21-
parent::init();
21+
$environment = defined('YII_ENV') ? YII_ENV : 'prod';
22+
$cssFiles = $environment === 'prod' ? 'bootstrap.min.css' : 'bootstrap.css';
2223

23-
$assetBootstrap = YII_ENV === 'prod' ? ['bootstrap.min.css'] : ['bootstrap.css'];
24-
$assetBootstrapMap = YII_ENV === 'prod' ? ['bootstrap.min.css.map'] : ['bootstrap.css.map'];
25-
26-
$this->css = $assetBootstrap;
27-
$this->publishOptions['only'] = array_merge($assetBootstrap, $assetBootstrapMap);
24+
$this->css = [$cssFiles];
25+
$this->publishOptions['only'] = [$cssFiles, "{$cssFiles}.map"];
2826
}
2927
}

src/BootstrapPluginAsset.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ final class BootstrapPluginAsset extends AssetBundle
2525
BootstrapAsset::class,
2626
];
2727

28-
public function init(): void
28+
public function __construct()
2929
{
30-
parent::init();
30+
$environment = defined('YII_ENV') ? YII_ENV : 'prod';
31+
$jsFiles = $environment === 'prod' ? 'bootstrap.bundle.min.js' : 'bootstrap.bundle.js';
3132

32-
$assetBootstrapPlugin = YII_ENV === 'prod' ? ['bootstrap.bundle.min.js'] : ['bootstrap.bundle.js'];
33-
$assetBootstrapPluginMap = YII_ENV === 'prod' ? ['bootstrap.bundle.min.js.map'] : ['bootstrap.bundle.js.map'];
34-
35-
$this->js = $assetBootstrapPlugin;
36-
$this->publishOptions['only'] = array_merge($assetBootstrapPlugin, $assetBootstrapPluginMap);
33+
$this->js = [$jsFiles];
34+
$this->publishOptions['only'] = [$jsFiles, "{$jsFiles}.map"];
3735
}
3836
}

tests/AssetTest.php

-151
This file was deleted.

tests/BootstrapAssetTest.php

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yii2\Asset\Tests;
6+
7+
use PHPUnit\Framework\Attributes\RequiresPhp;
8+
use Yii;
9+
use Yii2\Asset\BootstrapAsset;
10+
use Yii2\Asset\Tests\Support\TestSupport;
11+
use yii\web\AssetBundle;
12+
use yii\web\View;
13+
14+
use function runkit_constant_redefine;
15+
16+
final class BootstrapAssetTest extends \PHPUnit\Framework\TestCase
17+
{
18+
use TestSupport;
19+
20+
public function testRegister(): void
21+
{
22+
$view = new View();
23+
24+
$this->assertEmpty($view->assetBundles);
25+
26+
BootstrapAsset::register($view);
27+
28+
$this->assertCount(1, $view->assetBundles);
29+
$this->assertInstanceOf(AssetBundle::class, $view->assetBundles[BootstrapAsset::class]);
30+
31+
$result = $view->renderFile(__DIR__ . '/Support/main.php');
32+
33+
$this->assertStringContainsString('bootstrap.css', $result);
34+
35+
$this->assertSame(['bootstrap.css'], Yii::$app->assetManager->bundles[BootstrapAsset::class]->css);
36+
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css');
37+
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css.map');
38+
$this->assertFileDoesNotExist(__DIR__ . '/Support/runtime/55145ba9/bootstrap.min.css');
39+
$this->assertFileDoesNotExist(__DIR__ . '/Support/runtime/55145ba9/bootstrap.min.css.map');
40+
}
41+
42+
#[RequiresPhp('8.1')]
43+
public function testRegisterWithEnvironmentProd(): void
44+
{
45+
runkit_constant_redefine('YII_ENV', 'prod');
46+
47+
$view = new View();
48+
49+
$this->assertEmpty($view->assetBundles);
50+
51+
BootstrapAsset::register($view);
52+
53+
$this->assertCount(1, $view->assetBundles);
54+
$this->assertInstanceOf(AssetBundle::class, $view->assetBundles[BootstrapAsset::class]);
55+
56+
$result = $view->renderFile(__DIR__ . '/Support/main.php');
57+
58+
$this->assertStringContainsString('bootstrap.min.css', $result);
59+
60+
$this->assertSame(['bootstrap.min.css'], Yii::$app->assetManager->bundles[BootstrapAsset::class]->css);
61+
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.min.css');
62+
$this->assertFileExists(__DIR__ . '/Support/runtime/55145ba9/bootstrap.min.css.map');
63+
$this->assertFileDoesNotExist(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css');
64+
$this->assertFileDoesNotExist(__DIR__ . '/Support/runtime/55145ba9/bootstrap.css.map');
65+
66+
runkit_constant_redefine('YII_ENV', 'dev');
67+
}
68+
}

0 commit comments

Comments
 (0)