objectManagerHelper = new ObjectManager($this); $this->websiteFactory = $this->getMockBuilder(WebsiteFactory::class) ->disableOriginalConstructor() ->addMethods(['getCollection', '__wakeup']) ->onlyMethods(['create']) ->getMock(); $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class); $this->typeList = $this->getMockForAbstractClass(TypeListInterface::class); /** @var Website $websiteModel */ $this->model = $this->objectManagerHelper->getObject( Website::class, [ 'websiteFactory' => $this->websiteFactory, 'storeManager' => $this->storeManager, 'typeList' => $this->typeList ] ); } public function testIsCanDelete() { $websiteCollection = $this->createPartialMock( Collection::class, ['getSize'] ); $websiteCollection->expects($this->any())->method('getSize')->willReturn(2); $this->websiteFactory->expects($this->any()) ->method('create') ->willReturn($this->websiteFactory); $this->websiteFactory->expects($this->any()) ->method('getCollection') ->willReturn($websiteCollection); $this->model->setId(2); $this->assertTrue($this->model->isCanDelete()); } public function testGetScopeType() { $this->assertEquals(ScopeInterface::SCOPE_WEBSITE, $this->model->getScopeType()); } public function testGetScopeTypeName() { $this->assertEquals('Website', $this->model->getScopeTypeName()); } public function testGetCacheTags() { $this->assertEquals([Website::CACHE_TAG], $this->model->getCacheTags()); } public function testAfterSaveNewObject() { $this->storeManager->expects($this->once()) ->method('reinitStores'); $this->model->afterSave(); } public function testAfterSaveObject() { $this->model->setId(1); $this->storeManager->expects($this->never()) ->method('reinitStores'); $this->typeList->expects($this->once()) ->method('invalidate') ->with(['full_page', Config::TYPE_IDENTIFIER]); $this->model->afterSave(); } public function testAfterDelete() { $this->typeList->expects($this->exactly(2)) ->method('cleanType') ->willReturnCallback(fn($param) => match ([$param]) { ['full_page'], [Config::TYPE_IDENTIFIER] => $this->typeList }); $this->model->afterDelete(); } }