Completed
Push — master ( 67c7d1...f02869 )
by Nicolas
02:52
created

AsgardAssetManagerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
<?php namespace Modules\Core\Tests\Asset;
2
3
use Modules\Core\Foundation\Asset\Manager\AsgardAssetManager;
4
use Modules\Core\Tests\BaseTestCase;
5
6
class AsgardAssetManagerTest extends BaseTestCase
7
{
8
    /**
9
     * @var \Modules\Core\Foundation\Asset\Manager\AsgardAssetManager
10
     */
11
    private $assetManager;
12
13
    public function setUp()
14
    {
15
        parent::__construct();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (__construct() instead of setUp()). Are you sure this is correct? If so, you might want to change this to $this->__construct().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
16
        $this->assetManager = new AsgardAssetManager();
17
    }
18
19
    /** @test */
20 View Code Duplication
    public function it_should_return_empty_collection_if_no_assets()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        $cssResult = $this->assetManager->allCss();
23
        $jsResult = $this->assetManager->allJs();
24
25
        $this->assertInstanceOf('Illuminate\Support\Collection', $cssResult);
26
        $this->assertEquals(0, $cssResult->count());
0 ignored issues
show
Bug introduced by
The method count cannot be called on $cssResult (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
27
        $this->assertInstanceOf('Illuminate\Support\Collection', $jsResult);
28
        $this->assertEquals(0, $jsResult->count());
0 ignored issues
show
Bug introduced by
The method count cannot be called on $jsResult (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
29
    }
30
31
    /** @test */
32
    public function it_should_add_one_javascript_asset()
33
    {
34
        $this->assetManager->addAsset('jquery', '/path/to/jquery.js');
35
36
        $jsResult = $this->assetManager->allJs();
37
38
        $this->assertEquals(1, $jsResult->count());
0 ignored issues
show
Bug introduced by
The method count cannot be called on $jsResult (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
39
    }
40
41
    /** @test */
42
    public function it_should_add_one_css_asset()
43
    {
44
        $this->assetManager->addAsset('main', '/path/to/main.css');
45
46
        $cssResult = $this->assetManager->allCss();
47
48
        $this->assertEquals(1, $cssResult->count());
0 ignored issues
show
Bug introduced by
The method count cannot be called on $cssResult (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
49
    }
50
51
    /** @test */
52 View Code Duplication
    public function it_should_add_multiple_assets()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $this->assetManager->addAsset('main', '/path/to/main.css');
55
        $this->assetManager->addAsset('footer', '/path/to/footer.css');
56
        $this->assetManager->addAsset('jquery', '/path/to/jquery.js');
57
        $this->assetManager->addAsset('jquery_plugin', '/path/to/jquery_plugin.js');
58
59
        $cssResults = $this->assetManager->allCss();
60
        $jsResults = $this->assetManager->allJs();
61
62
        $this->assertEquals(2, $cssResults->count());
0 ignored issues
show
Bug introduced by
The method count cannot be called on $cssResults (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
63
        $this->assertEquals(2, $jsResults->count());
0 ignored issues
show
Bug introduced by
The method count cannot be called on $jsResults (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
64
    }
65
66
    /** @test */
67 View Code Duplication
    public function it_should_return_the_dependency_asked_for()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $this->assetManager->addAsset('main', '/path/to/main.css');
70
        $this->assetManager->addAsset('footer', '/path/to/footer.css');
71
        $this->assetManager->addAsset('jquery', '/path/to/jquery.js');
72
        $this->assetManager->addAsset('jquery_plugin', '/path/to/jquery_plugin.js');
73
74
        $jquery = $this->assetManager->getJs('jquery');
75
        $footer = $this->assetManager->getCss('footer');
76
77
        $this->assertEquals('/path/to/jquery.js', $jquery);
78
        $this->assertEquals('/path/to/footer.css', $footer);
79
    }
80
81
    /** @test */
82
    public function it_should_throw_an_exception_if_js_asset_not_found()
83
    {
84
        $this->setExpectedException('Modules\Core\Foundation\Asset\AssetNotFoundException');
85
86
        $this->assetManager->addAsset('jquery', '/path/to/jquery.js');
87
88
        $this->assetManager->getJs('app');
89
    }
90
91
    /** @test */
92
    public function it_should_throw_an_exception_if_css_asset_not_found()
93
    {
94
        $this->setExpectedException('Modules\Core\Foundation\Asset\AssetNotFoundException');
95
96
        $this->assetManager->addAsset('main', '/path/to/main.css');
97
98
        $this->assetManager->getCss('iCheck');
99
    }
100
101
    /** @test */
102
    public function it_should_add_an_array_of_assets()
103
    {
104
        $this->assetManager->addAssets([
105
            'jquery' => '/path/to/jquery.js',
106
            'plugin' => '/path/to/plugin.js',
107
            'main' => '/path/to/main.css',
108
            'icheck' => '/path/to/icheck.css',
109
        ]);
110
111
        $jsAssets = $this->assetManager->allJs();
112
        $cssAssets = $this->assetManager->allCss();
113
114
        $expectedJs = [
115
            'jquery' => '/path/to/jquery.js',
116
            'plugin' => '/path/to/plugin.js',
117
        ];
118
        $expectedCss = [
119
            'main' => '/path/to/main.css',
120
            'icheck' => '/path/to/icheck.css',
121
        ];
122
123
        $this->assertEquals($expectedJs, $jsAssets->toArray());
0 ignored issues
show
Bug introduced by
The method toArray cannot be called on $jsAssets (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
124
        $this->assertEquals($expectedCss, $cssAssets->toArray());
0 ignored issues
show
Bug introduced by
The method toArray cannot be called on $cssAssets (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
125
    }
126
}
127