Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ObjectRegistryTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class ObjectRegistryTest extends \PHPUnit\Framework\TestCase
12 {
14  protected $objectRegistry;
15 
17  protected $object;
18 
19  protected function setUp()
20  {
21  $this->object = new \Magento\Framework\DataObject(['id' => 1]);
22  $this->objectRegistry = (new ObjectManager($this))->getObject(
23  \Magento\CatalogUrlRewrite\Model\ObjectRegistry::class,
24  ['entities' => [$this->object]]
25  );
26  }
27 
28  public function testGet()
29  {
30  $this->assertEquals($this->object, $this->objectRegistry->get(1));
31  }
32 
33  public function testGetNotExistObject()
34  {
35  $this->assertEquals(null, $this->objectRegistry->get('no-id'));
36  }
37 
38  public function testGetList()
39  {
40  $this->assertEquals([1 => $this->object], $this->objectRegistry->getList());
41  }
42 
43  public function testGetEmptyList()
44  {
45  $objectRegistry = (new ObjectManager($this))->getObject(
46  \Magento\CatalogUrlRewrite\Model\ObjectRegistry::class,
47  ['entities' => []]
48  );
49  $this->assertEquals([], $objectRegistry->getList());
50  }
51 }