This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 Magento\Catalog\Block\ShortcutButtons; |
||
30 | use Magento\Framework\Event; |
||
31 | use Magento\Framework\Event\Observer; |
||
32 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
||
33 | use Magento\Framework\View\LayoutInterface; |
||
34 | use Magento\Paypal\Block\Express\Shortcut; |
||
35 | use Payone\Core\Helper\Payment; |
||
36 | use Payone\Core\Observer\AddPaypalExpressButtons as ClassToTest; |
||
37 | use Payone\Core\Test\Unit\BaseTestCase; |
||
38 | use Payone\Core\Model\Test\PayoneObjectManager; |
||
39 | |||
40 | class AddPaypalExpressButtonTest extends BaseTestCase |
||
41 | { |
||
42 | /** |
||
43 | * @var ClassToTest |
||
44 | */ |
||
45 | private $classToTest; |
||
46 | |||
47 | /** |
||
48 | * @var ObjectManager|PayoneObjectManager |
||
49 | */ |
||
50 | private $objectManager; |
||
51 | |||
52 | /** |
||
53 | * @var Payment|\PHPUnit_Framework_MockObject_MockObject |
||
54 | */ |
||
55 | private $paymentHelper; |
||
56 | |||
57 | View Code Duplication | protected function setUp() |
|
0 ignored issues
–
show
|
|||
58 | { |
||
59 | $this->objectManager = $this->getObjectManager(); |
||
60 | |||
61 | $this->paymentHelper = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock(); |
||
62 | |||
63 | $this->classToTest = $this->objectManager->getObject(ClassToTest::class, [ |
||
64 | 'paymentHelper' => $this->paymentHelper |
||
65 | ]); |
||
66 | } |
||
67 | |||
68 | View Code Duplication | public function testExecutePaypalInactive() |
|
0 ignored issues
–
show
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. ![]() |
|||
69 | { |
||
70 | $this->paymentHelper->method('isPayPalExpressActive')->willReturn(false); |
||
71 | $observer = $this->getMockBuilder(Observer::class)->disableOriginalConstructor()->getMock(); |
||
72 | |||
73 | $result = $this->classToTest->execute($observer); |
||
0 ignored issues
–
show
Are you sure the assignment to
$result is correct as $this->classToTest->execute($observer) (which targets Payone\Core\Observer\Add...pressButtons::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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
74 | $this->assertNull($result); |
||
75 | } |
||
76 | |||
77 | View Code Duplication | public function testExecutePaypalActive() |
|
0 ignored issues
–
show
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. ![]() |
|||
78 | { |
||
79 | $this->paymentHelper->method('isPayPalExpressActive')->willReturn(true); |
||
80 | |||
81 | $shortcut = $this->getMockBuilder(Shortcut::class)->disableOriginalConstructor()->getMock(); |
||
82 | |||
83 | $layout = $this->getMockBuilder(LayoutInterface::class)->disableOriginalConstructor()->getMock(); |
||
84 | $layout->method('createBlock')->willReturn($shortcut); |
||
85 | |||
86 | $shortcutButtons = $this->getMockBuilder(ShortcutButtons::class)->disableOriginalConstructor()->getMock(); |
||
87 | $shortcutButtons->method('getLayout')->willReturn($layout); |
||
88 | |||
89 | $event = $this->getMockBuilder(Event::class) |
||
90 | ->disableOriginalConstructor() |
||
91 | ->setMethods(['getContainer']) |
||
92 | ->getMock(); |
||
93 | $event->method('getContainer')->willReturn($shortcutButtons); |
||
94 | |||
95 | $observer = $this->getMockBuilder(Observer::class)->disableOriginalConstructor()->getMock(); |
||
96 | $observer->method('getEvent')->willReturn($event); |
||
97 | |||
98 | $executed = false; |
||
0 ignored issues
–
show
$executed is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
99 | |||
100 | /** @var Observer $observer */ |
||
101 | $this->classToTest->execute($observer); |
||
102 | $executed = true; |
||
103 | $this->assertTrue($executed); |
||
104 | } |
||
105 | |||
106 | View Code Duplication | public function testExecutePaypalActiveAddToCart() |
|
0 ignored issues
–
show
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. ![]() |
|||
107 | { |
||
108 | $this->paymentHelper->method('isPayPalExpressActive')->willReturn(true); |
||
109 | |||
110 | $shortcut = $this->getMockBuilder(Shortcut::class)->disableOriginalConstructor()->getMock(); |
||
111 | |||
112 | $layout = $this->getMockBuilder(LayoutInterface::class)->disableOriginalConstructor()->getMock(); |
||
113 | $layout->method('createBlock')->willReturn($shortcut); |
||
114 | |||
115 | $shortcutButtons = $this->getMockBuilder(ShortcutButtons::class)->disableOriginalConstructor()->getMock(); |
||
116 | $shortcutButtons->method('getNameInLayout')->willReturn('addtocart.shortcut.buttons'); |
||
117 | $shortcutButtons->method('getLayout')->willReturn($layout); |
||
118 | |||
119 | $event = $this->getMockBuilder(Event::class) |
||
120 | ->disableOriginalConstructor() |
||
121 | ->setMethods(['getContainer']) |
||
122 | ->getMock(); |
||
123 | $event->method('getContainer')->willReturn($shortcutButtons); |
||
124 | |||
125 | $observer = $this->getMockBuilder(Observer::class)->disableOriginalConstructor()->getMock(); |
||
126 | $observer->method('getEvent')->willReturn($event); |
||
127 | |||
128 | $executed = false; |
||
0 ignored issues
–
show
$executed is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
129 | |||
130 | /** @var Observer $observer */ |
||
131 | $this->classToTest->execute($observer); |
||
132 | $executed = true; |
||
133 | $this->assertTrue($executed); |
||
134 | } |
||
135 | } |
||
136 |
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.