Completed
Push — master ( d3a073...5737c8 )
by Greg
02:21
created

tests/unit/Task/ApiGenTest.php (1 issue)

Check for conflicting imported classes with local classes

Bug Major

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
use AspectMock\Test as test;
0 ignored issues
show
This use statement conflicts with another class in this namespace, test.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
3
use Robo\Robo;
4
5
class ApiGenTest extends \Codeception\TestCase\Test
6
{
7
    protected $container;
8
9
    /**
10
     * @var \AspectMock\Proxy\ClassProxy
11
     */
12
    protected $apigen;
13
14
    protected function _before()
15
    {
16
        $this->apigen = test::double('Robo\Task\ApiGen\ApiGen', [
17
            'executeCommand' => null,
18
            'output' => new \Symfony\Component\Console\Output\NullOutput(),
19
            'logger' => new \Psr\Log\NullLogger(),
20
        ]);
21
22
        $this->container = Robo::getContainer();
23
    }
24
25
    // tests
26
    public function testPHPUnitCommand()
27
    {
28
        // need an explicit Traversable
29
        $skippedPaths = new \SplDoublyLinkedList();
30
        $skippedPaths->push('a');
31
        $skippedPaths->push('b');
32
33
        // going for 'bang for the buck' here re: test converage
34
        $task = (new \Robo\Task\ApiGen\ApiGen('apigen'))
35
            ->config('./apigen.neon')
36
            ->source('src') // single string value of Traversable
37
            ->extensions('php') // single string value of List
38
            ->exclude(array('test', 'tmp')) // array value of Traversable
39
            ->skipDocPath($skippedPaths) // multi-value of Traversable
40
            ->charset(array('utf8','iso88591')) // array of List
41
            ->internal('no') // boolean as supported "no"
42
            ->php(true) // boolean as boolean
43
            ->tree('Y') // boolean as string
44
            ->debug('n');
45
46
        $linuxCmd = 'apigen generate --config ./apigen.neon --source src --extensions php --exclude test --exclude tmp --skip-doc-path a --skip-doc-path b --charset \'utf8,iso88591\' --internal no --php yes --tree yes --debug no';
47
48
        $winCmd = 'apigen generate --config ./apigen.neon --source src --extensions php --exclude test --exclude tmp --skip-doc-path a --skip-doc-path b --charset "utf8,iso88591" --internal no --php yes --tree yes --debug no';
49
50
        $cmd = stripos(PHP_OS, 'WIN') === 0 ? $winCmd : $linuxCmd;
51
52
        verify($task->getCommand())->equals($cmd);
53
54
        $task->run();
55
        $this->apigen->verifyInvoked('executeCommand', [$cmd]);
56
    }
57
}
58