Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RegistryLocatorTest.php
Go to the documentation of this file.
1 <?php
8 
14 
18 class RegistryLocatorTest extends \PHPUnit\Framework\TestCase
19 {
23  protected $objectManager;
24 
28  protected $model;
29 
33  protected $registryMock;
34 
38  protected $productMock;
39 
43  protected $storeMock;
44 
45  protected function setUp()
46  {
47  $this->objectManager = new ObjectManager($this);
48  $this->registryMock = $this->getMockBuilder(Registry::class)
49  ->setMethods(['registry'])
50  ->getMock();
51  $this->productMock = $this->getMockBuilder(ProductInterface::class)
52  ->getMockForAbstractClass();
53  $this->storeMock = $this->getMockBuilder(StoreInterface::class)
54  ->getMockForAbstractClass();
55 
56  $this->model = $this->objectManager->getObject(RegistryLocator::class, [
57  'registry' => $this->registryMock,
58  ]);
59  }
60 
61  public function testGetProduct()
62  {
63  $this->registryMock->expects($this->once())
64  ->method('registry')
65  ->with('current_product')
66  ->willReturn($this->productMock);
67 
68  $this->assertInstanceOf(ProductInterface::class, $this->model->getProduct());
69  // Lazy loading
70  $this->assertInstanceOf(ProductInterface::class, $this->model->getProduct());
71  }
72 
73  public function testGetStore()
74  {
75  $this->registryMock->expects($this->once())
76  ->method('registry')
77  ->with('current_store')
78  ->willReturn($this->storeMock);
79 
80  $this->assertInstanceOf(StoreInterface::class, $this->model->getStore());
81  // Lazy loading
82  $this->assertInstanceOf(StoreInterface::class, $this->model->getStore());
83  }
84 
89  public function testGetProductWithException()
90  {
91  $this->assertInstanceOf(ProductInterface::class, $this->model->getProduct());
92  }
93 
98  public function testGetStoreWithException()
99  {
100  $this->assertInstanceOf(StoreInterface::class, $this->model->getStore());
101  }
102 }