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