Created
September 25, 2014 11:02
-
-
Save up1/f8d16be2495e0f960f0e to your computer and use it in GitHub Desktop.
Demo :: 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
<?php | |
class OrderServiceUnitTest extends PHPUnit_Framework_TestCase { | |
private $mockOrderRepository; | |
private $mockEmailSender; | |
private $orderService; | |
function setUp() { | |
$this->mockOrderRepository = $this->getMock('OrderRepository'); | |
$this->mockEmailSender = $this->getMock('EmailSender'); | |
} | |
function testOrderingProductSuccessWithoutSendEmailToConfirm() { | |
$input = array( | |
'product_id' => 123, | |
'user_id' => 1, | |
'order_date' => time() | |
); | |
$order = new Order($input['product_id'], $input['user_id'], $input['order_date']); | |
$this->orderService = new OrderService(); | |
$this->orderService->setOrderRepository($this->mockOrderRepository); | |
$this->mockOrderRepository->expects($this->once())->method('persist')->with($order); | |
$this->orderService->setEmailSender($this->mockEmailSender); | |
$this->orderService->save($input); | |
} | |
function testOrderingProductSuccessWithSendEmailToConfirm() { | |
$input = array( | |
'product_id' => 123, | |
'user_id' => 1, | |
'order_date' => time() | |
); | |
$order = new Order($input['product_id'], $input['user_id'], $input['order_date']); | |
$email = new Email('[email protected]'); | |
$this->orderService = new OrderService(); | |
$this->orderService->setOrderRepository($this->mockOrderRepository); | |
$this->mockOrderRepository->expects($this->once())->method('persist')->with($order); | |
$this->orderService->setEmailSender($this->mockEmailSender); | |
$this->mockEmailSender->expects($this->once())->method('send')->with($email); | |
$this->orderService->save($input); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment