Completed
Push — master ( 1a26ad...341936 )
by Florian
04:37
created

PaidTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 1
eloc 7
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\Observer\Transactionstatus;
28
29
use Payone\Core\Observer\Transactionstatus\Paid as ClassToTest;
30
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31
use Magento\Framework\Event\Observer;
32
use Magento\Sales\Model\Order;
33
use Magento\Sales\Api\Data\OrderPaymentInterface;
34
use Magento\Sales\Model\Service\InvoiceService;
35
use Magento\Sales\Model\Order\Invoice;
36
37
class PaidTest extends \PHPUnit_Framework_TestCase
38
{
39
    /**
40
     * @var ClassToTest
41
     */
42
    private $classToTest;
43
44
    /**
45
     * @var ObjectManager
46
     */
47
    private $objectManager;
48
49 View Code Duplication
    protected function setUp()
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...
50
    {
51
        $this->objectManager = new ObjectManager($this);
52
53
        $invoice = $this->getMockBuilder(Invoice::class)->disableOriginalConstructor()->getMock();
54
55
        $invoiceService = $this->getMockBuilder(InvoiceService::class)->disableOriginalConstructor()->getMock();
56
        $invoiceService->method('prepareInvoice')->willReturn($invoice);
57
58
        $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [
59
            'invoiceService' => $invoiceService
60
        ]);
61
    }
62
63
    public function testExecute()
64
    {
65
        $payment = $this->getMockBuilder(OrderPaymentInterface::class)->disableOriginalConstructor()->getMock();
66
        $payment->method('getLastTransId')->willReturn('123');
67
68
        $order = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock();
69
        $order->method('getPayment')->willReturn($payment);
70
71
        $observer = $this->getMockBuilder(Observer::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock();
72
        $observer->method('getOrder')->willReturn($order);
73
74
        $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\Tra...nstatus\Paid::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...
75
        $this->assertNull($result);
76
    }
77
78 View Code Duplication
    public function testExecuteNoOrder()
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...
79
    {
80
        $observer = $this->getMockBuilder(Observer::class)->disableOriginalConstructor()->setMethods(['getOrder'])->getMock();
81
        $observer->method('getOrder')->willReturn(null);
82
83
        $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\Tra...nstatus\Paid::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...
84
        $this->assertNull($result);
85
    }
86
}
87