helperCatalogMock = $this->createMock(Catalog::class); $this->observerMock = $this->createMock(Observer::class); $this->eventMock = $this->getMockBuilder(Event::class) ->disableOriginalConstructor() ->addMethods(['getProduct']) ->getMock(); $this->productMock = $this->getMockBuilder(Product::class) ->disableOriginalConstructor() ->getMock(); $this->observer = $objectManager->getObject( SetAttributeTabBlockObserver::class, [ 'helperCatalog' => $this->helperCatalogMock ] ); } /** * Test setting attribute tab block for bundle product */ public function testAddingAttributeTabForBundleProduct() { $this->productMock->expects($this->any()) ->method('getTypeId') ->willReturn(Type::TYPE_BUNDLE); $this->eventMock->expects($this->any()) ->method('getProduct') ->willReturn($this->productMock); $this->observerMock->expects($this->any()) ->method('getEvent') ->willReturn($this->eventMock); $this->helperCatalogMock->expects($this->once()) ->method('setAttributeTabBlock') ->with(Attributes::class); $this->observer->execute($this->observerMock); } /** * Test setting attribute tab block for a non bundle product */ public function testAddingAttributeTabForNonBundleProduct() { $this->productMock->expects($this->any()) ->method('getTypeId') ->willReturn(Type::TYPE_VIRTUAL); $this->eventMock->expects($this->any()) ->method('getProduct') ->willReturn($this->productMock); $this->observerMock->expects($this->any()) ->method('getEvent') ->willReturn($this->eventMock); $this->helperCatalogMock->expects($this->never()) ->method('setAttributeTabBlock'); $this->observer->execute($this->observerMock); } }