1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\Test\Unit\Model\Placeholder;
use Magento\Config\Model\Placeholder\Environment;
use Magento\Config\Model\Placeholder\PlaceholderFactory;
use Magento\Framework\ObjectManagerInterface;
class PlaceholderFactoryTest extends \PHPUnit\Framework\TestCase
{
/**
* @var PlaceholderFactory
*/
private $model;
/**
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $objectManagerMock;
/**
* @var Environment|\PHPUnit_Framework_MockObject_MockObject
*/
private $environmentMock;
protected function setUp()
{
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
->getMockForAbstractClass();
$this->environmentMock = $this->getMockBuilder(Environment::class)
->disableOriginalConstructor()
->getMock();
$this->model = new PlaceholderFactory(
$this->objectManagerMock,
[
PlaceholderFactory::TYPE_ENVIRONMENT => Environment::class,
'wrongClass' => \stdClass::class,
]
);
}
public function testCreate()
{
$this->objectManagerMock->expects($this->once())
->method('create')
->with(Environment::class)
->willReturn($this->environmentMock);
$this->assertInstanceOf(
Environment::class,
$this->model->create(PlaceholderFactory::TYPE_ENVIRONMENT)
);
}
/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage There is no defined type dummyClass
*/
public function testCreateNonExisted()
{
$this->model->create('dummyClass');
}
/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage Object is not instance of Magento\Config\Model\Placeholder\PlaceholderInterface
*/
public function testCreateWrongImplementation()
{
$this->model->create('wrongClass');
}
}