Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FactoryDecoratorTest.php
Go to the documentation of this file.
1 <?php
2 /***
3  * Copyright © Magento, Inc. All rights reserved.
4  * See COPYING.txt for license details.
5  */
6 
8 
9 class FactoryDecoratorTest extends \PHPUnit\Framework\TestCase
10 {
14  const CLASS_NAME = \Magento\Test\Di\WrappedClass::class;
15 
19  const LOGGER_NAME = \Magento\Test\Di\WrappedClass\Logger::class;
20 
24  const GENERATOR_NAME = \Magento\Framework\ObjectManager\Profiler\Code\Generator\Logger::class;
25 
27  private $objectManagerMock;
28 
30  private $model;
31 
32  protected function setUp()
33  {
34  require_once __DIR__ . '/../_files/logger_classes.php';
35  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36 
37  $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManager\FactoryInterface::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40 
41  // Instantiate SUT
42  $this->model = $objectManager->getObject(
43  \Magento\Framework\ObjectManager\Profiler\FactoryDecorator::class,
44  ['subject' => $this->objectManagerMock]
45  );
46  }
47 
48  public function testCreate()
49  {
50  $baseObjectName = self::CLASS_NAME;
51  $baseObject = new $baseObjectName();
52 
53  $arguments = [1, 2, 3];
54 
55  $this->objectManagerMock->expects($this->once())
56  ->method('create')
57  ->with(self::CLASS_NAME, $arguments)
58  ->willReturn($baseObject);
59 
60  $this->assertInstanceOf(self::LOGGER_NAME, $this->model->create(self::CLASS_NAME, $arguments));
61  }
62 
63  public function testCreateNeglectGenerator()
64  {
65  $arguments = [1, 2, 3];
66  $loggerMock = $this->getMockBuilder(self::GENERATOR_NAME)->disableOriginalConstructor()->getMock();
67 
68  $this->objectManagerMock->expects($this->once())
69  ->method('create')
70  ->with(self::GENERATOR_NAME, $arguments)
71  ->willReturn($loggerMock);
72 
73  $this->assertSame($loggerMock, $this->model->create(self::GENERATOR_NAME, $arguments));
74  }
75 }
$objectManager
Definition: bootstrap.php:17
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$arguments