Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
ObjectManagerTest Class Reference
Inheritance diagram for ObjectManagerTest:

Public Member Functions

 testInstancePersistingAfterClearCache ()
 
 testInstanceDestroyingAfterClearCache ()
 
 testInstanceRecreatingAfterClearCache ()
 
 testIsEmptyMappedTableNamesAfterClearCache ()
 

Detailed Description

Definition at line 19 of file ObjectManagerTest.php.

Member Function Documentation

◆ testInstanceDestroyingAfterClearCache()

testInstanceDestroyingAfterClearCache ( )

Tests that instance is destroyed after Object Manager cache clearing.

@covers \Magento\TestFramework\ObjectManager::clearCache()

Definition at line 81 of file ObjectManagerTest.php.

82  {
83  $sharedInstances[self::$notPersistedInstance] = $this->createInstanceMock(self::$notPersistedInstance);
84  $config = $this->getObjectManagerConfigMock();
85  $factory = $this->getObjectManagerFactoryMock();
86 
87  $objectManager = new ObjectManager($factory, $config, $sharedInstances);
88  $objectManager->clearCache();
89 
90  $this->assertNull(
91  $objectManager->get(self::$notPersistedInstance),
92  'Instance of ' . self::$notPersistedInstance . ' should be destroyed after cache clearing.'
93  );
94  }
$objectManager
Definition: bootstrap.php:17
$config
Definition: fraud_order.php:17

◆ testInstancePersistingAfterClearCache()

testInstancePersistingAfterClearCache ( )

Tests that the scope of persisted instances doesn't clear after Object Manager cache clearing.

@covers \Magento\TestFramework\ObjectManager::clearCache()

Definition at line 45 of file ObjectManagerTest.php.

46  {
47  foreach (self::$persistedInstances as $className) {
48  $sharedInstances[$className] = $this->createInstanceMock($className);
49  }
50 
51  $config = $this->getObjectManagerConfigMock();
52  $factory = $this->getObjectManagerFactoryMock();
53 
54  $objectManager = new ObjectManager($factory, $config, $sharedInstances);
55  $objectManager->clearCache();
56 
57  $this->assertSame(
59  $objectManager->get(ObjectManagerInterface::class),
60  "Object manager instance should be the same after cache clearing."
61  );
62  $this->assertSame(
64  $objectManager->get(\Magento\Framework\App\ObjectManager::class),
65  "Object manager instance should be the same after cache clearing."
66  );
67  foreach (self::$persistedInstances as $className) {
68  $this->assertSame(
69  $sharedInstances[$className],
71  "Instance of {$className} should be the same after cache clearing."
72  );
73  }
74  }
$objectManager
Definition: bootstrap.php:17
$config
Definition: fraud_order.php:17
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ testInstanceRecreatingAfterClearCache()

testInstanceRecreatingAfterClearCache ( )

Tests that instance is recreated after Object Manager cache clearing.

@covers \Magento\TestFramework\ObjectManager::clearCache()

Definition at line 101 of file ObjectManagerTest.php.

102  {
103  $config = $this->getObjectManagerConfigMock();
104  $factory = $this->getObjectManagerFactoryMock();
105 
106  $objectManager = new ObjectManager($factory, $config);
107  $instance = $objectManager->get(DataObject::class);
108 
109  $this->assertSame($instance, $objectManager->get(DataObject::class));
110  $objectManager->clearCache();
111  $this->assertNotSame(
112  $instance,
113  $objectManager->get(DataObject::class),
114  'Instance ' . DataObject::class . ' should be recreated after cache clearing.'
115  );
116  }
$objectManager
Definition: bootstrap.php:17
$config
Definition: fraud_order.php:17

◆ testIsEmptyMappedTableNamesAfterClearCache()

testIsEmptyMappedTableNamesAfterClearCache ( )

Tests that mapped table names list is empty after Object Manager cache clearing.

@covers \Magento\TestFramework\ObjectManager::clearCache()

Definition at line 123 of file ObjectManagerTest.php.

124  {
125  $config = $this->getObjectManagerConfigMock();
126  $factory = $this->getObjectManagerFactoryMock();
127 
128  $objectManager = new ObjectManager($factory, $config);
129 
130  $resourceConnection = $this->getResourceConnection();
131  $resourceConnection->setMappedTableName('tableName', 'mappedTableName');
132  $objectManager->addSharedInstance(
134  ResourceConnection::class
135  );
136  $objectManager->clearCache();
137 
138  $this->assertFalse(
139  $objectManager->get(ResourceConnection::class)->getMappedTableName('tableName'),
140  'Mapped table names list is not empty after Object Manager cache clearing.'
141  );
142  }
$objectManager
Definition: bootstrap.php:17
$config
Definition: fraud_order.php:17

The documentation for this class was generated from the following file: