Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
AxiosLeo committed Jul 18, 2020
1 parent 4425fd5 commit d6d52ac
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 3 deletions.
21 changes: 18 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,27 @@
"issues": "https://github.com/AxiosCros/php-tools/issues"
},
"require": {
"php": ">=7.2",
"symfony/var-dumper": "*"
"php": ">=7.2"
},
"require-dev": {
"symfony/var-dumper": "*",
"phpunit/phpunit": "^8.5"
},
"autoload": {
"psr-4": {
"axios\\tools\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"axios\\tools\\tests\\": "tests"
}
},
"scripts": {
"test": [
"@clearCache",
"./vendor/bin/phpunit --colors=always"
],
"clearCache": "rm -rf cache/*"
}
}
}
32 changes: 32 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/bootstrap.php" colors="true" processIsolation="false" stopOnFailure="false"
convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true"
testSuiteLoaderFile="phpunit/src/Runner/StandardTestSuiteLoader.php">

<testsuites>
<testsuite name="All">
<directory>tests</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/unit</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>integration</group>
</exclude>
</groups>

<logging>
<log type="coverage-html" target="cache/coverage" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="cache/coverage.clover"/>
</logging>


<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
5 changes: 5 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
89 changes: 89 additions & 0 deletions tests/unit/ListTreeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace axios\tools\tests\unit;

use axios\tools\ListToTree;
use axios\tools\TreeToList;
use PHPUnit\Framework\TestCase;

/**
* @internal
* @coversNothing
*/
class ListTreeTest extends TestCase
{
public function testListToTree()
{
$data = [
['id' => 1, 'parent_id' => 0],
['id' => 2, 'parent_id' => 3],
['id' => 3, 'parent_id' => 1],
['id' => 4, 'parent_id' => 2],
['id' => 5, 'parent_id' => 6],
['id' => 6, 'parent_id' => 7],
['id' => 7, 'parent_id' => 5],
];
$ListToTree = new ListToTree($data);
$this->assertEquals([
[
'id' => 1,
'parent_id' => 0,
'child' => [
0 => [
'id' => 3,
'parent_id' => 1,
'child' => [
0 => [
'id' => 2,
'parent_id' => 3,
'child' => [
0 => [
'id' => 4,
'parent_id' => 2,
],
],
],
],
],
],
],
], $ListToTree->toTree());
}

public function testTreeToList()
{
$data = [
[
'id' => 1,
'parent_id' => 0,
'child' => [
0 => [
'id' => 3,
'parent_id' => 1,
'child' => [
0 => [
'id' => 2,
'parent_id' => 3,
'child' => [
0 => [
'id' => 4,
'parent_id' => 2,
],
],
],
],
],
],
],
];
$TreeToList = new TreeToList($data);
$this->assertEquals([
['id' => 1, 'parent_id' => 0],
['id' => 2, 'parent_id' => 1],
['id' => 3, 'parent_id' => 2],
['id' => 4, 'parent_id' => 3],
], $TreeToList->toList());
}
}

0 comments on commit d6d52ac

Please sign in to comment.