OrderPaymentPlaceEndTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 16 1
B testExecute() 0 26 1
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\Observer;
28
29
use Payone\Core\Observer\OrderPaymentPlaceEnd as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Framework\Event\Observer;
32
use Payone\Core\Helper\Consumerscore;
33
use Magento\Framework\Event;
34
use Magento\Sales\Model\Order\Payment;
35
use Magento\Payment\Model\MethodInterface;
36
use Magento\Sales\Model\Order;
37
use Payone\Core\Model\PayoneConfig;
38
use Payone\Core\Test\Unit\BaseTestCase;
39
use Payone\Core\Model\Test\PayoneObjectManager;
40
41
class OrderPaymentPlaceEndTest extends BaseTestCase
42
{
43
    /**
44
     * @var ClassToTest
45
     */
46
    private $classToTest;
47
48
    /**
49
     * @var ObjectManager|PayoneObjectManager
50
     */
51
    private $objectManager;
52
53
    protected function setUp()
54
    {
55
        $this->objectManager = $this->getObjectManager();
56
57
        $consumerscoreHelper = $this->getMockBuilder(Consumerscore::class)
58
            ->disableOriginalConstructor()
59
            ->setMethods(['getAdditionalDataEntry', 'getConsumerscoreSampleCounter', 'incrementConsumerscoreSampleCounter'])
60
            ->getMock();
61
        $consumerscoreHelper->method('getAdditionalDataEntry')->willReturn(true);
62
        $consumerscoreHelper->method('getConsumerscoreSampleCounter')->willReturn(0);
63
        $consumerscoreHelper->method('incrementConsumerscoreSampleCounter')->willReturn(1);
64
65
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
66
            'consumerscoreHelper' => $consumerscoreHelper
67
        ]);
68
    }
69
70
    public function testExecute()
71
    {
72
        $expectedStatus = 'new';
73
74
        $paymentMethod = $this->getMockBuilder(MethodInterface::class)->disableOriginalConstructor()->getMock();
75
        $paymentMethod->method('getCode')->willReturn(PayoneConfig::METHOD_CREDITCARD);
76
        $paymentMethod->method('getConfigData')->willReturn($expectedStatus);
77
78
        $order = $this->objectManager->getObject(Order::class);
79
80
        $payment = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock();
81
        $payment->method('getMethodInstance')->willReturn($paymentMethod);
82
        $payment->method('getOrder')->willReturn($order);
83
84
        $event = $this->getMockBuilder(Event::class)->disableOriginalConstructor()->setMethods(['getPayment'])->getMock();
85
        $event->method('getPayment')->willReturn($payment);
86
87
        $observer = $this->getMockBuilder(Observer::class)->disableOriginalConstructor()->getMock();
88
        $observer->method('getEvent')->willReturn($event);
89
90
        $result = $this->classToTest->execute($observer);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $this->classToTest->execute($observer) (which targets Payone\Core\Observer\Ord...mentPlaceEnd::execute()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
91
        $this->assertNull($result);
92
93
        $this->assertEquals(Order::STATE_NEW, $order->getState());
94
        $this->assertEquals($expectedStatus, $order->getStatus());
95
    }
96
}
97