Skip to content

Commit

Permalink
Add mutation tests, raise phpstan 7.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Nov 18, 2023
1 parent 97f3ddc commit 7169fad
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 38 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'psalm.xml'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'psalm.xml'

name: mutation test

jobs:
mutation:
uses: php-forge/actions/.github/workflows/roave-infection.yml@main
secrets:
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
with:
os: >-
['ubuntu-latest']
php: >-
['8.1']
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<a href="https://github.com/yii2-extensions/bootbox" target="_blank">
<a href="https://github.com/yii2-extensions/asset-bootbox" target="_blank">
<img src="https://www.yiiframework.com/image/yii_logo_light.svg" height="100px;">
</a>
<h1 align="center">Asset for Bootbox.</h1>
Expand All @@ -13,23 +13,28 @@
<a href="https://github.com/yiisoft/yii2/tree/2.2" target="_blank">
<img src="https://img.shields.io/badge/Yii2%20version-2.2-blue" alt="yii2-version">
</a>
<a href="https://github.com/yii2-extensions/bootbox/actions/workflows/build.yml" target="_blank">
<img src="https://github.com/yii2-extensions/bootbox/actions/workflows/build.yml/badge.svg" alt="PHPUnit">
<a href="https://github.com/yii2-extensions/asset-bootbox/actions/workflows/build.yml" target="_blank">
<img src="https://github.com/yii2-extensions/asset-bootbox/actions/workflows/build.yml/badge.svg" alt="PHPUnit">
</a>
<a href="https://codecov.io/gh/yii2-extensions/bootbox" target="_blank">
<img src="https://codecov.io/gh/yii2-extensions/bootbox/branch/main/graph/badge.svg?token=MF0XUGVLYC" alt="Codecov">
<a href="https://codecov.io/gh/yii2-extensions/asset-bootbox" target="_blank">
<img src="https://codecov.io/gh/yii2-extensions/asset-bootbox/branch/main/graph/badge.svg?token=MF0XUGVLYC" alt="Codecov">
</a>
<a href="https://github.com/yii2-extensions/bootbox/actions/workflows/static.yml" target="_blank">
<img src="https://github.com/yii2-extensions/bootbox/actions/workflows/static.yml/badge.svg" alt="PHPStan">
<a href="https://dashboard.stryker-mutator.io/reports/github.com/yii2-extensions/asset-bootbox/main" target="_blank">
<img src="https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyii2-extensions%2Fasset-bootbox%2Fmain" alt="Infection">
</a>
<a href="https://github.com/yii2-extensions/asset-bootbox/actions/workflows/static.yml" target="_blank">
<img src="https://github.com/yii2-extensions/asset-bootbox/actions/workflows/static.yml/badge.svg" alt="PHPStan">
</a>
<a href="https://github.com/yii2-extensions/bootbox/actions/workflows/static.yml" target="_blank">
<img src="https://img.shields.io/badge/PHPStan%20level-5-blue" alt="PHPStan level">
<a href="https://github.com/yii2-extensions/asset-bootbox/actions/workflows/static.yml" target="_blank">
<img src="https://img.shields.io/badge/PHPStan%20level-7-blue" alt="PHPStan level">
</a>
<a href="https://github.styleci.io/repos/193722479?branch=main" target="_blank">
<img src="https://github.styleci.io/repos/193722479/shield?branch=main" alt="Code style">
</a>
</p>

![asset-bootbox](docs/images/bootbox.png)

## Installation

The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
Expand Down
11 changes: 10 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
},
"require-dev": {
"maglnet/composer-require-checker": "^4.6",
"php-forge/support": "dev-main",
"phpunit/phpunit": "^10.2",
"roave/infection-static-analysis-plugin": "^1.32",
"yii2-extensions/phpstan": "dev-main"
},
"autoload": {
Expand All @@ -35,7 +37,8 @@
"allow-plugins": {
"composer/installers": true,
"yiisoft/yii2-composer": true,
"oomphinc/composer-installers-extender": true
"oomphinc/composer-installers-extender": true,
"infection/extension-installer": true
}
},
"extra": {
Expand All @@ -53,6 +56,12 @@
]
}
},
"scripts": {
"check-dependencies": "composer-require-checker",
"mutation": "roave-infection-static-analysis-plugin",
"phpstan": "phpstan",
"test": "phpunit"
},
"repositories": [
{
"type": "composer",
Expand Down
Binary file added docs/images/bootbox.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Testing

## Checking dependencies

This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`.

To run the checker, execute the following command:

```shell
composer run check-dependencies
```

## Static analysis

The code is statically analyzed with [Phpstan](https://phpstan.org/). To run static analysis:

```shell
composer run phpstan
```

## Unit tests

The code is tested with [PHPUnit](https://phpunit.de/). To run tests:

```
composer run test
```
16 changes: 16 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "php:\/\/stderr",
"stryker": {
"report": "main"
}
},
"mutators": {
"@default": true
}
}
11 changes: 11 additions & 0 deletions infection.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "vendor/infection/infection/resources/schema.json",
"source": {
"directories": [
"src"
]
},
"mutators": {
"@default": true
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parameters:
dynamicConstantNames:
- YII_ENV

level: 5
level: 7

paths:
- src
Expand Down
20 changes: 20 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
</issueHandlers>
</psalm>
2 changes: 2 additions & 0 deletions src/BootboxAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ final class BootboxAsset extends AssetBundle

/**
* @inheritDoc
*
* @phpstan-var array<array-key, mixed>
*/
public $depends = [
BootboxConfirmAsset::class,
Expand Down
2 changes: 2 additions & 0 deletions src/BootboxConfirmAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ final class BootboxConfirmAsset extends AssetBundle

/**
* @inheritDoc
*
* @phpstan-var array<array-key, mixed>
*/
public $depends = [
BootstrapAsset::class,
Expand Down
32 changes: 5 additions & 27 deletions tests/BootboxTest.php → tests/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use yii\web\View;
use yii\web\YiiAsset;

final class BootboxTest extends TestCase
final class AssetTest extends TestCase
{
public function testBootboxSimpleDependency(): void
{
Expand All @@ -34,16 +34,6 @@ public function testBootboxSimpleDependency(): void
$this->assertInstanceOf(AssetBundle::class, $view->assetBundles[JqueryAsset::class]);
$this->assertInstanceOf(AssetBundle::class, $view->assetBundles[YiiAsset::class]);
}

public function testBootboxSourcesPublish(): void
{
$view = new View();
$bundle = BootboxAsset::register($view);

$this->assertDirectoryExists($bundle->basePath);
$this->sourcesPublishVerifyFiles('js', $bundle);
}

public function testBootboxRegister(): void
{
$view = new View();
Expand All @@ -62,21 +52,9 @@ public function testBootboxRegister(): void

$result = $view->renderFile(__DIR__ . '/support/main.php');

$this->assertMatchesRegularExpression('/jquery.js/', $result);
$this->assertMatchesRegularExpression('/yii.js/', $result);
$this->assertMatchesRegularExpression('/bootbox-confirm.js/', $result);
$this->assertMatchesRegularExpression('/bootbox.js/', $result);
}

private function sourcesPublishVerifyFiles(string $type, object $bundle): void
{
foreach ($bundle->$type as $filename) {
$publishedFile = $bundle->basePath . DIRECTORY_SEPARATOR . $filename;
$sourceFile = $bundle->sourcePath . DIRECTORY_SEPARATOR . $filename;
$this->assertFileExists($publishedFile);
$this->assertFileEquals($publishedFile, $sourceFile);
}

$this->assertDirectoryExists($bundle->basePath);
$this->assertStringContainsString('jquery.js', $result);
$this->assertStringContainsString('yii.js', $result);
$this->assertStringContainsString('bootbox-confirm.js', $result);
$this->assertStringContainsString('bootbox.js', $result);
}
}
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yii2\Asset\Tests;

use PHPForge\Support\Assert;
use Yii;
use yii\di\Container;
use yii\web\Application;
Expand Down Expand Up @@ -58,5 +59,6 @@ protected function tearDown(): void
{
parent::tearDown();
$this->destroyApplication();
Assert::removeFilesFromDirectory(__DIR__ . '/runtime');
}
}

0 comments on commit 7169fad

Please sign in to comment.