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

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

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;
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', [
0 ignored issues
show
Documentation Bug introduced by
It seems like \AspectMock\Test::double...\Psr\Log\NullLogger())) can also be of type object<AspectMock\Proxy\InstanceProxy>. However, the property $apigen is declared as type object<AspectMock\Proxy\ClassProxy>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
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