Completed
Push — master ( 9d3f5c...f136ad )
by Aimeos
02:22
created

BaseTest::testCreateAddressItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Customer\Decorator;
10
11
12
class BaseTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $stub;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Customer\Standard' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Customer\Decorator\Base' )
28
			->setConstructorArgs( [$this->stub, $this->context] )
29
			->getMockForAbstractClass();
30
	}
31
32
33
	protected function tearDown()
34
	{
35
		unset( $this->context, $this->object, $this->stub );
36
	}
37
38
39
	public function testConstructException()
40
	{
41
		$stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Iface' )->getMock();
42
43
		$this->setExpectedException( '\Aimeos\Controller\Frontend\Exception' );
44
45
		$this->getMockBuilder( '\Aimeos\Controller\Frontend\Customer\Decorator\Base' )
46
			->setConstructorArgs( [$stub, $this->context] )
47
			->getMockForAbstractClass();
48
	}
49
50
51
	public function testCall()
52
	{
53
		$stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Customer\Standard' )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Customer\Decorator\Base' )
59
			->setConstructorArgs( [$stub, $this->context] )
60
			->getMockForAbstractClass();
61
62
		$stub->expects( $this->once() )->method( 'invalid' )->will( $this->returnValue( true ) );
63
64
		$this->assertTrue( $object->invalid() );
65
	}
66
67
68
	public function testAddItem()
69
	{
70
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->createItem();
71
72
		$this->stub->expects( $this->once() )->method( 'addItem' )
73
			->will( $this->returnValue( $item ) );
74
75
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $this->object->addItem( [] ) );
76
	}
77
78
79
	public function testCreateItem()
80
	{
81
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->createItem();
82
83
		$this->stub->expects( $this->once() )->method( 'createItem' )
84
			->will( $this->returnValue( $item ) );
85
86
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $this->object->createItem() );
87
	}
88
89
90
	public function testDeleteItem()
91
	{
92
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->createItem();
0 ignored issues
show
Unused Code introduced by
$item 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
93
94
		$this->stub->expects( $this->once() )->method( 'deleteItem' );
95
96
		$this->object->deleteItem( -1 );
97
	}
98
99
100
	public function testEditItem()
101
	{
102
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->createItem();
103
104
		$this->stub->expects( $this->once() )->method( 'editItem' )
105
			->will( $this->returnValue( $item ) );
106
107
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $this->object->editItem( -1, [] ) );
108
	}
109
110
111
	public function testGetItem()
112
	{
113
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->createItem();
114
115
		$this->stub->expects( $this->once() )->method( 'getItem' )
116
			->will( $this->returnValue( $item ) );
117
118
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $this->object->getItem( -1 ) );
119
	}
120
121
122
	public function testFindItem()
123
	{
124
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->createItem();
125
126
		$this->stub->expects( $this->once() )->method( 'findItem' )
127
			->will( $this->returnValue( $item ) );
128
129
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $this->object->findItem( 'test' ) );
130
	}
131
132
133
	public function testSaveItem()
134
	{
135
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->createItem();
136
137
		$this->stub->expects( $this->once() )->method( 'saveItem' );
138
139
		$this->object->saveItem( $item );
140
	}
141
142
143
	public function testCreateAddressItem()
144
	{
145
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/address' )->createItem();
146
147
		$this->stub->expects( $this->once() )->method( 'createAddressItem' )
148
			->will( $this->returnValue( $item ) );
149
150
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $this->object->createAddressItem() );
151
	}
152
153
154
	public function testDeleteAddressItem()
155
	{
156
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/address' )->createItem();
0 ignored issues
show
Unused Code introduced by
$item 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
157
158
		$this->stub->expects( $this->once() )->method( 'deleteAddressItem' );
159
160
		$this->object->deleteAddressItem( -1 );
161
	}
162
163
164
	public function testEditAddressItem()
165
	{
166
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/address' )->createItem();
167
168
		$this->stub->expects( $this->once() )->method( 'editAddressItem' )
169
			->will( $this->returnValue( $item ) );
170
171
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $this->object->editAddressItem( -1, [] ) );
172
	}
173
174
175
	public function testGetAddressItem()
176
	{
177
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/address' )->createItem();
178
179
		$this->stub->expects( $this->once() )->method( 'getAddressItem' )
180
			->will( $this->returnValue( $item ) );
181
182
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $this->object->getAddressItem( -1 ) );
183
	}
184
185
186
	public function testSaveAddressItem()
187
	{
188
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/address' )->createItem();
189
190
		$this->stub->expects( $this->once() )->method( 'saveAddressItem' );
191
192
		$this->object->saveAddressItem( $item );
193
	}
194
195
196
	public function testGetController()
197
	{
198
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
199
200
		$this->assertSame( $this->stub, $result );
201
	}
202
203
204
	protected function access( $name )
205
	{
206
		$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Customer\Decorator\Base' );
207
		$method = $class->getMethod( $name );
208
		$method->setAccessible( true );
209
210
		return $method;
211
	}
212
}
213