Passed
Push — master ( 5b861b...ddbcd6 )
by Aimeos
16:40 queued 03:20
created

BaseTest::testLoad()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
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-2023
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Basket\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() : void
20
	{
21
		$this->context = \TestHelper::context();
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() : void
34
	{
35
		unset( $this->context, $this->object, $this->stub );
36
	}
37
38
39
	public function testCall()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Basket\Standard::class )
42
			->disableOriginalConstructor()
43
			->onlyMethods( ['__call'] )
44
			->getMock();
45
46
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Basket\Decorator\Base::class )
47
			->setConstructorArgs( [$stub, $this->context] )
48
			->getMockForAbstractClass();
49
50
		$stub->expects( $this->once() )->method( '__call' )->will( $this->returnValue( true ) );
51
52
		$this->assertTrue( $object->invalid() );
53
	}
54
55
56
	public function testAdd()
57
	{
58
		$this->stub->expects( $this->once() )->method( 'add' );
59
		$this->assertSame( $this->object, $this->object->add( [] ) );
60
	}
61
62
63
	public function testClear()
64
	{
65
		$this->stub->expects( $this->once() )->method( 'clear' );
66
		$this->assertSame( $this->object, $this->object->clear() );
67
	}
68
69
70
	public function testGet()
71
	{
72
		$context = \TestHelper::context();
73
		$order = \Aimeos\MShop::create( $context, 'order' )->create();
74
75
		$this->stub->expects( $this->once() )->method( 'get' )->will( $this->returnValue( $order ) );
76
77
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $this->object->get() );
78
	}
79
80
81
	public function testSave()
82
	{
83
		$this->stub->expects( $this->once() )->method( 'save' );
84
		$this->assertSame( $this->object, $this->object->save() );
85
	}
86
87
88
	public function testSetType()
89
	{
90
		$this->stub->expects( $this->once() )->method( 'setType' );
91
		$this->assertSame( $this->object, $this->object->setType( 'test' ) );
92
	}
93
94
95
	public function testStore()
96
	{
97
		$basket = \Aimeos\MShop::create( $this->context, 'order' )->create();
98
99
		$this->stub->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $basket ) );
100
101
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $this->object->store() );
102
	}
103
104
105
	public function testLoad()
106
	{
107
		$basket = \Aimeos\MShop::create( $this->context, 'order' )->create();
108
109
		$this->stub->expects( $this->once() )->method( 'load' )->will( $this->returnValue( $basket ) );
110
111
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $this->object->load( -1 ) );
112
	}
113
114
115
	public function testAddProduct()
116
	{
117
		$product = \Aimeos\MShop::create( $this->context, 'product' )->create();
118
119
		$this->stub->expects( $this->once() )->method( 'addProduct' );
120
121
		$this->assertSame( $this->object, $this->object->addProduct( $product ) );
122
	}
123
124
125
	public function testDeleteProduct()
126
	{
127
		$this->stub->expects( $this->once() )->method( 'deleteProduct' );
128
129
		$this->assertSame( $this->object, $this->object->deleteProduct( 0 ) );
130
	}
131
132
133
	public function testUpdateProduct()
134
	{
135
		$this->stub->expects( $this->once() )->method( 'updateProduct' );
136
137
		$this->assertSame( $this->object, $this->object->updateProduct( 0, 1 ) );
138
	}
139
140
141
	public function testAddCoupon()
142
	{
143
		$this->stub->expects( $this->once() )->method( 'addCoupon' );
144
145
		$this->assertSame( $this->object, $this->object->addCoupon( 'test' ) );
146
	}
147
148
149
	public function testDeleteCoupon()
150
	{
151
		$this->stub->expects( $this->once() )->method( 'deleteCoupon' );
152
153
		$this->assertSame( $this->object, $this->object->deleteCoupon( 'test' ) );
154
	}
155
156
157
	public function testAddAddress()
158
	{
159
		$this->stub->expects( $this->once() )->method( 'addAddress' );
160
161
		$this->assertSame( $this->object, $this->object->addAddress( 'payment', [] ) );
162
	}
163
164
165
	public function testDeleteAddress()
166
	{
167
		$this->stub->expects( $this->once() )->method( 'deleteAddress' );
168
169
		$this->assertSame( $this->object, $this->object->deleteAddress( 'payment' ) );
170
	}
171
172
173
	public function testAddService()
174
	{
175
		$item = \Aimeos\MShop::create( $this->context, 'service' )->create()->setType( 'payment' );
176
177
		$this->stub->expects( $this->once() )->method( 'addService' );
178
179
		$this->assertSame( $this->object, $this->object->addService( $item ) );
180
	}
181
182
183
	public function testDeleteService()
184
	{
185
		$this->stub->expects( $this->once() )->method( 'deleteService' );
186
187
		$this->assertSame( $this->object, $this->object->deleteService( 'payment' ) );
188
	}
189
190
191
	public function testGetController()
192
	{
193
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
194
195
		$this->assertSame( $this->stub, $result );
196
	}
197
198
199
	protected function access( $name )
200
	{
201
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Basket\Decorator\Base::class );
202
		$method = $class->getMethod( $name );
203
		$method->setAccessible( true );
204
205
		return $method;
206
	}
207
}
208