Skip to content

Commit

Permalink
Raise MSI to 100%, fix psalm errors, use yiisoft/test-support (#37)
Browse files Browse the repository at this point in the history
* Make Breadcrumbs::class final

* Update dependencies to composer.json

* Use yiisoft/test-support package to tests

* Fix psalm errors

* Raise MSI to 100%
  • Loading branch information
devanych committed Jul 17, 2021
1 parent 5123483 commit 07598c3
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 36 deletions.
12 changes: 6 additions & 6 deletions composer.json
Expand Up @@ -20,21 +20,21 @@
"prefer-stable": true,
"require": {
"php": "^7.4|^8.0",
"npm-asset/bulma": "^0.9.1",
"npm-asset/bulma": "^0.9.3",
"npm-asset/bulma-helpers": "^0.3.12",
"npm-asset/vizuaalog--bulmajs": "^0.11.0",
"oomphinc/composer-installers-extender": "^2.0.0",
"yiisoft/arrays": "@dev",
"yiisoft/arrays": "^1.0",
"yiisoft/assets": "^1.0",
"yiisoft/html": "^1.0",
"yiisoft/html": "^1.2",
"yiisoft/widget": "@dev"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"roave/infection-static-analysis-plugin": "^1.",
"roave/infection-static-analysis-plugin": "^1.8",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.3",
"yiisoft/di": "^3.0@dev"
"vimeo/psalm": "^4.8",
"yiisoft/test-support": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 0 additions & 4 deletions psalm.xml
Expand Up @@ -7,9 +7,5 @@
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="src/Asset" />
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
4 changes: 1 addition & 3 deletions src/Asset/BulmaAsset.php
Expand Up @@ -10,14 +10,12 @@ final class BulmaAsset extends AssetBundle
{
public ?string $basePath = '@assets';
public ?string $baseUrl = '@assetsUrl';
public ?string $sourcePath = '@npm/bulma/';
public ?string $sourcePath = '@npm/bulma';

/** @psalm-suppress NonInvariantDocblockPropertyType */
public array $css = [
'css/bulma.css',
];

/** @psalm-suppress NonInvariantDocblockPropertyType */
public array $publishOptions = [
'only' => [
'css/bulma.css',
Expand Down
2 changes: 0 additions & 2 deletions src/Asset/BulmaHelpersAsset.php
Expand Up @@ -12,12 +12,10 @@ final class BulmaHelpersAsset extends AssetBundle
public ?string $baseUrl = '@assetsUrl';
public ?string $sourcePath = '@npm/bulma-helpers/css';

/** @psalm-suppress NonInvariantDocblockPropertyType */
public array $css = [
'bulma-helpers.css',
];

/** @psalm-suppress NonInvariantDocblockPropertyType */
public array $publishOptions = [
'only' => [
'bulma-helpers.css',
Expand Down
2 changes: 0 additions & 2 deletions src/Asset/BulmaJsAsset.php
Expand Up @@ -12,12 +12,10 @@ final class BulmaJsAsset extends AssetBundle
public ?string $baseUrl = '@assetsUrl';
public ?string $sourcePath = '@npm/vizuaalog--bulmajs';

/** @psalm-suppress NonInvariantDocblockPropertyType */
public array $js = [
'dist/bulma.js',
];

/** @psalm-suppress NonInvariantDocblockPropertyType */
public array $publishOptions = [
'only' => [
'dist/bulma.js',
Expand Down
2 changes: 0 additions & 2 deletions src/Asset/FilePluginAsset.php
Expand Up @@ -12,12 +12,10 @@ final class FilePluginAsset extends AssetBundle
public ?string $baseUrl = '@assetsUrl';
public ?string $sourcePath = '@npm/vizuaalog--bulmajs';

/** @psalm-suppress NonInvariantDocblockPropertyType */
public array $js = [
'dist/file.js',
];

/** @psalm-suppress NonInvariantDocblockPropertyType */
public array $publishOptions = [
'only' => [
'dist/file.js',
Expand Down
2 changes: 1 addition & 1 deletion src/Breadcrumbs.php
Expand Up @@ -26,7 +26,7 @@
*
* @link https://bulma.io/documentation/components/breadcrumb/
*/
class Breadcrumbs extends Widget
final class Breadcrumbs extends Widget
{
private bool $encodeLabels = true;
private bool $encodeLinks = false;
Expand Down
6 changes: 2 additions & 4 deletions src/Menu.php
Expand Up @@ -86,7 +86,7 @@ public function activateParents(): self
/**
* The CSS class to be appended to the active menu item.
*
* @var string
* @param string $value
*
* @return self
*/
Expand Down Expand Up @@ -141,7 +141,7 @@ public function withoutEncodeLabels(): self
* The CSS class that will be assigned to the first item in the main menu or each submenu. Defaults to null,
* meaning no such CSS class will be assigned.
*
* @var string
* @param string $value
*
* @return self
*/
Expand All @@ -156,8 +156,6 @@ public function firstItemCssClass(string $value): self
* Whether to show empty menu items. An empty menu item is one whose `url` option is not set and which has no
* visible child menu items.
*
* @var bool
*
* @return self
*/
public function showEmptyItems(): self
Expand Down
4 changes: 0 additions & 4 deletions src/ModalCard.php
Expand Up @@ -209,8 +209,6 @@ public function toggleButtonColor(string $value): self
/**
* Disable toggle button.
*
* @param bool $value
*
* @return self
*/
public function withoutToggleButton(): self
Expand Down Expand Up @@ -261,8 +259,6 @@ public function closeButtonOptions(array $value): self
/**
* Disable close button.
*
* @param bool $value
*
* @return self
*/
public function withoutCloseButton(): self
Expand Down
2 changes: 1 addition & 1 deletion src/Panel.php
Expand Up @@ -114,7 +114,7 @@ public function headingOptions(array $value): self
/**
* Set progress bar color.
*
* @var string $value Color class.
* @param string $value Color class.
*
* @return self
*/
Expand Down
8 changes: 4 additions & 4 deletions src/ProgressBar.php
Expand Up @@ -76,7 +76,7 @@ public function options(array $value): self
/**
* Set the value of the progress.
*
* @var float $value The value of the progress. Set `0` to display loading animation.
* @param float $value The value of the progress. Set `0` to display loading animation.
*
* @return self
*/
Expand All @@ -91,7 +91,7 @@ public function value(float $value): self
/**
* Set maximum progress value.
*
* @var int $value Maximum progress value. Set `0` for no maximum.
* @param int $value Maximum progress value. Set `0` for no maximum.
*
* @return self
*/
Expand Down Expand Up @@ -126,7 +126,7 @@ public function size(string $value): self
/**
* Set progress bar color.
*
* @var string $value Color class.
* @param string $value Color class.
*
* @return self
*/
Expand All @@ -151,7 +151,7 @@ private function buildOptions(): void

$this->options = $this->addOptions($this->options, 'progress');

if ($this->maxValue !== 0) {
if ($this->maxValue > 0) {
$this->options['max'] = $this->maxValue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Widget.php
Expand Up @@ -83,6 +83,7 @@ protected function addOptions(array $options, string $defaultClass): array
$class = '';

if (isset($options['class'])) {
/** @var string|string[] $class */
$class = $options['class'];
unset($options['class']);

Expand All @@ -91,7 +92,6 @@ protected function addOptions(array $options, string $defaultClass): array
}
}

/** @psalm-var string $class */
if (strpos($class, $defaultClass) === false) {
Html::addCssClass($options, $defaultClass);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/BreadcrumbsTest.php
Expand Up @@ -284,4 +284,19 @@ public function testBreadcrumbsWithoutHomeItem(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}

public function testImmutability(): void
{
$widget = Breadcrumbs::widget();

$this->assertNotSame($widget, $widget->homeItem([]));
$this->assertNotSame($widget, $widget->withoutHomeItem());
$this->assertNotSame($widget, $widget->itemTemplate(''));
$this->assertNotSame($widget, $widget->activeItemTemplate(''));
$this->assertNotSame($widget, $widget->items([]));
$this->assertNotSame($widget, $widget->options([]));
$this->assertNotSame($widget, $widget->itemsOptions([]));
$this->assertNotSame($widget, $widget->id(Breadcrumbs::class));
$this->assertNotSame($widget, $widget->autoIdPrefix(Breadcrumbs::class));
}
}
20 changes: 20 additions & 0 deletions tests/DropdownTest.php
Expand Up @@ -259,4 +259,24 @@ public function testEncodeLabels(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}

public function testImmutability(): void
{
$widget = Dropdown::widget();

$this->assertNotSame($widget, $widget->buttonLabel(''));
$this->assertNotSame($widget, $widget->buttonLabelOptions([]));
$this->assertNotSame($widget, $widget->dividerClass(''));
$this->assertNotSame($widget, $widget->itemClass(''));
$this->assertNotSame($widget, $widget->itemsClass(''));
$this->assertNotSame($widget, $widget->withoutEncodeLabels());
$this->assertNotSame($widget, $widget->withoutEncloseByContainer());
$this->assertNotSame($widget, $widget->items([]));
$this->assertNotSame($widget, $widget->options([]));
$this->assertNotSame($widget, $widget->buttonOptions([]));
$this->assertNotSame($widget, $widget->itemsOptions([]));
$this->assertNotSame($widget, $widget->triggerOptions([]));
$this->assertNotSame($widget, $widget->id(Dropdown::class));
$this->assertNotSame($widget, $widget->autoIdPrefix(Dropdown::class));
}
}
23 changes: 23 additions & 0 deletions tests/MenuTest.php
Expand Up @@ -873,4 +873,27 @@ public function testMenuSubMenuTemplate(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}

public function testImmutability(): void
{
$widget = Menu::widget();

$this->assertNotSame($widget, $widget->withoutActivateItems());
$this->assertNotSame($widget, $widget->activateParents());
$this->assertNotSame($widget, $widget->activeCssClass(''));
$this->assertNotSame($widget, $widget->brand(''));
$this->assertNotSame($widget, $widget->currentPath(''));
$this->assertNotSame($widget, $widget->withoutEncodeLabels());
$this->assertNotSame($widget, $widget->firstItemCssClass(''));
$this->assertNotSame($widget, $widget->showEmptyItems());
$this->assertNotSame($widget, $widget->items([]));
$this->assertNotSame($widget, $widget->itemOptions([]));
$this->assertNotSame($widget, $widget->labelTemplate(''));
$this->assertNotSame($widget, $widget->lastItemCssClass(''));
$this->assertNotSame($widget, $widget->linkTemplate(''));
$this->assertNotSame($widget, $widget->options([]));
$this->assertNotSame($widget, $widget->subMenuTemplate(''));
$this->assertNotSame($widget, $widget->id(Menu::class));
$this->assertNotSame($widget, $widget->autoIdPrefix(Menu::class));
}
}
18 changes: 18 additions & 0 deletions tests/MessageTest.php
Expand Up @@ -253,4 +253,22 @@ public function testMessageWithoutHeader(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}

public function testImmutability(): void
{
$widget = Message::widget();

$this->assertNotSame($widget, $widget->body(''));
$this->assertNotSame($widget, $widget->headerColor(''));
$this->assertNotSame($widget, $widget->headerMessage(''));
$this->assertNotSame($widget, $widget->options([]));
$this->assertNotSame($widget, $widget->bodyOptions([]));
$this->assertNotSame($widget, $widget->closeButtonOptions([]));
$this->assertNotSame($widget, $widget->headerOptions([]));
$this->assertNotSame($widget, $widget->size(''));
$this->assertNotSame($widget, $widget->closeButton());
$this->assertNotSame($widget, $widget->withoutHeader());
$this->assertNotSame($widget, $widget->id(Message::class));
$this->assertNotSame($widget, $widget->autoIdPrefix(Message::class));
}
}
24 changes: 24 additions & 0 deletions tests/ModalCardTest.php
Expand Up @@ -436,4 +436,28 @@ public function testModalCardOptions(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}

public function testImmutability(): void
{
$widget = ModalCard::widget();

$this->assertNotSame($widget, $widget->options([]));
$this->assertNotSame($widget, $widget->contentOptions([]));
$this->assertNotSame($widget, $widget->toggleButtonLabel(''));
$this->assertNotSame($widget, $widget->toggleButtonOptions([]));
$this->assertNotSame($widget, $widget->toggleButtonSize('is-small'));
$this->assertNotSame($widget, $widget->toggleButtonColor('is-primary'));
$this->assertNotSame($widget, $widget->withoutToggleButton());
$this->assertNotSame($widget, $widget->closeButtonSize('is-small'));
$this->assertNotSame($widget, $widget->closeButtonOptions([]));
$this->assertNotSame($widget, $widget->withoutCloseButton());
$this->assertNotSame($widget, $widget->headerOptions([]));
$this->assertNotSame($widget, $widget->bodyOptions([]));
$this->assertNotSame($widget, $widget->footerOptions([]));
$this->assertNotSame($widget, $widget->footer(''));
$this->assertNotSame($widget, $widget->titleOptions([]));
$this->assertNotSame($widget, $widget->title(''));
$this->assertNotSame($widget, $widget->id(ModalCard::class));
$this->assertNotSame($widget, $widget->autoIdPrefix(ModalCard::class));
}
}
18 changes: 18 additions & 0 deletions tests/ModalTest.php
Expand Up @@ -230,4 +230,22 @@ public function testToggleButtonOptions(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}

public function testImmutability(): void
{
$widget = Modal::widget();

$this->assertNotSame($widget, $widget->options([]));
$this->assertNotSame($widget, $widget->toggleButtonLabel(''));
$this->assertNotSame($widget, $widget->toggleButtonOptions([]));
$this->assertNotSame($widget, $widget->toggleButtonSize('is-small'));
$this->assertNotSame($widget, $widget->toggleButtonColor('is-primary'));
$this->assertNotSame($widget, $widget->withoutToggleButton());
$this->assertNotSame($widget, $widget->closeButtonSize('is-small'));
$this->assertNotSame($widget, $widget->closeButtonOptions([]));
$this->assertNotSame($widget, $widget->withoutCloseButton());
$this->assertNotSame($widget, $widget->contentOptions([]));
$this->assertNotSame($widget, $widget->id(Modal::class));
$this->assertNotSame($widget, $widget->autoIdPrefix(Modal::class));
}
}
20 changes: 20 additions & 0 deletions tests/NavBarTest.php
Expand Up @@ -418,4 +418,24 @@ public function testNavBarItemsOptionsClassArray(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}

public function testImmutability(): void
{
$widget = NavBar::widget();

$this->assertNotSame($widget, $widget->brand(''));
$this->assertNotSame($widget, $widget->brandLabel(''));
$this->assertNotSame($widget, $widget->brandImage(''));
$this->assertNotSame($widget, $widget->brandUrl(''));
$this->assertNotSame($widget, $widget->toggleIcon(''));
$this->assertNotSame($widget, $widget->options([]));
$this->assertNotSame($widget, $widget->brandOptions([]));
$this->assertNotSame($widget, $widget->brandLabelOptions([]));
$this->assertNotSame($widget, $widget->brandImageOptions([]));
$this->assertNotSame($widget, $widget->itemsOptions([]));
$this->assertNotSame($widget, $widget->menuOptions([]));
$this->assertNotSame($widget, $widget->toggleOptions([]));
$this->assertNotSame($widget, $widget->id(NavBar::class));
$this->assertNotSame($widget, $widget->autoIdPrefix(NavBar::class));
}
}
13 changes: 13 additions & 0 deletions tests/NavTest.php
Expand Up @@ -516,4 +516,17 @@ public function testNavIcon(): void
HTML;
$this->assertEqualsWithoutLE($expected, $html);
}

public function testImmutability(): void
{
$widget = Nav::widget();

$this->assertNotSame($widget, $widget->withoutActivateItems());
$this->assertNotSame($widget, $widget->activateParents());
$this->assertNotSame($widget, $widget->currentPath(''));
$this->assertNotSame($widget, $widget->withoutEncodeLabels());
$this->assertNotSame($widget, $widget->items([]));
$this->assertNotSame($widget, $widget->id(Nav::class));
$this->assertNotSame($widget, $widget->autoIdPrefix(Nav::class));
}
}

0 comments on commit 07598c3

Please sign in to comment.