Completed
Push — master ( 0e2bb1...d48330 )
by WEBEWEB
02:01
created

SkeletonHelperTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2019 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\Tests\Helper;
13
14
use Exception;
15
use InvalidArgumentException;
16
use Symfony\Component\Filesystem\Filesystem;
17
use WBW\Bundle\CoreBundle\Helper\SkeletonHelper;
18
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase;
19
20
/**
21
 * Skeleton helper test.
22
 *
23
 * @author webeweb <https://github.com/webeweb/>
24
 * @package WBW\Bundle\CoreBundle\Tests\Helper
25
 */
26
class SkeletonHelperTest extends AbstractTestCase {
27
28
    /**
29
     * Directory "illegal".
30
     *
31
     * @var string
32
     */
33
    private $directoryIllegal;
34
35
    /**
36
     * Directory "resources".
37
     *
38
     * @var string
39
     */
40
    private $directoryResources;
41
42
    /**
43
     * Directory "skeleton".
44
     *
45
     * @var string
46
     */
47
    private $directorySkeleton;
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    protected function setUp(): void {
53
        parent::setUp();
54
55
        // Set the directories.
56
        $this->directoryIllegal   = getcwd() . "/composer.json";
57
        $this->directoryResources = getcwd() . "/Tests/Fixtures/app/Resources";
58
        $this->directorySkeleton  = getcwd() . "/Resources/views";
59
60
        (new Filesystem())->remove($this->directoryResources);
61
    }
62
63
    /**
64
     * Tests the copySkeleton() method.
65
     *
66
     * @return void
67
     */
68
    public function testCopySkeleton(): void {
69
70
        $res = SkeletonHelper::copySkeleton($this->directorySkeleton, $this->directoryResources);
71
        $this->assertCount(8, $res);
0 ignored issues
show
Documentation introduced by
$res is of type array<integer,boolean>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72
73
        foreach ($res as $current) {
74
            $this->assertTrue($current);
75
        }
76
    }
77
78
    /**
79
     * Tests the listSkeleton() method.
80
     *
81
     * @return void
82
     * @throws Exception Throws an exception if an error occurs.
83
     */
84
    public function testListSkeleton(): void {
85
86
        $res = SkeletonHelper::listSkeleton($this->directorySkeleton);
87
        $this->assertCount(8, $res);
0 ignored issues
show
Documentation introduced by
$res is of type array<integer,string>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
88
89
        $this->assertEquals($this->directorySkeleton . "/email/content.html.twig", $res[0]);
90
        $this->assertEquals($this->directorySkeleton . "/email/footer.html.twig", $res[1]);
91
        $this->assertEquals($this->directorySkeleton . "/email/header.html.twig", $res[2]);
92
        $this->assertEquals($this->directorySkeleton . "/email/layout.html.twig", $res[3]);
93
        $this->assertEquals($this->directorySkeleton . "/email/stylesheet.html.twig", $res[4]);
94
        $this->assertEquals($this->directorySkeleton . "/layout/exception.html.twig", $res[5]);
95
        $this->assertEquals($this->directorySkeleton . "/layout/javascripts.html.twig", $res[6]);
96
        $this->assertEquals($this->directorySkeleton . "/layout/stylesheets.html.twig", $res[7]);
97
    }
98
99
    /**
100
     * Tests the listSkeleton() method.
101
     *
102
     * @return void
103
     */
104
    public function testListSkeletonWithDirectoryNotFoundException(): void {
105
106
        try {
107
108
            SkeletonHelper::listSkeleton($this->directoryIllegal);
109
        } catch (Exception $ex) {
110
111
            $this->assertInstanceOf(InvalidArgumentException::class, $ex);
112
        }
113
    }
114
}
115