Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataObjectHandlerTest.php
Go to the documentation of this file.
1 <?php
8 
9 use AspectMock\Test as AspectMock;
16 
21 {
22  // All tests share this array, feel free to add but be careful modifying or removing
23  const PARSER_OUTPUT = [
24  'entity' => [
25  'EntityOne' => [
26  'type' => 'testType',
27  'data' => [
28  0 => [
29  'key' => 'testKey',
30  'value' => 'testValue'
31  ]
32  ]
33  ]
34  ]
35  ];
36 
42  public static function setUpBeforeClass()
43  {
44  $mockDataProfileSchemaParser = AspectMock::double(DataProfileSchemaParser::class, [
45  'readDataProfiles' => self::PARSER_OUTPUT
46  ])->make();
47 
48  $mockObjectManager = AspectMock::double(ObjectManager::class, [
49  'create' => $mockDataProfileSchemaParser
50  ])->make();
51 
52  AspectMock::double(ObjectManagerFactory::class, [
53  'getObjectManager' => $mockObjectManager
54  ]);
55  }
56 
60  public function testGetAllObjects()
61  {
62  // Call the method under test
63 
64  $actual = DataObjectHandler::getInstance()->getAllObjects();
65 
66  // Assert
67 
68  $expected = new EntityDataObject('EntityOne', 'testType', ['testkey' => 'testValue'], [], null, []);
69  $this->assertArrayHasKey('EntityOne', $actual);
70  $this->assertEquals($expected, $actual['EntityOne']);
71  }
72 
76  public function testGetObject()
77  {
78  // Call the method under test
79 
80  $actual = DataObjectHandler::getInstance()->getObject('EntityOne');
81 
82  // Assert
83 
84  $expected = new EntityDataObject('EntityOne', 'testType', ['testkey' => 'testValue'], [], null, []);
85  $this->assertEquals($expected, $actual);
86  }
87 
91  public function testGetObjectNull()
92  {
93  $actual = DataObjectHandler::getInstance()->getObject('h953u789h0g73t521'); // doesnt exist
94  $this->assertNull($actual);
95  }
96 }