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\Factory; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Prophecy\Argument; |
16
|
|
|
use Sylius\Bundle\ThemeBundle\Factory\ThemeFactory; |
17
|
|
|
use Sylius\Bundle\ThemeBundle\Factory\ThemeFactoryInterface; |
18
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @mixin ThemeFactory |
22
|
|
|
* |
23
|
|
|
* @author Kamil Kokot <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class ThemeFactorySpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
function let( |
28
|
|
|
$themeClassName = 'Sylius\Bundle\ThemeBundle\Model\Theme', |
29
|
|
|
PropertyAccessorInterface $propertyAccessor |
30
|
|
|
) { |
31
|
|
|
$this->beConstructedWith($themeClassName, $propertyAccessor); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_is_initializable() |
35
|
|
|
{ |
36
|
|
|
$this->shouldHaveType('Sylius\Bundle\ThemeBundle\Factory\ThemeFactory'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_implements_theme_factory_interface() |
40
|
|
|
{ |
41
|
|
|
$this->shouldImplement(ThemeFactoryInterface::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_creates_theme_from_valid_array($themeClassName, PropertyAccessorInterface $propertyAccessor) |
45
|
|
|
{ |
46
|
|
|
$data = [ |
47
|
|
|
'name' => 'Foo bar', |
48
|
|
|
'slug' => 'foo/bar', |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$propertyAccessor->setValue(Argument::any(), 'name', 'Foo bar')->shouldBeCalled(); |
|
|
|
|
52
|
|
|
$propertyAccessor->setValue(Argument::any(), 'slug', 'foo/bar')->shouldBeCalled(); |
|
|
|
|
53
|
|
|
$propertyAccessor->setValue(Argument::any(), 'parentsSlugs', [])->shouldBeCalled(); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$this->createFromArray($data)->shouldHaveType($themeClassName); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function it_throws_exception_if_given_array_is_invalid() |
59
|
|
|
{ |
60
|
|
|
$data = [ |
61
|
|
|
'name' => 'Foo bar', |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
$this->shouldThrow('\Exception')->duringCreateFromArray($data); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|