PlaceholderFactoryTest.php 2.1 KB

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