bulton-fr / dependency-tree

Lib for generate a dependency tree
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Sub-tree with null value #5

Closed bulton-fr closed 6 years ago

bulton-fr commented 6 years ago

I load two modules. One have a priority to 1. The other a priority of 0 but require the first module. So the second module take the priority 1 and will be after the first module in the tree.

But, in the main tree, the key "0" (for dependency with a priority to 0) stay and have a value to null. So it's not an array and the system can't loop and sort.

Example with unit test of https://github.com/bulton-fr/bfw

$this->assert('test Modules::generateTree with some modules')
    ->given($mock = $this->mock)
    ->and($mock::setModuleLoadInfos(
        'atoum',
        (object) [
            'priority' => 1
        ]
    ))
    ->and($mock::setModuleLoadInfos(
        'hello-world',
        (object) [
            'require'  => 'atoum',
            'priority' => 0
            //So hello-world is more priority than atoum.
            //But we required atoum, so we will have a priority >= 1, not at 0.
        ]
    ))
    ->and($this->mock->addModule('hello-world'))
    ->and($this->mock->addModule('atoum'))
    ->variable($this->mock->generateTree())
        ->isNull()
    ->array($tree = $this->mock->getLoadTree())
        ->isNotEmpty()
    ->given(var_dump($tree))
==> Error E_WARNING in /opt/Projects-dev/bfw-v3/test/unit/src/class/Modules.php on line 152, generated by file /opt/Projects-dev/bfw-v3/vendor/bulton-fr/dependency-tree/src/Tree.php on line 101 in case 'test Modules::generateTree with some modules':
Invalid argument supplied for foreach()
==> Error E_WARNING in /opt/Projects-dev/bfw-v3/test/unit/src/class/Modules.php on line 152, generated by file /opt/Projects-dev/bfw-v3/vendor/bulton-fr/dependency-tree/src/Tree.php on line 108 in case 'test Modules::generateTree with some modules':
ksort() expects parameter 1 to be array, null given
/opt/Projects-dev/bfw-v3/test/unit/src/class/Modules.php:156:
array(2) {
  [0] => NULL
  [1] => array(2) {
    [0] => array(1) {
      [0] => string(5) "atoum"
    }
    [1] => array(1) {
      [0] => string(11) "hello-world"
    }
  }
}
bulton-fr commented 6 years ago

Fixed on 1.0.2 release. The patch had already be done on the 1.0 branch :)