Passed
Push — master ( cb7c44...75ed13 )
by Aimeos
01:47
created

BaseTest::testDeleteAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2018
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Basket\Decorator;
10
11
12
class BaseTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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\Basket\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Basket\Decorator\Base::class )
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::class )->getMock();
42
43
		$this->setExpectedException( \Aimeos\MW\Common\Exception::class );
44
45
		$this->getMockBuilder( \Aimeos\Controller\Frontend\Basket\Decorator\Base::class )
46
			->setConstructorArgs( [$stub, $this->context] )
47
			->getMockForAbstractClass();
48
	}
49
50
51
	public function testCall()
52
	{
53
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Basket\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Basket\Decorator\Base::class )
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 testAdd()
69
	{
70
		$this->stub->expects( $this->once() )->method( 'add' );
71
		$this->assertSame( $this->object, $this->object->add( [] ) );
72
	}
73
74
75
	public function testClear()
76
	{
77
		$this->stub->expects( $this->once() )->method( 'clear' );
78
		$this->assertSame( $this->object, $this->object->clear() );
79
	}
80
81
82
	public function testGet()
83
	{
84
		$context = \TestHelperFrontend::getContext();
85
		$order = \Aimeos\MShop::create( $context, 'order/base' )->createItem();
86
87
		$this->stub->expects( $this->once() )->method( 'get' )->will( $this->returnValue( $order ) );
88
89
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $this->object->get() );
90
	}
91
92
93
	public function testSave()
94
	{
95
		$this->stub->expects( $this->once() )->method( 'save' );
96
		$this->assertSame( $this->object, $this->object->save() );
97
	}
98
99
100
	public function testSetType()
101
	{
102
		$this->stub->expects( $this->once() )->method( 'setType' );
103
		$this->assertSame( $this->object, $this->object->setType( 'test' ) );
104
	}
105
106
107
	public function testStore()
108
	{
109
		$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->createItem();
110
111
		$this->stub->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $basket ) );
112
113
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $this->object->store() );
114
	}
115
116
117
	public function testLoad()
118
	{
119
		$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->createItem();
120
121
		$this->stub->expects( $this->once() )->method( 'load' )->will( $this->returnValue( $basket ) );
122
123
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $this->object->load( -1 ) );
124
	}
125
126
127
	public function testAddProduct()
128
	{
129
		$product = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
130
131
		$this->stub->expects( $this->once() )->method( 'addProduct' );
132
133
		$this->assertSame( $this->object, $this->object->addProduct( $product ) );
134
	}
135
136
137
	public function testDeleteProduct()
138
	{
139
		$this->stub->expects( $this->once() )->method( 'deleteProduct' );
140
141
		$this->assertSame( $this->object, $this->object->deleteProduct( 0 ) );
142
	}
143
144
145
	public function testUpdateProduct()
146
	{
147
		$this->stub->expects( $this->once() )->method( 'updateProduct' );
148
149
		$this->assertSame( $this->object, $this->object->updateProduct( 0, 1 ) );
150
	}
151
152
153
	public function testAddCoupon()
154
	{
155
		$this->stub->expects( $this->once() )->method( 'addCoupon' );
156
157
		$this->assertSame( $this->object, $this->object->addCoupon( 'test' ) );
158
	}
159
160
161
	public function testDeleteCoupon()
162
	{
163
		$this->stub->expects( $this->once() )->method( 'deleteCoupon' );
164
165
		$this->assertSame( $this->object, $this->object->deleteCoupon( 'test' ) );
166
	}
167
168
169
	public function testAddAddress()
170
	{
171
		$this->stub->expects( $this->once() )->method( 'addAddress' );
172
173
		$this->assertSame( $this->object, $this->object->addAddress( 'payment', [] ) );
174
	}
175
176
177
	public function testDeleteAddress()
178
	{
179
		$this->stub->expects( $this->once() )->method( 'deleteAddress' );
180
181
		$this->assertSame( $this->object, $this->object->deleteAddress( 'payment' ) );
182
	}
183
184
185
	public function testAddService()
186
	{
187
		$item = \Aimeos\MShop::create( $this->context, 'service' )->createItem()->setType( 'payment' );
188
189
		$this->stub->expects( $this->once() )->method( 'addService' );
190
191
		$this->assertSame( $this->object, $this->object->addService( $item ) );
192
	}
193
194
195
	public function testDeleteService()
196
	{
197
		$this->stub->expects( $this->once() )->method( 'deleteService' );
198
199
		$this->assertSame( $this->object, $this->object->deleteService( 'payment' ) );
200
	}
201
202
203
	public function testGetController()
204
	{
205
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
206
207
		$this->assertSame( $this->stub, $result );
208
	}
209
210
211
	protected function access( $name )
212
	{
213
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Basket\Decorator\Base::class );
214
		$method = $class->getMethod( $name );
215
		$method->setAccessible( true );
216
217
		return $method;
218
	}
219
}
220