Completed
Push — master ( 0dbe68...17d58d )
by Florian
04:25
created

ReviewTest::testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 8
loc 8
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2017 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Test\Unit\Controller\Onepage;
28
29
use Magento\Quote\Model\Quote;
30
use Payone\Core\Controller\Onepage\Review as ClassToTest;
31
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
32
use Magento\Checkout\Model\Session;
33
use Magento\Framework\App\Action\Context;
34
use Magento\Framework\App\Request\Http;
35
use Magento\Quote\Model\Quote\Address;
36
use Magento\Framework\View\Result\PageFactory;
37
use Magento\Framework\View\Result\Page;
38
use Magento\Framework\Controller\ResultFactory;
39
use Magento\Framework\Controller\Result\Redirect;
40
use Magento\Quote\Api\Data\CartExtension;
41
use Magento\Quote\Model\ShippingAssignment;
42
use Magento\Quote\Model\Shipping;
43
44
class ReviewTest extends \PHPUnit_Framework_TestCase
45
{
46
    /**
47
     * @var ClassToTest
48
     */
49
    private $classToTest;
50
51
    /**
52
     * @var ObjectManager
53
     */
54
    private $objectManager;
55
56
    /**
57
     * @var Session|\PHPUnit_Framework_MockObject_MockObject
58
     */
59
    private $checkoutSession;
60
61
    /**
62
     * @var Redirect|\PHPUnit_Framework_MockObject_MockObject
63
     */
64
    private $request;
65
66
    protected function setUp()
67
    {
68
        $this->objectManager = new ObjectManager($this);
69
70
        $this->request = $this->getMockBuilder(Http::class)->disableOriginalConstructor()->getMock();
71
        $this->request->method('getParam')->willReturn('free');
72
73
        $redirect = $this->getMockBuilder(Redirect::class)->disableOriginalConstructor()->getMock();
74
        $redirect->method('setPath')->willReturn($redirect);
75
76
        $resultFactory = $this->getMockBuilder(ResultFactory::class)->disableOriginalConstructor()->getMock();
77
        $resultFactory->method('create')->willReturn($redirect);
78
79
        $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
80
        $context->method('getRequest')->willReturn($this->request);
81
        $context->method('getResultFactory')->willReturn($resultFactory);
82
83
        $address = $this->getMockBuilder(Address::class)
84
            ->disableOriginalConstructor()
85
            ->setMethods(['getShippingMethod', 'setShippingMethod'])
86
            ->getMock();
87
        $address->method('getShippingMethod')->willReturn('not_free');
88
        $address->method('setShippingMethod')->willReturn($address);
89
90
        $shipping = $this->getMockBuilder(Shipping::class)->disableOriginalConstructor()->getMock();
91
92
        $assignment = $this->getMockBuilder(ShippingAssignment::class)->disableOriginalConstructor()->getMock();
93
        $assignment->method('getShipping')->willReturn($shipping);
94
95
        $cartExtension = $this->getMockBuilder(CartExtension::class)->disableOriginalConstructor()->getMock();
96
        $cartExtension->method('getShippingAssignments')->willReturn([$assignment]);
97
98
        $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock();
99
        $quote->method('getBillingAddress')->willReturn($address);
100
        $quote->method('getShippingAddress')->willReturn($address);
101
        $quote->method('getIsVirtual')->willReturn(false);
102
        $quote->method('getExtensionAttributes')->willReturn($cartExtension);
103
104
        $this->checkoutSession = $this->getMockBuilder(Session::class)
105
            ->disableOriginalConstructor()
106
            ->setMethods(['getQuote', 'getPayoneWorkorderId'])
107
            ->getMock();
108
        $this->checkoutSession->method('getQuote')->willReturn($quote);
109
110
        $page = $this->getMockBuilder(Page::class)->disableOriginalConstructor()->getMock();
111
112
        $pageFactory = $this->getMockBuilder(PageFactory::class)->disableOriginalConstructor()->getMock();
113
        $pageFactory->method('create')->willReturn($page);
114
115
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
116
            'context' => $context,
117
            'checkoutSession' => $this->checkoutSession,
118
            'pageFactory' => $pageFactory
119
        ]);
120
    }
121
122 View Code Duplication
    public function testExecute()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
    {
124
        $this->checkoutSession->method('getPayoneWorkorderId')->willReturn(null);
125
126
        $this->request->method('getBeforeForwardInfo')->willReturn(false);
127
        $result = $this->classToTest->execute();
128
        $this->assertInstanceOf(Redirect::class, $result);
129
    }
130
131 View Code Duplication
    public function testExecuteRedirect()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
132
    {
133
        $this->checkoutSession->method('getPayoneWorkorderId')->willReturn('12345');
134
135
        $this->request->method('getBeforeForwardInfo')->willReturn(false);
136
        $result = $this->classToTest->execute();
137
        $this->assertInstanceOf(Page::class, $result);
138
    }
139
}
140