Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
PlaceOrderDefaultTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
17 class PlaceOrderDefaultTest extends \PHPUnit\Framework\TestCase
18 {
22  private $orderManagement;
23 
27  private $placeOrderDefault;
28 
32  protected function setUp()
33  {
34  $this->orderManagement = $this->getMockForAbstractClass(OrderManagementInterface::class);
35 
36  $this->placeOrderDefault = new PlaceOrderDefault($this->orderManagement);
37  }
38 
39  public function testPlace()
40  {
41  $incrementId = '000000001';
42 
43  $order = $this->getMockForAbstractClass(OrderInterface::class);
44  $order->method('getIncrementId')->willReturn($incrementId);
45  $orderList = [$order];
46 
47  $this->orderManagement->expects($this->once())
48  ->method('place')
49  ->with($order)
50  ->willReturn($order);
51  $errors = $this->placeOrderDefault->place($orderList);
52 
53  $this->assertEmpty($errors);
54  }
55 
56  public function testPlaceWithErrors()
57  {
58  $incrementId = '000000001';
59 
60  $order = $this->getMockForAbstractClass(OrderInterface::class);
61  $order->method('getIncrementId')->willReturn($incrementId);
62  $orderList = [$order];
63 
64  $exception = new \Exception('error');
65  $this->orderManagement->method('place')->willThrowException($exception);
66  $errors = $this->placeOrderDefault->place($orderList);
67 
68  $this->assertEquals(
69  [$incrementId => $exception],
70  $errors
71  );
72  }
73 }
$order
Definition: order.php:55
$errors
Definition: overview.phtml:9