![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-catalog/Test/Unit/Model/Locator/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Catalog\Test\Unit\Model\Locator; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Model\Locator\RegistryLocator; use Magento\Framework\Registry; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Store\Api\Data\StoreInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class RegistryLocatorTest extends TestCase { /** * @var ObjectManager */ protected $objectManager; /** * @var RegistryLocator */ protected $model; /** * @var Registry|MockObject */ protected $registryMock; /** * @var ProductInterface|MockObject */ protected $productMock; /** * @var StoreInterface|MockObject */ protected $storeMock; protected function setUp(): void { $this->objectManager = new ObjectManager($this); $this->registryMock = $this->getMockBuilder(Registry::class) ->setMethods(['registry']) ->getMock(); $this->productMock = $this->getMockBuilder(ProductInterface::class) ->getMockForAbstractClass(); $this->storeMock = $this->getMockBuilder(StoreInterface::class) ->getMockForAbstractClass(); $this->model = $this->objectManager->getObject(RegistryLocator::class, [ 'registry' => $this->registryMock, ]); } public function testGetProduct() { $this->registryMock->expects($this->once()) ->method('registry') ->with('current_product') ->willReturn($this->productMock); $this->assertInstanceOf(ProductInterface::class, $this->model->getProduct()); // Lazy loading $this->assertInstanceOf(ProductInterface::class, $this->model->getProduct()); } public function testGetStore() { $this->registryMock->expects($this->once()) ->method('registry') ->with('current_store') ->willReturn($this->storeMock); $this->assertInstanceOf(StoreInterface::class, $this->model->getStore()); // Lazy loading $this->assertInstanceOf(StoreInterface::class, $this->model->getStore()); } public function testGetProductWithException() { $this->expectException('Magento\Framework\Exception\NotFoundException'); $this->expectExceptionMessage('The product wasn\'t registered.'); $this->assertInstanceOf(ProductInterface::class, $this->model->getProduct()); } public function testGetStoreWithException() { $this->expectException('Magento\Framework\Exception\NotFoundException'); $this->expectExceptionMessage('The store wasn\'t registered. Verify the store and try again.'); $this->assertInstanceOf(StoreInterface::class, $this->model->getStore()); } }