RegistryTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Test\Unit;
  7. use \Magento\Framework\Registry;
  8. /**
  9. * Registry model test. Test cases for managing values in registry
  10. */
  11. class RegistryTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Framework\Registry
  15. */
  16. protected $registry;
  17. /**
  18. * @var array
  19. */
  20. protected $data;
  21. protected function setUp()
  22. {
  23. $this->registry = new Registry();
  24. $this->data = [
  25. 'key' => 'customer',
  26. 'value' => \Magento\Customer\Model\Customer::class,
  27. ];
  28. $this->registry->register($this->data['key'], $this->data['value']);
  29. }
  30. public function tearDown()
  31. {
  32. unset($this->registry);
  33. }
  34. public function testRegistry()
  35. {
  36. $this->assertEquals($this->data['value'], $this->registry->registry($this->data['key']));
  37. $this->assertNull($this->registry->registry($this->data['value']));
  38. }
  39. public function testRegister()
  40. {
  41. $key = 'email';
  42. $value = 'test@magento.com';
  43. $this->registry->register($key, $value);
  44. $this->assertEquals($value, $this->registry->registry($key));
  45. $key = 'name';
  46. $graceful = true;
  47. $this->registry->register($key, $value, $graceful);
  48. }
  49. /**
  50. * @expectedException \RuntimeException
  51. */
  52. public function testRegisterKeyExists()
  53. {
  54. $this->registry->register($this->data['key'], $this->data['value']);
  55. }
  56. public function testUnregister()
  57. {
  58. $key = 'csv_adapter';
  59. $valueObj = $this->createMock(\Magento\ImportExport\Model\Export\Adapter\Csv::class);
  60. $this->registry->register($key, $valueObj);
  61. $this->assertEquals($valueObj, $this->registry->registry($key));
  62. $this->registry->unregister($key);
  63. $this->assertNull($this->registry->registry($key));
  64. $this->registry->unregister($this->data['key']);
  65. $this->assertNull($this->registry->registry($this->data['key']));
  66. }
  67. }