1 | <?php |
||
11 | class RequestBuilderTest extends \PHPUnit_Framework_TestCase |
||
12 | { |
||
13 | /** |
||
14 | * @var PreApproval|\PHPUnit_Framework_MockObject_MockObject |
||
15 | */ |
||
16 | private $approval; |
||
17 | |||
18 | protected function setUp() |
||
19 | { |
||
20 | $this->approval = $this->createMock(PreApproval::class); |
||
21 | |||
22 | $this->approval->expects($this->once()) |
||
23 | ->method('setChargeType') |
||
24 | ->with(ChargeType::AUTOMATIC); |
||
25 | |||
26 | $this->mockRequest = $this->createMock(Request::class); |
||
27 | } |
||
28 | |||
29 | public function testContructShouldSetterChargeTypeAndInstanceofInterface() |
||
30 | { |
||
31 | $this->mockRequest->expects($this->once())->method('getPreApproval')->willReturn($this->approval); |
||
32 | |||
33 | $builder = new RequestBuilder(false, $this->mockRequest); |
||
34 | |||
35 | $this->assertInstanceOf(RequestBuilderInterface::class, $builder); |
||
36 | $this->assertAttributeEquals($this->mockRequest, 'request', $builder); |
||
37 | $this->assertEquals($this->mockRequest, $builder->getRequest()); |
||
38 | } |
||
39 | |||
40 | public function testSetterRequestShouldReturnSelfObject() |
||
41 | { |
||
42 | $customer = $this->createMock(Customer::class); |
||
43 | |||
44 | $this->mockRequest->expects($this->once())->method('getPreApproval')->willReturn($this->approval); |
||
45 | $this->mockRequest->expects($this->once())->method('setCustomer')->with($customer); |
||
46 | $this->mockRequest->expects($this->once())->method('setRedirectTo')->with('http://redirect'); |
||
47 | $this->mockRequest->expects($this->once())->method('setReference')->with('ABCDEF'); |
||
48 | $this->mockRequest->expects($this->once())->method('setReviewOn')->with('http://review'); |
||
49 | |||
50 | $builder = new RequestBuilder(false, $this->mockRequest); |
||
51 | |||
52 | $this->assertEquals($builder, $builder->setCustomer($customer)); |
||
53 | $this->assertEquals($builder, $builder->setRedirectTo('http://redirect')); |
||
54 | $this->assertEquals($builder, $builder->setReference('ABCDEF')); |
||
55 | $this->assertEquals($builder, $builder->setReviewOn('http://review')); |
||
56 | } |
||
57 | |||
58 | public function testSetterPreApprovalShouldReturnSelfObject() |
||
59 | { |
||
60 | $this->mockRequest->expects($this->exactly(11))->method('getPreApproval')->willReturn($this->approval); |
||
61 | |||
62 | $this->approval->expects($this->once())->method('setName')->with('FooBar'); |
||
63 | $this->approval->expects($this->once())->method('setDetails')->with('Details Foo Bar'); |
||
64 | $this->approval->expects($this->once())->method('setFinalDate')->with(new DateTime('2016-11-18')); |
||
65 | $this->approval->expects($this->once())->method('setMaxTotalAmount')->with(2000); |
||
66 | $this->approval->expects($this->once())->method('setPeriod')->with('WEEKLY'); |
||
67 | $this->approval->expects($this->once())->method('setAmountPerPayment')->with(123.56); |
||
68 | $this->approval->expects($this->once())->method('setMaxAmountPerPayment')->with(97); |
||
69 | $this->approval->expects($this->once())->method('setMaxPaymentsPerPeriod')->with(544.87); |
||
70 | $this->approval->expects($this->once())->method('setMaxAmountPerPeriod')->with(5432.90); |
||
71 | $this->approval->expects($this->once())->method('setInitialDate')->with(new DateTime('2015-11-18')); |
||
72 | |||
73 | $builder = new RequestBuilder(false, $this->mockRequest); |
||
74 | |||
75 | $this->assertEquals($builder, $builder->setName('FooBar')); |
||
76 | $this->assertEquals($builder, $builder->setDetails('Details Foo Bar')); |
||
77 | $this->assertEquals($builder, $builder->setFinalDate(new DateTime('2016-11-18'))); |
||
78 | $this->assertEquals($builder, $builder->setMaxTotalAmount(2000)); |
||
79 | $this->assertEquals($builder, $builder->setPeriod('WEEKLY')); |
||
87 |