Completed
Push — 2.0 ( 80d7ba...6db185 )
by Nicolas
03:06
created

AssetFactoryTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 70
rs 10
wmc 6
lcom 1
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A it_throws_exception_if_asset_type_not_found() 0 8 1
A it_returns_an_asset_type_class() 0 14 1
A it_returns_theme_asset() 0 8 1
A it_returns_module_asset() 0 8 1
A it_returns_cdn_asset() 0 8 1
1
<?php namespace Modules\Core\Tests\Asset;
2
3
use Modules\Core\Foundation\Asset\Types\AssetType;
4
use Modules\Core\Foundation\Asset\Types\AssetTypeFactory;
5
use Modules\Core\Tests\BaseTestCase;
6
7
class AssetFactoryTest extends BaseTestCase
8
{
9
    /**
10
     * @var AssetTypeFactory
11
     */
12
    private $assetFactory;
13
14
    public function setUp()
15
    {
16
        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...
17
        $this->refreshApplication();
18
        $this->assetFactory = app(AssetTypeFactory::class);
19
    }
20
21
    /** @test */
22
    public function it_throws_exception_if_asset_type_not_found()
23
    {
24
        $this->setExpectedException(\InvalidArgumentException::class);
25
26
        $path = ['somehting' => 'some/path.something'];
27
28
        $this->assetFactory->make($path)->url();
29
    }
30
31
    /** @test */
32
    public function it_returns_an_asset_type_class()
33
    {
34
        $themePath = ['theme' => 'some/path.js'];
35
        $modulePath = ['module' => 'some/path.js'];
36
        $cdnPath = ['module' => 'some/path.js'];
37
38
        $themeClass = $this->assetFactory->make($themePath);
39
        $moduleClass = $this->assetFactory->make($modulePath);
40
        $cdnClass = $this->assetFactory->make($cdnPath);
41
42
        $this->assertInstanceOf(AssetType::class, $themeClass);
43
        $this->assertInstanceOf(AssetType::class, $moduleClass);
44
        $this->assertInstanceOf(AssetType::class, $cdnClass);
45
    }
46
47
    /** @test */
48
    public function it_returns_theme_asset()
49
    {
50
        $themePath = ['theme' => 'some/path.js'];
51
52
        $asset = $this->assetFactory->make($themePath)->url();
53
54
        $this->assertEquals('http://localhost/some/path.js', $asset);
55
    }
56
57
    /** @test */
58
    public function it_returns_module_asset()
59
    {
60
        $modulePath = ['module' => 'core:some/path.js'];
61
62
        $asset = $this->assetFactory->make($modulePath)->url();
63
64
        $this->assertEquals('//localhost/modules/core/some/path.js', $asset);
65
    }
66
67
    /** @test */
68
    public function it_returns_cdn_asset()
69
    {
70
        $cdnPath = ['cdn' => 'https://js.stripe.com/v2'];
71
72
        $asset = $this->assetFactory->make($cdnPath)->url();
73
74
        $this->assertEquals('https://js.stripe.com/v2', $asset);
75
    }
76
}
77