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

CartControllerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 123
Duplicated Lines 40.65 %

Coupling/Cohesion

Components 1
Dependencies 6
Metric Value
wmc 4
lcom 1
cbo 6
dl 50
loc 123
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 25 1
B testAddAction() 25 25 1
B testAddFail() 25 25 1
A testRemoveAction() 0 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
require_once 'EbayEnterprise/GiftCard/controllers/CartController.php';
17
18
class EbayEnterprise_GiftCard_Test_Model_CartControllerTest extends EbayEnterprise_Eb2cCore_Test_Base
19
{
20
    const REDIRECT_PATH = EbayEnterprise_GiftCard_CartController::REDIRECT_PATH;
21
22
    protected $container;
23
    protected $giftCard;
24
    protected $helper;
25
    protected $controller;
26
    protected $giftCardNumber = 'somecardnumber';
27
    protected $giftCardPin = '12345678';
28
    protected $checkoutSession;
29
30
    // prepare mocks
31
    public function setUp()
32
    {
33
        $this->helper = $this->getHelperMock('ebayenterprise_giftcard/data');
34
        $this->helper->expects($this->any())
35
            ->method('__')->with($this->isType('string'))->will($this->returnArgument(0));
36
        // disable constructor to prevent having to mock dependencies
37
        $this->checkoutSession = $this->getModelMockBuilder('checkout/session')->disableOriginalConstructor()
38
            ->setMethods(null)->getMock();
39
        $this->giftCard = $this->getMock('EbayEnterprise_GiftCard_Model_IGiftcard');
40
        $this->giftCard->expects($this->any())
41
            ->method('setPin')->with($this->isType('string'))->will($this->returnSelf());
42
        // disable constructor to avoid mocking dependencies
43
        $this->container = $this->getMockBuilder('EbayEnterprise_GiftCard_Model_IContainer')->disableOriginalConstructor()
44
            ->getMock();
45
        $this->container->expects($this->any())
46
            ->method('getGiftCard')->will($this->returnValue($this->giftCard));
47
        // disable constructor to avoid mocking dependencies
48
        $this->controller = $this->getMockBuilder('EbayEnterprise_GiftCard_CartController')->disableOriginalConstructor()
49
            ->setMethods(['_redirect', '_rewrite', 'setFlag', '_getCardInfoFromRequest'])->getMock();
50
        $this->controller->expects($this->once())
51
            ->method('_getCardInfoFromRequest')->will($this->returnValue([$this->giftCardNumber, $this->giftCardPin]));
52
        // inject mocked dependencies
53
        EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->controller, '_container', $this->container);
54
        EcomDev_Utils_Reflection::setRestrictedPropertyValue($this->controller, '_helper', $this->helper);
55
    }
56
57
    /**
58
     * verify:
59
     *   - controller uses account number and pin to get a giftcard instance to work with.
60
     *   - controller will call the check balance function only once
61
     *   - controller will add the giftCard back to the container on success.
62
     *   - controller will add a translated success message to the session.
63
     *   - controller will attempt to redirect back to cart page when done.
64
     */
65 View Code Duplication
    public function testAddAction()
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...
66
    {
67
        $this->giftCard->expects($this->once())
68
            ->method('setPin')
69
            ->with($this->identicalTo($this->giftCardPin))
70
            ->will($this->returnSelf());
71
        $this->helper
72
            ->expects($this->once())
73
            ->method('addGiftCardToOrder')
74
            ->with($this->identicalTo($this->giftCard), $this->identicalTo($this->container))
75
            ->will($this->returnSelf());
76
        $this->controller
77
            ->expects($this->once())
78
            ->method('_redirect')
79
            ->with($this->identicalTo(self::REDIRECT_PATH))
80
            ->willReturnSelf();
81
82
        // inject the session mock
83
        $this->replaceByMock('singleton', 'checkout/session', $this->checkoutSession);
84
        $this->controller->addAction();
85
86
        // Successfully adding gift card to order should result in success message
87
        // being added to checkout session.
88
        $this->assertCount(1, $this->checkoutSession->getMessages()->getItemsByType(Mage_Core_Model_Message::SUCCESS));
89
    }
90
91
    /**
92
     * verify:
93
     * - when gift card cannot be added to the order, an error message is added
94
     *   to the checkout session
95
     */
96 View Code Duplication
    public function testAddFail()
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...
97
    {
98
        $this->giftCard->expects($this->once())
99
            ->method('setPin')
100
            ->with($this->identicalTo($this->giftCardPin))
101
            ->will($this->returnSelf());
102
        $this->helper
103
            ->expects($this->once())
104
            ->method('addGiftCardToOrder')
105
            ->with($this->identicalTo($this->giftCard), $this->identicalTo($this->container))
106
            ->willThrowException(new EbayEnterprise_GiftCard_Exception('TEST EXCEPTION: ' . __METHOD__));
107
        $this->controller
108
            ->expects($this->once())
109
            ->method('_redirect')
110
            ->with($this->identicalTo(self::REDIRECT_PATH))
111
            ->will($this->returnSelf());
112
113
        // inject the session mock
114
        $this->replaceByMock('singleton', 'checkout/session', $this->checkoutSession);
115
        $this->controller->addAction();
116
117
        // Failure to add gift card to the order should result in an error message
118
        // being added to the checkout session.
119
        $this->assertCount(1, $this->checkoutSession->getMessages()->getErrors());
120
    }
121
122
    /**
123
     * verify:
124
     *   - controller uses account number and pin to get a giftcard instance to work with.
125
     *   - controller will use the container to remove the gift card.
126
     *   - controller will attempt to redirect back to cart page when done.
127
     */
128
    public function testRemoveAction()
129
    {
130
        $this->container->expects($this->once())
131
            ->method('removeGiftCard')->with($this->isInstanceOf('EbayEnterprise_GiftCard_Model_IGiftcard'))
132
            ->will($this->returnSelf());
133
        $this->controller->expects($this->once())
134
            ->method('_redirect')->with($this->identicalTo(self::REDIRECT_PATH))->will($this->returnSelf());
135
136
        // inject the session mock
137
        $this->replaceByMock('singleton', 'checkout/session', $this->checkoutSession);
138
        $this->controller->removeAction();
139
    }
140
}
141