Skip to content

Commit c862ef0

Browse files
committed
Add PHPUnit for testing
1 parent fe899f3 commit c862ef0

7 files changed

+97
-10
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ Get Report as JSON
115115
```
116116
- It returns the report as JSON
117117

118+
## Testing
119+
120+
```bash
121+
$ ./vendor/bin/phpunit --testdox --coverage-text --coverage-clover=coverage.clover
122+
```
123+
118124
## Contributing
119125

120126
----

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.1.4 (19-07-2022)
2+
- Add PHPUnit for testing
3+
- Move DecomposerAsset to root folder
4+
-----
15
## v0.1.3 (17-07-2022)
26
- Update README.md
37
-----

composer.json

+19-10
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,40 @@
22
"name": "thangnm93/yii2-decomposer",
33
"description": "A Yii2 package to decompose your installed packages, their dependencies, your app & server environment",
44
"license": "MIT",
5-
"type" : "yii2-extension",
6-
"keywords" : [
5+
"type": "yii2-extension",
6+
"keywords": [
77
"yii2",
88
"thangnm93",
99
"decomposer",
1010
"yii2 decomposer"
1111
],
12-
"homepage" : "https://github.com/thangnm93/yii2-decomposer",
13-
"support" : {
14-
"source" : "https://github.com/thangnm93/yii2-decomposer"
12+
"homepage": "https://github.com/thangnm93/yii2-decomposer",
13+
"support": {
14+
"issues": "https://github.com/thangnm93/yii2-decomposer/issues",
15+
"source": "https://github.com/thangnm93/yii2-decomposer"
1516
},
1617
"authors": [
1718
{
1819
"name": "Thang Nguyen",
1920
"email": "contact@thangnm.info"
2021
}
2122
],
22-
"autoload": {
23-
"psr-4": {
24-
"thangnm93\\decomposer\\": "src/"
25-
}
26-
},
2723
"require": {
2824
"php": ">=7.2",
2925
"ext-json": "*",
3026
"yiisoft/yii2": ">=2.0.13"
27+
},
28+
"require-dev": {
29+
"phpunit/phpunit": "<7",
30+
"yiisoft/yii2-dev": ">=2.0.13"
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
"thangnm93\\decomposer\\": "src/",
35+
"thangnm93\\decomposer\\tests\\": "tests/"
36+
}
37+
},
38+
"config": {
39+
"optimize-autoloader": true
3140
}
3241
}

phpunit.xml.dist

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<phpunit bootstrap="./tests/bootstrap.php"
3+
colors="true"
4+
convertErrorsToExceptions="true"
5+
convertNoticesToExceptions="true"
6+
convertWarningsToExceptions="true"
7+
stopOnFailure="false">
8+
<testsuites>
9+
<testsuite name="Test Suite">
10+
<directory>./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist processUncoveredFilesFromWhitelist="true">
15+
<directory suffix="Test.php">src/</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

tests/TestCase.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
namespace thangnm93\decomposer\tests;
3+
4+
use yii\helpers\ArrayHelper;
5+
use Yii;
6+
7+
abstract class TestCase extends \PHPUnit\Framework\TestCase
8+
{
9+
/**
10+
* Populates Yii::$app with a new application
11+
* The application will be destroyed on tearDown() automatically.
12+
* @param array $config The application configuration, if needed
13+
* @param string $appClass name of the application class to create
14+
*/
15+
protected function mockApplication($config = [], $appClass = '\yii\console\Application')
16+
{
17+
new $appClass(ArrayHelper::merge([
18+
'id' => 'testapp',
19+
'basePath' => __DIR__,
20+
'vendorPath' => dirname(__DIR__) . '/vendor',
21+
], $config));
22+
}
23+
24+
/**
25+
* Destroys application in Yii::$app by setting it to null.
26+
*/
27+
protected function destroyApplication()
28+
{
29+
Yii::$app = null;
30+
}
31+
}

tests/bootstrap.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
error_reporting(-1);
3+
4+
const YII_DEBUG = true;
5+
$_SERVER['SCRIPT_NAME'] = '/' . __DIR__;
6+
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
7+
8+
require(__DIR__ . '/../vendor/autoload.php');
9+
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace thangnm93\decomposer\tests;
3+
4+
class DecomposerHelperTest extends TestCase
5+
{
6+
public function testDemo()
7+
{
8+
$this->assertTrue(true);
9+
}
10+
}

0 commit comments

Comments
 (0)