Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FilterMapperTest.php
Go to the documentation of this file.
1 <?php
7 
12 
18 class FilterMapperTest extends \PHPUnit\Framework\TestCase
19 {
23  private $braintreeSearchAdapterMock;
24 
28  private $appliersPoolMock;
29 
33  private $applierMock;
34 
38  protected function setUp()
39  {
40  $methods = [
41  'id',
42  'merchantAccountId',
43  'orderId',
44  'paypalPaymentId',
45  'createdUsing',
46  'type',
47  'createdAt',
48  'amount',
49  'status',
50  'settlementBatchId',
51  'paymentInstrumentType',
52  ];
53  $this->braintreeSearchAdapterMock = $this->getMockBuilder(BraintreeSearchAdapter::class)
54  ->setMethods($methods)
55  ->disableOriginalConstructor()
56  ->getMock();
57  foreach ($methods as $method) {
58  $this->braintreeSearchAdapterMock->expects($this->once())->method($method)
59  ->willReturn(new BraintreeSearchNodeStub());
60  }
61 
62  $this->appliersPoolMock = $this->getMockBuilder(AppliersPool::class)
63  ->setMethods(['getApplier'])
64  ->disableOriginalConstructor()
65  ->getMock();
66 
67  $this->applierMock = $this->getMockBuilder(ApplierInterface::class)
68  ->setMethods(['apply'])
69  ->disableOriginalConstructor()
70  ->getMock();
71  }
72 
76  public function testGetFilterPositiveApply()
77  {
78  $this->applierMock->expects($this->exactly(3))
79  ->method('apply')
80  ->willReturn(true);
81 
82  $this->appliersPoolMock->expects($this->exactly(3))
83  ->method('getApplier')
84  ->willReturn($this->applierMock);
85 
86  $mapper = new FilterMapper($this->appliersPoolMock, $this->braintreeSearchAdapterMock);
87 
88  $result = $mapper->getFilter('id', ['eq' => 'value']);
89  $this->assertInstanceOf(BraintreeSearchNodeStub::class, $result);
90 
91  $result = $mapper->getFilter('orderId', ['eq' => 'value']);
92  $this->assertInstanceOf(BraintreeSearchNodeStub::class, $result);
93 
94  $result = $mapper->getFilter('amount', ['eq' => 'value']);
95  $this->assertInstanceOf(BraintreeSearchNodeStub::class, $result);
96  }
97 
101  public function testGetFilterNegativeApply()
102  {
103  $this->applierMock->expects($this->never())
104  ->method('apply')
105  ->willReturn(true);
106 
107  $this->appliersPoolMock->expects($this->once())
108  ->method('getApplier')
109  ->willReturn($this->applierMock);
110 
111  $mapper = new FilterMapper($this->appliersPoolMock, $this->braintreeSearchAdapterMock);
112  $result = $mapper->getFilter('orderId', []);
113  $this->assertEquals(null, $result);
114  }
115 }
$methods
Definition: billing.phtml:71
$method
Definition: info.phtml:13