GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c3368f...693668 )
by Scott van
10:56
created

ObserverTest::setUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 27
rs 8.8571
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2013-2014 eBay Enterprise, Inc.
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the Open Software License (OSL 3.0)
8
 * that is bundled with this package in the file LICENSE.md.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * @copyright   Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/)
13
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
14
 */
15
16
/**
17
 * Unit tests for @see EbayEnterprise_GiftCard_Model_Adminhtml_Observer
18
 */
19
class EbayEnterprise_GiftCard_Test_Model_Adminhtml_ObserverTest extends EbayEnterprise_Eb2cCore_Test_Base
20
{
21
    /** @var EbayEnterprise_GiftCard_Model_IContainer (mock) */
22
    protected $container;
23
    /** @var EbayEnterprise_GiftCard_Model_Giftcard (mock) */
24
    protected $giftCard;
25
    /** @var EbayEnterprise_GiftCard_Helper_Data (mock) */
26
    protected $helper;
27
    /** @var EbayEnterprise_GiftCard_Model_Adminhtml_Observer */
28
    protected $observer;
29
30
    public function setUp()
31
    {
32
        $this->container = $this->getMockForAbstractClass('EbayEnterprise_GiftCard_Model_IContainer');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...Card_Model_IContainer') of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<EbayEnterprise_GiftCard_Model_IContainer> of property $container.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
34
        $this->giftCard = $this->getModelMock('ebayenterprise_giftcard/giftcard', ['setPin']);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getModelMock('eba...card', array('setPin')) of type object<EcomDev_PHPUnit_Mock_Proxy> is incompatible with the declared type object<EbayEnterprise_GiftCard_Model_Giftcard> of property $giftCard.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
36
        $this->helper = $this->getHelperMock('ebayenterprise_giftcard', ['addGiftCardToOrder', '__']);
37
        $this->helper->method('__')->willReturnArgument(0);
38
39
        $this->session = $this->getModelMockBuilder('adminhtml/session_quote')
0 ignored issues
show
Bug introduced by
The property session does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
40
            ->setMethods(null)
41
            ->disableOriginalConstructor()
42
            ->getMock();
43
44
        $logContext = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']);
45
        $logContext->method('getMetaData')->willReturn([]);
46
47
        $this->observer = Mage::getModel(
48
            'ebayenterprise_giftcard/adminhtml_observer',
49
            [
50
                'container' => $this->container,
51
                'helper' => $this->helper,
52
                'log_context' => $logContext,
53
                'session' => $this->session
54
            ]
55
        );
56
    }
57
58
    /**
59
     * When adding a gift card to the order, the card should be retrieved from
60
     * the container by card number, have the PIN set on the card and finally
61
     * be added to the order.
62
     *
63
     * @param bool
64
     * @dataProvider provideTrueFalse
65
     */
66
    public function testAddGiftCard($success)
67
    {
68
        $cardNumber = '1111111111111111';
69
        $pin = '1234';
70
71
        $this->container
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<EbayEnterprise_GiftCard_Model_IContainer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
            ->method('getGiftCard')
73
            ->with($cardNumber)
74
            ->willReturn($this->giftCard);
75
        // Pin must be set on the gift card to be added.
76
        $this->giftCard->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<EbayEnterprise_GiftCard_Model_Giftcard>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
            ->method('setPin')
78
            ->with($this->identicalTo($pin))
79
            ->willReturnSelf();
80
81
        // Helper should be used to add the gift card to the order. When gift
82
        // card is successfully added, it should return self. Otherwise, it will
83
        // thrown an exception.
84
        $addGiftCardInvoker = $this->helper->expects($this->once())
85
            ->method('addGiftCardToOrder')
86
            ->with($this->identicalTo($this->giftCard), $this->identicalTo($this->container));
87
88
        if ($success) {
89
            $addGiftCardInvoker->willReturnSelf();
90
        } else {
91
            $addGiftCardInvoker->willThrowException(new EbayEnterprise_GiftCard_Exception('TEST EXCEPTION: ' . __METHOD__));
92
        }
93
94
        $this->assertSame(
95
            $this->observer,
96
            EcomDev_Utils_Reflection::invokeRestrictedMethod($this->observer, 'addGiftCard', [$cardNumber, $pin])
97
        );
98
99
        // When gift card added successfully, expect a success message to have
100
        // been added to the session. When unsuccessful, should add an error
101
        // message to the session.
102
        $expectMessageType = $success ? Mage_Core_Model_Message::SUCCESS : Mage_Core_Model_Message::ERROR;
103
        $this->assertCount(1, $this->session->getMessages()->getItemsByType($expectMessageType));
104
    }
105
}
106