testFactoryWithSourceSizes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * responsive-images-css
5
 *
6
 * @category   Jkphl
7
 * @package    Jkphl\Respimgcss
8
 * @subpackage Jkphl\Respimgcss\Tests
9
 * @author     Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright  Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license    http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Jkphl\Respimgcss\Tests\Application;
38
39
use Jkphl\Respimgcss\Application\Contract\CalculatorServiceFactoryInterface;
40
use Jkphl\Respimgcss\Application\Contract\UnitLengthInterface;
41
use Jkphl\Respimgcss\Application\Factory\CssRulesetCompilerServiceFactory;
42
use Jkphl\Respimgcss\Application\Factory\LengthFactory;
43
use Jkphl\Respimgcss\Application\Model\ImageCandidateSet;
44
use Jkphl\Respimgcss\Domain\Model\Css\Ruleset;
45
use Jkphl\Respimgcss\Domain\Model\DensityImageCandidate;
46
use Jkphl\Respimgcss\Domain\Model\WidthImageCandidate;
47
use Jkphl\Respimgcss\Domain\Service\DensityCssRulesetCompilerService;
48
use Jkphl\Respimgcss\Domain\Service\WidthCssRulesetCompilerService;
49
use Jkphl\Respimgcss\Infrastructure\SourceSizeList;
50
use Jkphl\Respimgcss\Infrastructure\ViewportCalculatorServiceFactory;
51
use Jkphl\Respimgcss\Tests\AbstractTestBase;
52
use Jkphl\Respimgcss\Tests\Application\Mocks\ImageCandidateMock;
53
54
/**
55
 * CSS Ruleset compiler service factory tests
56
 *
57
 * @package    Jkphl\Respimgcss
58
 * @subpackage Jkphl\Respimgcss\Tests
59
 */
60
class CssRulesetCompilerServiceFactoryTest extends AbstractTestBase
61
{
62
    /**
63
     * Breakpoints
64
     *
65
     * @var UnitLengthInterface[]
66
     */
67
    protected $breakpoints = [];
68
69
    /**
70
     * Test the CSS Ruleset compiler service factory with an invalid image candidate set
71
     *
72
     * @expectedException \Jkphl\Respimgcss\Application\Exceptions\RuntimeException
73
     * @expectedExceptionCode 1522514954
74
     */
75
    public function testFactoryWithInvalidImageCandidateSet()
76
    {
77
        CssRulesetCompilerServiceFactory::createForImageCandidates(
78
            new Ruleset(),
79
            $this->breakpoints,
80
            new ImageCandidateSet(new ImageCandidateMock('image.jpg', 1)),
81
            new ViewportCalculatorServiceFactory(),
82
            16
83
        );
84
    }
85
86
    /**
87
     * Test the CSS Ruleset compiler service factory with a density based image candidate set
88
     */
89
    public function testFactoryWithDensityImageCandidateSet()
90
    {
91
        $compilerService = CssRulesetCompilerServiceFactory::createForImageCandidates(
92
            new Ruleset(),
93
            $this->breakpoints,
94
            new ImageCandidateSet(new DensityImageCandidate('image.jpg', 1)),
95
            new ViewportCalculatorServiceFactory(),
96
            16
97
        );
98
        $this->assertInstanceOf(DensityCssRulesetCompilerService::class, $compilerService);
99
    }
100
101
    /**
102
     * Test the CSS Ruleset compiler service factory with a width based image candidate set
103
     */
104
    public function testFactoryWithWidthImageCandidateSet()
105
    {
106
        $compilerService = CssRulesetCompilerServiceFactory::createForImageCandidates(
107
            new Ruleset(),
108
            $this->breakpoints,
109
            new ImageCandidateSet(new WidthImageCandidate('image.jpg', 1000)),
110
            new ViewportCalculatorServiceFactory(),
111
            16
112
        );
113
        $this->assertInstanceOf(WidthCssRulesetCompilerService::class, $compilerService);
114
    }
115
116
    /**
117
     * Test the CSS Ruleset compiler service factory with a width based image candidate set and source sizes
118
     */
119
    public function testFactoryWithSourceSizes()
120
    {
121
        $lengthFactory   = new LengthFactory($this->createMock(CalculatorServiceFactoryInterface::class), 16);
122
        $sourceSizeList  = new SourceSizeList([], $lengthFactory);
123
        $compilerService = CssRulesetCompilerServiceFactory::createForImageCandidates(
124
            new Ruleset(),
125
            $this->breakpoints,
126
            new ImageCandidateSet(new WidthImageCandidate('image.jpg', 1000)),
127
            new ViewportCalculatorServiceFactory(),
128
            16,
129
            $sourceSizeList
130
        );
131
        $this->assertInstanceOf(WidthCssRulesetCompilerService::class, $compilerService);
132
    }
133
134
    /**
135
     * Test setup
136
     */
137
    protected function setUp()/* The :void return type declaration that should be here would cause a BC issue */
138
    {
139
        parent::setUp();
140
        $lengthFactory       = new LengthFactory(new ViewportCalculatorServiceFactory(), 16);
141
        $this->breakpoints[] = $lengthFactory->createLengthFromString('24em');
142
        $this->breakpoints[] = $lengthFactory->createLengthFromString('800px');
143
        $this->breakpoints[] = $lengthFactory->createLengthFromString('72em');
144
    }
145
}
146