-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FRW-1817 Adjusted Dynamic Multistore Test Coverage (#10800)
FRW-1817 Adjusted Dynamic Multistore Test Coverage
- Loading branch information
Showing
3 changed files
with
290 additions
and
1 deletion.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
tests/SprykerTest/Zed/Oms/Business/Mail/MailHandlerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerTest\Zed\Oms\Business\Mail; | ||
|
||
use Codeception\Test\Unit; | ||
use Generated\Shared\Transfer\MailTransfer; | ||
use Generated\Shared\Transfer\OrderTransfer; | ||
use Orm\Zed\Sales\Persistence\SpySalesOrder; | ||
use Orm\Zed\Sales\Persistence\SpySalesOrderAddress; | ||
use Spryker\Zed\Oms\Business\Mail\MailHandler; | ||
use Spryker\Zed\Oms\Dependency\Facade\OmsToMailInterface; | ||
use Spryker\Zed\Oms\Dependency\Facade\OmsToSalesInterface; | ||
use SprykerTest\Zed\Oms\OmsBusinessTester; | ||
|
||
/** | ||
* Auto-generated group annotations | ||
* | ||
* @group SprykerTest | ||
* @group Zed | ||
* @group Oms | ||
* @group Business | ||
* @group Mail | ||
* @group MailHandlerTest | ||
* Add your own group annotations below this line | ||
*/ | ||
class MailHandlerTest extends Unit | ||
{ | ||
/** | ||
* @var \SprykerTest\Zed\Oms\OmsBusinessTester | ||
*/ | ||
protected OmsBusinessTester $tester; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->tester->configureTestStateMachine([$this->tester::DEFAULT_OMS_PROCESS_NAME]); | ||
} | ||
|
||
/** | ||
* @dataProvider getMailTypes | ||
* | ||
* @param string $mailType | ||
* | ||
* @return void | ||
*/ | ||
public function testSendOrderMailExpandsMailTransferWithStore(string $mailType): void | ||
{ | ||
// Arrange | ||
$orderTransfer = $this->tester->haveOrder([], $this->tester::DEFAULT_OMS_PROCESS_NAME); | ||
$orderTransfer = $this->tester->getOrderByIdSalesOrder($orderTransfer->getIdSalesOrder()); | ||
$salesOrderEntity = (new SpySalesOrder()) | ||
->fromArray($orderTransfer->toArray()) | ||
->setBillingAddress((new SpySalesOrderAddress())->setAddress1($this->tester::FAKE_BILLING_ADDRESS)); | ||
|
||
// Assert | ||
$mailFacadeMock = $this->createMailFacadeMock(); | ||
$mailFacadeMock | ||
->expects($this->once()) | ||
->method('handleMail') | ||
->with($this->callback(function (MailTransfer $mailTransfer) use ($salesOrderEntity) { | ||
return $mailTransfer->getStoreName() === $salesOrderEntity->getStore(); | ||
})); | ||
|
||
// Act | ||
$mailHandler = new MailHandler( | ||
$this->createSalesFacadeMock($orderTransfer), | ||
$mailFacadeMock, | ||
[], | ||
); | ||
$mailHandler->{$mailType}($salesOrderEntity); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getMailTypes(): array | ||
{ | ||
return [ | ||
['sendOrderShippedMail'], | ||
['sendOrderConfirmationMail'], | ||
]; | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer | ||
* | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Oms\Dependency\Facade\OmsToSalesInterface | ||
*/ | ||
protected function createSalesFacadeMock(OrderTransfer $orderTransfer): OmsToSalesInterface | ||
{ | ||
$salesFacadeMock = $this->createMock(OmsToSalesInterface::class); | ||
$salesFacadeMock->expects($this->once()) | ||
->method('getOrderByIdSalesOrder') | ||
->willReturn($orderTransfer); | ||
|
||
return $salesFacadeMock; | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Oms\Dependency\Facade\OmsToMailInterface | ||
*/ | ||
protected function createMailFacadeMock(): OmsToMailInterface | ||
{ | ||
return $this->createMock(OmsToMailInterface::class); | ||
} | ||
} |
145 changes: 145 additions & 0 deletions
145
tests/SprykerTest/Zed/Oms/Business/Util/ReservationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerTest\Zed\Oms\Business\Util; | ||
|
||
use Codeception\Test\Unit; | ||
use Generated\Shared\Transfer\OmsProductReservationTransfer; | ||
use Generated\Shared\Transfer\ReservationRequestTransfer; | ||
use Spryker\DecimalObject\Decimal; | ||
use Spryker\Zed\Oms\Business\Reader\ReservationReaderInterface; | ||
use Spryker\Zed\Oms\Business\Util\Reservation; | ||
use Spryker\Zed\Oms\Dependency\Facade\OmsToStoreFacadeInterface; | ||
use Spryker\Zed\Oms\Persistence\OmsEntityManagerInterface; | ||
use Spryker\Zed\Oms\Persistence\OmsRepositoryInterface; | ||
use SprykerTest\Zed\Oms\OmsBusinessTester; | ||
|
||
/** | ||
* Auto-generated group annotations | ||
* | ||
* @group SprykerTest | ||
* @group Zed | ||
* @group Oms | ||
* @group Business | ||
* @group Util | ||
* @group ReservationTest | ||
* Add your own group annotations below this line | ||
*/ | ||
class ReservationTest extends Unit | ||
{ | ||
/** | ||
* @var \SprykerTest\Zed\Oms\OmsBusinessTester | ||
*/ | ||
protected OmsBusinessTester $tester; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testUpdateReservationQuantityGetsAllStores(): void | ||
{ | ||
// Arrange | ||
$reservationReaderMock = $this->createReservationReaderMock(); | ||
$storeTransfers = $this->tester->getLocator()->store()->facade()->getAllStores(); | ||
|
||
// Assert | ||
$reservationReaderMock->expects($this->once()) | ||
->method('sumReservedProductQuantitiesForSku') | ||
->willReturn(new Decimal(1)); | ||
|
||
// Act | ||
$reservation = new Reservation( | ||
$reservationReaderMock, | ||
[], | ||
$this->createStoreFacadeMock($storeTransfers), | ||
$this->createOmsRepositoryMock(count($storeTransfers)), | ||
$this->createOmsEntityManagerMock(count($storeTransfers)), | ||
[], | ||
[], | ||
); | ||
$reservation->updateReservationQuantity($this->tester::FAKE_SKU); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testUpdateReservationGetsAllStores(): void | ||
{ | ||
// Arrange | ||
$reservationRequestTransfer = new ReservationRequestTransfer(); | ||
$reservationReaderMock = $this->createReservationReaderMock(); | ||
$storeTransfers = $this->tester->getLocator()->store()->facade()->getAllStores(); | ||
|
||
// Assert | ||
$reservationReaderMock->expects($this->exactly(count($storeTransfers))) | ||
->method('sumReservedProductQuantities') | ||
->willReturn(new Decimal(1)); | ||
|
||
// Act | ||
$reservation = new Reservation( | ||
$reservationReaderMock, | ||
[], | ||
$this->createStoreFacadeMock($storeTransfers), | ||
$this->createOmsRepositoryMock(count($storeTransfers)), | ||
$this->createOmsEntityManagerMock(count($storeTransfers)), | ||
[], | ||
[], | ||
); | ||
$reservation->updateReservation($reservationRequestTransfer); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Oms\Business\Reader\ReservationReaderInterface | ||
*/ | ||
protected function createReservationReaderMock(): ReservationReaderInterface | ||
{ | ||
return $this->createMock(ReservationReaderInterface::class); | ||
} | ||
|
||
/** | ||
* @param array<\Generated\Shared\Transfer\StoreTransfer> $storeTransfers | ||
* | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Oms\Dependency\Facade\OmsToStoreFacadeInterface | ||
*/ | ||
protected function createStoreFacadeMock(array $storeTransfers): OmsToStoreFacadeInterface | ||
{ | ||
$storeFacadeMock = $this->createMock(OmsToStoreFacadeInterface::class); | ||
$storeFacadeMock->expects($this->once()) | ||
->method('getAllStores') | ||
->willReturn($storeTransfers); | ||
|
||
return $storeFacadeMock; | ||
} | ||
|
||
/** | ||
* @param int $storesCount | ||
* | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Oms\Persistence\OmsRepositoryInterface | ||
*/ | ||
protected function createOmsRepositoryMock(int $storesCount): OmsRepositoryInterface | ||
{ | ||
$omsRepositoryMock = $this->createMock(OmsRepositoryInterface::class); | ||
$omsRepositoryMock->expects($this->exactly($storesCount)) | ||
->method('findProductReservation') | ||
->willReturn(new OmsProductReservationTransfer()); | ||
|
||
return $omsRepositoryMock; | ||
} | ||
|
||
/** | ||
* @param int $storesCount | ||
* | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\Oms\Persistence\OmsEntityManagerInterface | ||
*/ | ||
protected function createOmsEntityManagerMock(int $storesCount): OmsEntityManagerInterface | ||
{ | ||
$omsEntityManagerMock = $this->createMock(OmsEntityManagerInterface::class); | ||
$omsEntityManagerMock->expects($this->exactly($storesCount)) | ||
->method('updateReservation'); | ||
|
||
return $omsEntityManagerMock; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters