generationSpecFactoryMock = $this->getMockBuilder(CouponGenerationSpecInterfaceFactory::class) ->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->couponManagementServiceMock = $this->createMock(CouponManagementService::class); $this->generationSpecMock = $this->createMock(CouponGenerationSpecInterface::class); $this->couponGenerator = new CouponGenerator( $this->couponManagementServiceMock, $this->generationSpecFactoryMock ); } /** * Test beforeSave method * * @return void */ public function testBeforeSave() { $expected = ['test']; $this->generationSpecFactoryMock->expects($this->once())->method('create') ->willReturn($this->generationSpecMock); $this->couponManagementServiceMock->expects($this->once())->method('generate') ->with($this->generationSpecMock)->willReturn($expected); $actual = $this->couponGenerator->generateCodes([]); self::assertEquals($expected, $actual); } }