Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FieldDataConverterFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
13 
14 class FieldDataConverterFactoryTest extends \PHPUnit\Framework\TestCase
15 {
19  private $objectManagerMock;
20 
24  private $dataConverterMock;
25 
29  private $fieldDataConverterFactory;
30 
31  protected function setUp()
32  {
33  $objectManager = new ObjectManager($this);
34  $this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
35  $this->dataConverterMock = $this->createMock(DataConverterInterface::class);
36  $this->fieldDataConverterFactory = $objectManager->getObject(
37  FieldDataConverterFactory::class,
38  [
39  'objectManager' => $this->objectManagerMock
40  ]
41  );
42  }
43 
44  public function testCreate()
45  {
46  $dataConverterClassName = 'ClassName';
47  $fieldDataConverterInstance = 'field data converter instance';
48  $this->objectManagerMock->expects($this->once())
49  ->method('get')
50  ->with($dataConverterClassName)
51  ->willReturn($this->dataConverterMock);
52  $this->objectManagerMock->expects($this->once())
53  ->method('create')
54  ->with(
55  FieldDataConverter::class,
56  [
57  'dataConverter' => $this->dataConverterMock
58  ]
59  )
60  ->willReturn($fieldDataConverterInstance);
61  $this->assertEquals(
62  $fieldDataConverterInstance,
63  $this->fieldDataConverterFactory->create($dataConverterClassName)
64  );
65  }
66 }
$objectManager
Definition: bootstrap.php:17