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

tests/unit/Common/ResourceExistenceChecker.php (2 issues)

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 Robo\Common\ResourceExistenceChecker;
3
4
class ResourceExistenceCheckerTest extends \Codeception\TestCase\Test
5
{
6
    use ResourceExistenceChecker;
7
8
    protected $testDir = null;
9
10
    protected $testFile = null;
11
12
    protected function _before()
13
    {
14
        $this->apigen = test::double('Robo\Task\ApiGen\ApiGen', [
0 ignored issues
show
The property apigen does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
The method double() does not seem to exist on object<Test>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
15
            'executeCommand' => null,
16
            'output' => new \Symfony\Component\Console\Output\NullOutput()
17
        ]);
18
        if (!defined('DS')) {
19
            define('DS', DIRECTORY_SEPARATOR);
20
        }
21
        $this->testDir = __DIR__ . '..' . DS . '..' . DS . 'data' . DS;
22
        $this->testFile = $this->testDir . 'dump.sql';
23
    }
24
25
    /**
26
     * testCheckResources
27
     */
28
    public function testCheckResources()
29
    {
30
        $this->assertTrue($this->checkResources($this->testDir, 'dir'));
31
        $this->assertTrue($this->checkResources([
32
            $this->testDir,
33
            $this->testFile
34
        ]));
35
    }
36
37
    /**
38
     * @expectException \InvalidArgumentException
39
     */
40
    public function testCheckResourcesException()
41
    {
42
        $this->checkResources('does not exist', 'invalid type');
43
    }
44
45
    /**
46
     * testCheckResource
47
     */
48
    public function testCheckResource()
49
    {
50
        $this->assertTrue($this->checkResource($this->testDir, 'dir'));
51
        $this->assertTrue($this->checkResource($this->testDir, 'fileAndDir'));
52
        $this->assertTrue($this->checkResource($this->testFile, 'file'));
53
        $this->assertTrue($this->checkResource($this->testFile, 'fileAndDir'));
54
55
        $this->assertFalse($this->checkResource('does-not-exist', 'dir'));
56
        $this->assertFalse($this->checkResource('does-not-exist', 'fileAndDir'));
57
        $this->assertFalse($this->checkResource('does-not-exist', 'file'));
58
        $this->assertFalse($this->checkResource('does-not-exist', 'fileAndDir'));
59
    }
60
61
    /**
62
     * testIsDir
63
     */
64
    public function testIsDir()
65
    {
66
        $this->assertTrue($this->isDir($this->testDir));
67
        $this->assertFalse($this->isDir('does-not-exist'));
68
    }
69
70
    /**
71
     * testIsFile
72
     */
73
    public function testIsFile()
74
    {
75
        $this->assertTrue($this->isFile($this->testFile));
76
        $this->assertFalse($this->isFile($this->testDir . 'does-not-exist'));
77
    }
78
}
79