Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RegistryTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Registry;
9 
13 class RegistryTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $registry;
19 
23  protected $data;
24 
25  protected function setUp()
26  {
27  $this->registry = new Registry();
28  $this->data = [
29  'key' => 'customer',
30  'value' => \Magento\Customer\Model\Customer::class,
31  ];
32  $this->registry->register($this->data['key'], $this->data['value']);
33  }
34 
35  public function tearDown()
36  {
37  unset($this->registry);
38  }
39 
40  public function testRegistry()
41  {
42  $this->assertEquals($this->data['value'], $this->registry->registry($this->data['key']));
43  $this->assertNull($this->registry->registry($this->data['value']));
44  }
45 
46  public function testRegister()
47  {
48  $key = 'email';
50  $this->registry->register($key, $value);
51  $this->assertEquals($value, $this->registry->registry($key));
52  $key = 'name';
53  $graceful = true;
54  $this->registry->register($key, $value, $graceful);
55  }
56 
60  public function testRegisterKeyExists()
61  {
62  $this->registry->register($this->data['key'], $this->data['value']);
63  }
64 
65  public function testUnregister()
66  {
67  $key = 'csv_adapter';
68  $valueObj = $this->createMock(\Magento\ImportExport\Model\Export\Adapter\Csv::class);
69  $this->registry->register($key, $valueObj);
70  $this->assertEquals($valueObj, $this->registry->registry($key));
71  $this->registry->unregister($key);
72  $this->assertNull($this->registry->registry($key));
73  $this->registry->unregister($this->data['key']);
74  $this->assertNull($this->registry->registry($this->data['key']));
75  }
76 }
$value
Definition: gender.phtml:16