Completed
Push — php71-support ( 2570a5...950570 )
by Kamil
30:36
created

PathPackageSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 85
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_returns_path_without_changes_if_it_is_absolute() 0 5 1
A it_does_not_prepend_it_with_base_path_if_modified_path_is_an_absolute_one() 0 16 1
A it_does_not_prepend_it_with_base_path_if_modified_path_is_an_absolute_url() 0 16 1
A it_implements_package_interface_interface() 0 4 1
A it_returns_vanilla_path_if_there_are_no_active_themes() 0 12 1
A it_returns_modified_path_if_there_is_active_theme() 0 16 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 spec\Sylius\Bundle\ThemeBundle\Asset\Package;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\ThemeBundle\Asset\PathResolverInterface;
16
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
17
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
18
use Symfony\Component\Asset\PackageInterface;
19
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
20
21
/**
22
 * @author Kamil Kokot <[email protected]>
23
 */
24
final class PathPackageSpec extends ObjectBehavior
25
{
26
    function let(
27
        VersionStrategyInterface $versionStrategy,
28
        ThemeContextInterface $themeContext,
29
        PathResolverInterface $pathResolver
30
    ) {
31
        $this->beConstructedWith('/', $versionStrategy, $themeContext, $pathResolver);
32
    }
33
34
    function it_implements_package_interface_interface()
35
    {
36
        $this->shouldImplement(PackageInterface::class);
37
    }
38
39
    function it_returns_vanilla_path_if_there_are_no_active_themes(
40
        ThemeContextInterface $themeContext,
41
        VersionStrategyInterface $versionStrategy
42
    ) {
43
        $path = 'bundles/sample/asset.js';
44
        $versionedPath = 'bundles/sample/asset.js?v=42';
45
46
        $themeContext->getTheme()->shouldBeCalled()->willReturn(null);
47
        $versionStrategy->applyVersion($path)->shouldBeCalled()->willReturn($versionedPath);
48
49
        $this->getUrl($path)->shouldReturn('/' . $versionedPath);
50
    }
51
52
    function it_returns_modified_path_if_there_is_active_theme(
53
        ThemeContextInterface $themeContext,
54
        VersionStrategyInterface $versionStrategy,
55
        PathResolverInterface $pathResolver,
56
        ThemeInterface $theme
57
    ) {
58
        $path = 'bundles/sample/asset.js';
59
        $themedPath = 'bundles/theme/foo/bar/sample/asset.js';
60
        $versionedThemedPath = 'bundles/theme/foo/bar/sample/asset.js?v=42';
61
62
        $themeContext->getTheme()->shouldBeCalled()->willReturn($theme);
63
        $pathResolver->resolve($path, $theme)->shouldBeCalled()->willReturn($themedPath);
64
        $versionStrategy->applyVersion($themedPath)->shouldBeCalled()->willReturn($versionedThemedPath);
65
66
        $this->getUrl($path)->shouldReturn('/' . $versionedThemedPath);
67
    }
68
69
    function it_returns_path_without_changes_if_it_is_absolute()
70
    {
71
        $this->getUrl('//localhost/asset.js')->shouldReturn('//localhost/asset.js');
72
        $this->getUrl('https://localhost/asset.js')->shouldReturn('https://localhost/asset.js');
73
    }
74
75
    function it_does_not_prepend_it_with_base_path_if_modified_path_is_an_absolute_one(
76
        ThemeContextInterface $themeContext,
77
        VersionStrategyInterface $versionStrategy,
78
        PathResolverInterface $pathResolver,
79
        ThemeInterface $theme
80
    ) {
81
        $path = 'bundles/sample/asset.js';
82
        $themedPath = 'bundles/theme/foo/bar/sample/asset.js';
83
        $versionedThemedPath = '/bundles/theme/foo/bar/sample/asset.js?v=42';
84
85
        $themeContext->getTheme()->shouldBeCalled()->willReturn($theme);
86
        $pathResolver->resolve($path, $theme)->shouldBeCalled()->willReturn($themedPath);
87
        $versionStrategy->applyVersion($themedPath)->shouldBeCalled()->willReturn($versionedThemedPath);
88
89
        $this->getUrl($path)->shouldReturn($versionedThemedPath);
90
    }
91
92
    function it_does_not_prepend_it_with_base_path_if_modified_path_is_an_absolute_url(
93
        ThemeContextInterface $themeContext,
94
        VersionStrategyInterface $versionStrategy,
95
        PathResolverInterface $pathResolver,
96
        ThemeInterface $theme
97
    ) {
98
        $path = 'bundles/sample/asset.js';
99
        $themedPath = 'bundles/theme/foo/bar/sample/asset.js';
100
        $versionedThemedPath = 'https://bundles/theme/foo/bar/sample/asset.js?v=42';
101
102
        $themeContext->getTheme()->shouldBeCalled()->willReturn($theme);
103
        $pathResolver->resolve($path, $theme)->shouldBeCalled()->willReturn($themedPath);
104
        $versionStrategy->applyVersion($themedPath)->shouldBeCalled()->willReturn($versionedThemedPath);
105
106
        $this->getUrl($path)->shouldReturn($versionedThemedPath);
107
    }
108
}
109