Completed
Push — master ( 31faa3...626087 )
by Aimeos
02:18
created

BaseTest::testClear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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\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()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Basket\Standard' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Basket\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\Basket\Decorator\Base' )
46
			->setConstructorArgs( [$stub, $this->context] )
47
			->getMockForAbstractClass();
48
	}
49
50
51
	public function testCall()
52
	{
53
		$stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Basket\Standard' )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Basket\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 testClear()
69
	{
70
		$this->stub->expects( $this->once() )->method( 'clear' );
71
72
		$this->object->clear();
73
	}
74
75
76
	public function testGet()
77
	{
78
		$context = \TestHelperFrontend::getContext();
79
		$order = \Aimeos\MShop\Factory::createManager( $context, 'order/base' )->createItem();
80
81
		$this->stub->expects( $this->once() )->method( 'get' )
82
			->will( $this->returnValue( $order ) );
83
84
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Base\Iface', $this->object->get() );
85
	}
86
87
88
	public function testSave()
89
	{
90
		$this->stub->expects( $this->once() )->method( 'save' );
91
92
		$this->object->save();
93
	}
94
95
96
	public function testAddProduct()
97
	{
98
		$this->stub->expects( $this->once() )->method( 'addProduct' );
99
100
		$this->object->addProduct( -1 );
101
	}
102
103
104
	public function testDeleteProduct()
105
	{
106
		$this->stub->expects( $this->once() )->method( 'deleteProduct' );
107
108
		$this->object->deleteProduct( 0 );
109
	}
110
111
112
	public function testEditProduct()
113
	{
114
		$this->stub->expects( $this->once() )->method( 'editProduct' );
115
116
		$this->object->editProduct( 0, 1 );
117
	}
118
119
120
	public function testAddCoupon()
121
	{
122
		$this->stub->expects( $this->once() )->method( 'addCoupon' );
123
124
		$this->object->addCoupon( 'test' );
125
	}
126
127
128
	public function testDeleteCoupon()
129
	{
130
		$this->stub->expects( $this->once() )->method( 'deleteCoupon' );
131
132
		$this->object->deleteCoupon( 'test' );
133
	}
134
135
136
	public function testSetAddress()
137
	{
138
		$this->stub->expects( $this->once() )->method( 'setAddress' );
139
140
		$this->object->setAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, null );
141
	}
142
143
144
	public function testSetService()
145
	{
146
		$this->stub->expects( $this->once() )->method( 'setService' );
147
148
		$this->object->setService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT, -1 );
149
	}
150
151
152
	public function testGetController()
153
	{
154
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
155
156
		$this->assertSame( $this->stub, $result );
157
	}
158
159
160
	protected function access( $name )
161
	{
162
		$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Basket\Decorator\Base' );
163
		$method = $class->getMethod( $name );
164
		$method->setAccessible( true );
165
166
		return $method;
167
	}
168
}
169