diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml
index b79d84c..a59ab63 100644
--- a/.github/workflows/static.yml
+++ b/.github/workflows/static.yml
@@ -1,17 +1,13 @@
+name: static analysis
+
on:
- pull_request
- push
-name: static analysis
-
jobs:
mutation:
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
- env:
- extensions: ast
- update: true
-
runs-on: ${{ matrix.os }}
strategy:
@@ -30,7 +26,6 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
- extensions: ${{ env.extensions }}
tools: composer:v2, cs2pr
coverage: none
@@ -38,7 +33,7 @@ jobs:
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
- name: Cache dependencies installed with composer
- uses: actions/cache@v2
+ uses: actions/cache@v1
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
@@ -49,4 +44,4 @@ jobs:
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
- name: Static analysis with phan
- run: vendor/bin/phan --no-progress-bar --output-mode checkstyle | cs2pr --graceful-warnings --colorize
+ run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle | cs2pr --graceful-warnings --colorize
diff --git a/composer.json b/composer.json
index 55d05ed..2b63353 100644
--- a/composer.json
+++ b/composer.json
@@ -28,11 +28,9 @@
},
"require-dev": {
"infection/infection": "^0.16.3",
- "phan/phan": "^3.0",
"phpunit/phpunit": "^9.3",
- "yiisoft/composer-config-plugin": "^1.0@dev",
- "yiisoft/di": "^3.0@dev",
- "yiisoft/log": "^3.0@dev"
+ "vimeo/psalm": "^3.15",
+ "yiisoft/di": "^3.0@dev"
},
"autoload": {
"psr-4": {
diff --git a/psalm.xml b/psalm.xml
new file mode 100644
index 0000000..3e4e3d0
--- /dev/null
+++ b/psalm.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/Breadcrumbs.php b/src/Breadcrumbs.php
index a01ae58..ce0194e 100644
--- a/src/Breadcrumbs.php
+++ b/src/Breadcrumbs.php
@@ -4,11 +4,13 @@
namespace Yiisoft\Yii\Bulma;
+use JsonException;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Html\Html;
use Yiisoft\Widget\Exception\InvalidConfigException;
use function array_key_exists;
+use function array_merge;
use function is_array;
use function strtr;
@@ -53,7 +55,7 @@ protected function run(): string
*
* @param bool $value
*
- * @return self
+ * @return $this
*/
public function encodeLabels(bool $value): self
{
@@ -71,7 +73,7 @@ public function encodeLabels(bool $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*/
public function homeLink(array $value): self
{
@@ -85,7 +87,7 @@ public function homeLink(array $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function itemTemplate(string $value): self
{
@@ -99,7 +101,7 @@ public function itemTemplate(string $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function activeItemTemplate(string $value): self
{
@@ -121,7 +123,7 @@ public function activeItemTemplate(string $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*/
public function links(array $value): self
{
@@ -134,7 +136,7 @@ public function links(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -149,7 +151,7 @@ public function options(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -194,9 +196,9 @@ private function renderIcon(string $icon, array $iconOptions): string
* @param string $template the template to be used to rendered the link. The token "{link}" will be replaced by the
* link.
*
- * @return string the rendering result
+ * @throws InvalidConfigException|JsonException if `$link` does not have "label" element.
*
- * @throws InvalidConfigException if `$link` does not have "label" element.
+ * @return string the rendering result
*/
private function renderItem(array $link, string $template): string
{
diff --git a/src/Dropdown.php b/src/Dropdown.php
index c20b8aa..43d1271 100644
--- a/src/Dropdown.php
+++ b/src/Dropdown.php
@@ -4,12 +4,15 @@
namespace Yiisoft\Yii\Bulma;
+use JsonException;
use Yiisoft\Arrays\ArrayHelper;
+use Yiisoft\Factory\Exceptions\InvalidConfigException;
use Yiisoft\Html\Html;
-use Yiisoft\Widget\Exception\InvalidConfigException;
+use function array_key_exists;
use function array_merge;
use function implode;
+use function is_array;
final class Dropdown extends Widget
{
@@ -41,7 +44,7 @@ protected function run(): string
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function buttonLabel(string $value): self
{
@@ -54,7 +57,7 @@ public function buttonLabel(string $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -69,7 +72,7 @@ public function buttonLabelOptions(array $value): self
*
* @param $value
*
- * @return self
+ * @return $this
*/
public function dividerClass(string $value): self
{
@@ -82,7 +85,7 @@ public function dividerClass(string $value): self
*
* @param $value
*
- * @return self
+ * @return $this
*/
public function itemClass(string $value): self
{
@@ -95,7 +98,7 @@ public function itemClass(string $value): self
*
* @param $value
*
- * @return self
+ * @return $this
*/
public function itemsClass(string $value): self
{
@@ -108,7 +111,7 @@ public function itemsClass(string $value): self
*
* @param bool $value
*
- * @return self
+ * @return $this
*/
public function encodeLabels(bool $value): self
{
@@ -121,7 +124,7 @@ public function encodeLabels(bool $value): self
*
* @param $value
*
- * @return self
+ * @return $this
*/
public function encloseByContainer(bool $value): self
{
@@ -146,7 +149,7 @@ public function encloseByContainer(bool $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*/
public function items(array $value): self
{
@@ -159,7 +162,7 @@ public function items(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -174,7 +177,7 @@ public function options(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -189,7 +192,7 @@ public function buttonOptions(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -204,7 +207,7 @@ public function itemsOptions(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -269,9 +272,9 @@ private function buildOptions(): void
* @param array $items the menu items to be rendered
* @param array $itemsOptions the container HTML attributes
*
- * @return string the rendering result.
+ * @throws InvalidConfigException|JsonException if the label option is not specified in one of the items.
*
- * @throws InvalidConfigException if the label option is not specified in one of the items.
+ * @return string the rendering result.
*/
private function renderItems(array $items, array $itemsOptions = []): string
{
@@ -295,6 +298,16 @@ private function renderItems(array $items, array $itemsOptions = []): string
$label = $item['label'];
}
+ $iconOptions = [];
+
+ $icon = $item['icon'] ?? '';
+
+ if (array_key_exists('iconOptions', $item) && is_array($item['iconOptions'])) {
+ $iconOptions = $this->addOptions($iconOptions, 'icon');
+ }
+
+ $label = $this->renderIcon($label, $icon, $iconOptions);
+
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
$active = ArrayHelper::getValue($item, 'active', false);
$disabled = ArrayHelper::getValue($item, 'disabled', false);
@@ -305,6 +318,7 @@ private function renderItems(array $items, array $itemsOptions = []): string
Html::addCssStyle($linkOptions, 'opacity:.65; pointer-events:none;');
}
+ /** @psalm-suppress ConflictingReferenceConstraint */
if ($active) {
Html::addCssClass($linkOptions, 'is-active');
}
@@ -316,7 +330,7 @@ private function renderItems(array $items, array $itemsOptions = []): string
} else {
$lines[] = Html::a($label, $url, array_merge($this->linkOptions, $linkOptions));
- $lines[] = Dropdown::widget()
+ $lines[] = self::widget()
->dividerClass($this->dividerClass)
->itemClass($this->itemClass)
->itemsClass($this->itemsClass)
@@ -332,4 +346,16 @@ private function renderItems(array $items, array $itemsOptions = []): string
implode("\n", $lines) . "\n" .
Html::endTag('div');
}
+
+ private function renderIcon(string $label, string $icon, array $iconOptions): string
+ {
+ if ($icon !== '') {
+ $label = Html::beginTag('span', $iconOptions) .
+ Html::tag('i', '', ['class' => $icon]) .
+ Html::endTag('span') .
+ Html::tag('span', $label);
+ }
+
+ return $label;
+ }
}
diff --git a/src/Menu.php b/src/Menu.php
index 9a78bd5..b9023fd 100644
--- a/src/Menu.php
+++ b/src/Menu.php
@@ -13,6 +13,7 @@
use function call_user_func;
use function count;
use function implode;
+use function strtr;
final class Menu extends Widget
{
@@ -57,7 +58,7 @@ protected function run(): string
*
* @var bool $value
*
- * @return self
+ * @return $this
*
* {@see isItemActive()}
*/
@@ -73,7 +74,7 @@ public function activateItems(bool $value): self
*
* @param bool $value
*
- * @return self
+ * @return $this
*/
public function activateParents(bool $value): self
{
@@ -86,7 +87,7 @@ public function activateParents(bool $value): self
*
* @var string $value
*
- * @return self
+ * @return $this
*/
public function activeCssClass(string $value): self
{
@@ -100,7 +101,7 @@ public function activeCssClass(string $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function brand(string $value): self
{
@@ -113,7 +114,7 @@ public function brand(string $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function currentPath(string $value): self
{
@@ -124,9 +125,9 @@ public function currentPath(string $value): self
/**
* Whether the labels for menu items should be HTML-encoded.
*
- * @param bool
+ * @param bool $value
*
- * @return self
+ * @return $this
*/
public function encodeLabels(bool $value): self
{
@@ -140,7 +141,7 @@ public function encodeLabels(bool $value): self
*
* @var string $value
*
- * @return self
+ * @return $this
*/
public function firstItemCssClass(string $value): self
{
@@ -154,7 +155,7 @@ public function firstItemCssClass(string $value): self
*
* @var bool $value
*
- * @return self
+ * @return $this
*/
public function hideEmptyItems(bool $value): self
{
@@ -193,7 +194,7 @@ public function hideEmptyItems(bool $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*/
public function items(array $value): self
{
@@ -212,7 +213,7 @@ public function items(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes() for details on how attributes are being rendered}
*/
@@ -231,7 +232,7 @@ public function itemOptions(array $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function labelTemplate(string $value): self
{
@@ -245,7 +246,7 @@ public function labelTemplate(string $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function lastItemCssClass(string $value): self
{
@@ -261,7 +262,7 @@ public function lastItemCssClass(string $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function linkTemplate(string $value): self
{
@@ -277,7 +278,7 @@ public function linkTemplate(string $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -294,7 +295,7 @@ public function options(array $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function subMenuTemplate(string $value): self
{
diff --git a/src/Message.php b/src/Message.php
index 8a5da74..c519205 100644
--- a/src/Message.php
+++ b/src/Message.php
@@ -51,7 +51,7 @@ protected function run(): string
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function body(string $value): self
{
@@ -65,7 +65,7 @@ public function body(string $value): self
* @param string $value setting default 'is-dark', 'is-primary', 'is-link', 'is-info', 'is-success', 'is-warning',
* 'is-danger'.
*
- * @return self
+ * @return $this
*/
public function headerColor(string $value): self
{
@@ -79,7 +79,7 @@ public function headerColor(string $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function headerMessage(string $value): self
{
@@ -94,7 +94,7 @@ public function headerMessage(string $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*/
public function options(array $value): self
{
@@ -109,7 +109,7 @@ public function options(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*/
public function bodyOptions(array $value): self
{
@@ -125,7 +125,7 @@ public function bodyOptions(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*/
public function closeButtonOptions(array $value): self
{
@@ -140,7 +140,7 @@ public function closeButtonOptions(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*/
public function headerOptions(array $value): self
{
@@ -153,7 +153,7 @@ public function headerOptions(array $value): self
*
* @param string $value default setting empty normal, 'is-small', 'is-medium', 'is-large'.
*
- * @return self
+ * @return $this
*/
public function size(string $value): self
{
@@ -166,7 +166,7 @@ public function size(string $value): self
*
* @param bool $value
*
- * @return self
+ * @return $this
*/
public function withoutCloseButton(bool $value): self
{
@@ -179,7 +179,7 @@ public function withoutCloseButton(bool $value): self
*
* @param bool $value
*
- * @return self
+ * @return $this
*/
public function withoutHeader(bool $value): self
{
diff --git a/src/Nav.php b/src/Nav.php
index eb1f742..d386ac9 100644
--- a/src/Nav.php
+++ b/src/Nav.php
@@ -4,10 +4,12 @@
namespace Yiisoft\Yii\Bulma;
+use JsonException;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Html\Html;
-use Yiisoft\Widget\Exception\InvalidConfigException;
+use Yiisoft\Factory\Exceptions\InvalidConfigException;
+use function array_key_exists;
use function implode;
use function is_array;
@@ -36,7 +38,7 @@ protected function run(): string
*
* @param bool $value
*
- * @return self
+ * @return $this
*
* {@see isItemActive}
*/
@@ -51,7 +53,7 @@ public function activateItems(bool $value): self
*
* @param bool $value
*
- * @return self
+ * @return $this
*/
public function activateParents(bool $value): self
{
@@ -64,7 +66,7 @@ public function activateParents(bool $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function currentPath(string $value): self
{
@@ -77,7 +79,7 @@ public function currentPath(string $value): self
*
* @param bool $value
*
- * @return self
+ * @return $this
*/
public function encodeLabels(bool $value): self
{
@@ -104,7 +106,8 @@ public function encodeLabels(bool $value): self
* If a menu item is a string, it will be rendered directly without HTML encoding.
*
* @param array $value
- * @return Nav
+ *
+ * @return $this
*/
public function items(array $value): self
{
@@ -121,6 +124,8 @@ public function items(array $value): self
* @param array $parentItem the parent item information. Please refer to {@see items} for the structure of this
* array.
*
+ * @throws InvalidConfigException
+ *
* @return string the rendering result.
*/
private function renderDropdown(array $items, array $parentItem): string
@@ -210,7 +215,7 @@ private function renderIcon(string $label, string $icon, array $iconOptions): st
/**
* Renders widget items.
*
- * @throws InvalidConfigException
+ * @throws InvalidConfigException|JsonException
*
* @return string
*/
@@ -234,9 +239,9 @@ private function renderItems(): string
*
* @param array $item the item to render.
*
- * @return string the rendering result.
+ * @throws InvalidConfigException|JsonException
*
- * @throws InvalidConfigException
+ * @return string the rendering result.
*/
private function renderItem(array $item): string
{
@@ -252,14 +257,11 @@ private function renderItem(array $item): string
$label = $item['label'];
}
- $icon = '';
$iconOptions = [];
- if (isset($item['icon'])) {
- $icon = $item['icon'];
- }
+ $icon = $item['icon'] ?? '';
- if (isset($item['iconOptions']) && is_array($item['iconOptions'])) {
+ if (array_key_exists('iconOptions', $item) && is_array($item['iconOptions'])) {
$iconOptions = $this->addOptions($iconOptions, 'icon');
}
@@ -290,6 +292,7 @@ private function renderItem(array $item): string
Html::addCssStyle($linkOptions, 'opacity:.65; pointer-events:none;');
}
+ /** @psalm-suppress ConflictingReferenceConstraint */
if ($this->activateItems && $active) {
Html::addCssClass($linkOptions, 'is-active');
}
diff --git a/src/NavBar.php b/src/NavBar.php
index 1ec3721..e219799 100644
--- a/src/NavBar.php
+++ b/src/NavBar.php
@@ -7,6 +7,8 @@
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Html\Html;
+use function strpos;
+
final class NavBar extends Widget
{
private string $brand = '';
@@ -57,7 +59,7 @@ protected function run(): string
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function brand(string $value): self
{
@@ -70,7 +72,7 @@ public function brand(string $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function brandLabel(string $value): self
{
@@ -83,7 +85,7 @@ public function brandLabel(string $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function brandImage(string $value): self
{
@@ -97,7 +99,7 @@ public function brandImage(string $value): self
*
* @param string $value
*
- * @return self
+ * @return $this
*/
public function brandUrl(string $value): self
{
@@ -110,7 +112,7 @@ public function brandUrl(string $value): self
*
* @param string $value.
*
- * @return self
+ * @return $this
*/
public function toggleIcon(string $value): self
{
@@ -123,7 +125,7 @@ public function toggleIcon(string $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -138,7 +140,7 @@ public function options(array $value): self
*
* @param array $value default value `navbar-item`.
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -153,7 +155,7 @@ public function brandOptions(array $value): self
*
* @param array $value default value `navbar-item`.
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -168,7 +170,7 @@ public function brandLabelOptions(array $value): self
*
* @param array $value default value `navbar-item`.
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -183,7 +185,7 @@ public function brandImageOptions(array $value): self
*
* @param array $value default value `navbar-start`.
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -198,7 +200,7 @@ public function itemsOptions(array $value): self
*
* @param array $value default value `navbar-menu`.
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
@@ -213,7 +215,7 @@ public function menuOptions(array $value): self
*
* @param array $value
*
- * @return self
+ * @return $this
*
* {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
*/
diff --git a/src/Widget.php b/src/Widget.php
index b875414..369ecfa 100644
--- a/src/Widget.php
+++ b/src/Widget.php
@@ -7,6 +7,8 @@
use Yiisoft\Html\Html;
use Yiisoft\Widget\Widget as BaseWidget;
+use function strpos;
+
abstract class Widget extends BaseWidget
{
private ?string $id = null;
@@ -92,6 +94,6 @@ protected function addOptions(array $options, string $valueDefault): array
Html::addCssClass($options, $optionsTmp);
}
- return $options;
+ return $options ?? [];
}
}
diff --git a/tests/DropdownTest.php b/tests/DropdownTest.php
index 2ed244d..8b121ec 100644
--- a/tests/DropdownTest.php
+++ b/tests/DropdownTest.php
@@ -4,7 +4,6 @@
namespace Yiisoft\Yii\Bulma\Tests;
-use Yiisoft\Widget\Exception\InvalidConfigException;
use Yiisoft\Yii\Bulma\Dropdown;
final class DropdownTest extends TestCase
@@ -198,6 +197,44 @@ public function testDropdownTriggerOptions(): void
Ekaterinburgo
+HTML;
+
+ $this->assertEqualsWithoutLE($expected, $html);
+ }
+
+ public function testDropdownWithIcon(): void
+ {
+ Dropdown::counter(0);
+
+ $html = Dropdown::widget()
+ ->buttonLabel('Russian cities')
+ ->items([
+ ['label' => 'San petesburgo', 'url' => '#', 'icon' => 'testIcon', 'iconOptions' => ['class' => 'icon']],
+ ['label' => 'Moscu', 'url' => '#'],
+ ['label' => 'Novosibirsk', 'url' => '#'],
+ '-',
+ ['label' => 'Ekaterinburgo', 'url' => '#', 'icon' => 'testIcon', 'iconOptions' => ['class' => 'icon']],
+ ])
+ ->render();
+
+ $expected = <<
+
+
+
+
+
HTML;
$this->assertEqualsWithoutLE($expected, $html);
diff --git a/tests/NavTest.php b/tests/NavTest.php
index cdd0636..c636cc4 100644
--- a/tests/NavTest.php
+++ b/tests/NavTest.php
@@ -5,7 +5,7 @@
namespace Yiisoft\Yii\Bulma\Tests;
use Yiisoft\Html\Html;
-use Yiisoft\Widget\Exception\InvalidConfigException;
+use Yiisoft\Factory\Exceptions\InvalidConfigException;
use Yiisoft\Yii\Bulma\Nav;
use Yiisoft\Yii\Bulma\NavBar;
@@ -412,7 +412,7 @@ public function testNavExceptionLabelItems(): void
$this->expectException(InvalidConfigException::class);
$this->expectExceptionMessage("The 'label' option is required.");
- $html = Nav::widget()
+ Nav::widget()
->encodeLabels(true)
->items([
[
@@ -465,7 +465,7 @@ public function testNavDropdownExceptionLabelItems(): void
$this->expectException(InvalidConfigException::class);
$this->expectExceptionMessage("The 'label' option is required.");
- $html = Nav::widget()
+ Nav::widget()
->encodeLabels(true)
->items([
[
diff --git a/tests/TestCase.php b/tests/TestCase.php
index ce4b2bc..aa7508a 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -4,13 +4,21 @@
namespace Yiisoft\Yii\Bulma\Tests;
+use Exception;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Psr\Container\ContainerInterface;
+use Psr\Log\LoggerInterface;
+use Psr\Log\NullLogger;
+use Yiisoft\Assets\AssetConverter;
+use Yiisoft\Assets\AssetConverterInterface;
use Yiisoft\Assets\AssetManager;
+use Yiisoft\Assets\AssetPublisher;
+use Yiisoft\Assets\AssetPublisherInterface;
use Yiisoft\Aliases\Aliases;
-use Yiisoft\Composer\Config\Builder;
-use Yiisoft\Files\FileHelper;
use Yiisoft\Di\Container;
+use Yiisoft\Factory\Definitions\Reference;
+use Yiisoft\Files\FileHelper;
+use Yiisoft\Widget\WidgetFactory;
abstract class TestCase extends BaseTestCase
{
@@ -22,10 +30,9 @@ protected function setUp(): void
{
parent::setUp();
- $this->container = new Container(
- require Builder::path('web'),
- require Builder::path('providers')
- );
+ $this->container = new Container($this->config());
+
+ WidgetFactory::initialize($this->container, []);
$this->aliases = $this->container->get(Aliases::class);
@@ -67,7 +74,7 @@ private function removeAssets(string $basePath): void
$handle = opendir($dir = $this->aliases->get($basePath));
if ($handle === false) {
- throw new \Exception("Unable to open directory: $dir");
+ throw new Exception("Unable to open directory: $dir");
}
while (($file = readdir($handle)) !== false) {
@@ -84,4 +91,39 @@ private function removeAssets(string $basePath): void
closedir($handle);
}
+
+ private function config(): array
+ {
+ return [
+ Aliases::class => [
+ '__class' => Aliases::class
+ ],
+
+ LoggerInterface::class => NullLogger::class,
+
+ AssetConverterInterface::class => [
+ '__class' => AssetConverter::class,
+ '__construct()' => [
+ Reference::to(Aliases::class),
+ Reference::to(LoggerInterface::class)
+ ]
+ ],
+
+ AssetPublisherInterface::class => [
+ '__class' => AssetPublisher::class,
+ '__construct()' => [
+ Reference::to(Aliases::class)
+ ]
+ ],
+
+ AssetManager::class => static function (ContainerInterface $container) {
+ $assetManager = new AssetManager($container->get(LoggerInterface::class));
+
+ $assetManager->setConverter($container->get(AssetConverterInterface::class));
+ $assetManager->setPublisher($container->get(AssetPublisherInterface::class));
+
+ return $assetManager;
+ }
+ ];
+ }
}