entityMock = $this->createMock(Product::class); $this->sampleRepositoryMock = $this->getMockBuilder(SampleRepository::class) ->disableOriginalConstructor() ->setMethods(['getList', 'delete']) ->getMockForAbstractClass(); $this->deleteHandler = (new ObjectManagerHelper($this))->getObject( DeleteHandler::class, ['sampleRepository' => $this->sampleRepositoryMock] ); } /** * Test case when provided Product has type Downloadable. */ public function testExecuteWithDownloadableProduct() { $this->entityMock->expects($this->once()) ->method('getTypeId') ->willReturn(Type::TYPE_DOWNLOADABLE); $this->entityMock->expects($this->once()) ->method('getSku') ->willReturn(self::STUB_PRODUCT_SKU); $sampleMock = $this->getMockForAbstractClass(SampleInterface::class); $sampleMock->expects($this->once()) ->method('getId') ->willReturn(self::STUB_SAMPLE_ID); $this->sampleRepositoryMock->expects($this->once())->method('delete'); $this->sampleRepositoryMock->expects($this->once()) ->method('getList') ->willReturn([$sampleMock]); $this->assertSame($this->entityMock, $this->deleteHandler->execute($this->entityMock)); } /** * Test case when provided Product is not Downloadable. */ public function testExecuteWithOtherProduct() { $this->entityMock->expects($this->once()) ->method('getTypeId') ->willReturn(self::STUB_PRODUCT_TYPE); $this->sampleRepositoryMock->expects($this->never())->method('getList'); $this->sampleRepositoryMock->expects($this->never())->method('delete'); $this->assertSame($this->entityMock, $this->deleteHandler->execute($this->entityMock)); } }