|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\SalesRule\Test\Unit\Model; |
| 9 | + |
| 10 | +use Magento\SalesRule\Api\Data\CouponGenerationSpecInterface; |
| 11 | +use Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory; |
| 12 | +use Magento\SalesRule\Model\CouponGenerator; |
| 13 | +use Magento\SalesRule\Model\Service\CouponManagementService; |
| 14 | + |
| 15 | +/** |
| 16 | + * @covers \Magento\SalesRule\Model\CouponGenerator |
| 17 | + */ |
| 18 | +class CouponGeneratorTest extends \PHPUnit\Framework\TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * Testable Object |
| 22 | + * |
| 23 | + * @var CouponGenerator |
| 24 | + */ |
| 25 | + private $couponGenerator; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var CouponManagementService|\PHPUnit_Framework_MockObject_MockObject |
| 29 | + */ |
| 30 | + private $couponManagementServiceMock; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var CouponGenerationSpecInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject |
| 34 | + */ |
| 35 | + private $generationSpecFactoryMock; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var CouponGenerationSpecInterface|\PHPUnit_Framework_MockObject_MockObject |
| 39 | + */ |
| 40 | + private $generationSpecMock; |
| 41 | + |
| 42 | + /** |
| 43 | + * Set Up |
| 44 | + * |
| 45 | + * @return void |
| 46 | + */ |
| 47 | + protected function setUp() |
| 48 | + { |
| 49 | + $this->generationSpecFactoryMock = $this->getMockBuilder(CouponGenerationSpecInterfaceFactory::class) |
| 50 | + ->disableOriginalConstructor()->setMethods(['create'])->getMock(); |
| 51 | + $this->couponManagementServiceMock = $this->createMock(CouponManagementService::class); |
| 52 | + $this->generationSpecMock = $this->createMock(CouponGenerationSpecInterface::class); |
| 53 | + $this->couponGenerator = new CouponGenerator( |
| 54 | + $this->couponManagementServiceMock, |
| 55 | + $this->generationSpecFactoryMock |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Test beforeSave method |
| 61 | + * |
| 62 | + * @return void |
| 63 | + */ |
| 64 | + public function testBeforeSave() |
| 65 | + { |
| 66 | + $expected = ['test']; |
| 67 | + $this->generationSpecFactoryMock->expects($this->once())->method('create') |
| 68 | + ->willReturn($this->generationSpecMock); |
| 69 | + $this->couponManagementServiceMock->expects($this->once())->method('generate') |
| 70 | + ->with($this->generationSpecMock)->willReturn($expected); |
| 71 | + $actual = $this->couponGenerator->generateCodes([]); |
| 72 | + self::assertEquals($expected, $actual); |
| 73 | + } |
| 74 | +} |
0 commit comments