Completed
Push — master ( 25c6af...9f51fe )
by Aimeos
02:20
created

BaseTest::testAddItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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\Order\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\Order\Standard' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Order\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\Order\Decorator\Base' )
46
			->setConstructorArgs( [$stub, $this->context] )
47
			->getMockForAbstractClass();
48
	}
49
50
51
	public function testCall()
52
	{
53
		$stub = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Order\Standard' )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( '\Aimeos\Controller\Frontend\Order\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, 'order' )->createItem();
71
72
		$this->stub->expects( $this->once() )->method( 'addItem' )->will( $this->returnValue( $item ) );
73
74
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Iface', $this->object->addItem( -1, '' ) );
75
	}
76
77
78
	public function testCreateFilter()
79
	{
80
		$search = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createSearch();
81
82
		$this->stub->expects( $this->once() )->method( 'createFilter' )->will( $this->returnValue( $search ) );
83
84
		$this->assertInstanceOf( '\Aimeos\MW\Criteria\Iface', $this->object->createFilter() );
85
	}
86
87
88
	public function testGetItem()
89
	{
90
		$item = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem();
91
92
		$this->stub->expects( $this->once() )->method( 'getItem' )->will( $this->returnValue( $item ) );
93
94
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Iface', $this->object->getItem( -1 ) );
95
	}
96
97
98
	public function testSearchItems()
99
	{
100
		$search = $this->getMockBuilder( '\Aimeos\MW\Criteria\Iface' )->getMock();
101
102
		$this->stub->expects( $this->once() )->method( 'searchItems' )->will( $this->returnValue( [] ) );
103
104
		$this->assertEquals( [], $this->object->searchItems( $search ) );
105
	}
106
107
108
	public function testUnblock()
109
	{
110
		$orderItem = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem();
111
112
		$this->stub->expects( $this->once() )->method( 'unblock' );
113
114
		$this->object->unblock( $orderItem );
115
	}
116
117
118
	public function testUpdate()
119
	{
120
		$orderItem = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem();
121
122
		$this->stub->expects( $this->once() )->method( 'update' );
123
124
		$this->object->update( $orderItem );
125
	}
126
127
128
	public function testStore()
129
	{
130
		$orderItem = \Aimeos\MShop\Factory::createManager( $this->context, 'order' )->createItem();
131
		$basket = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' )->createItem();
132
133
		$this->stub->expects( $this->once() )->method( 'store' )
134
			->will( $this->returnValue( $orderItem ) );
135
136
		$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Iface', $this->object->store( $basket ) );
137
	}
138
139
140
	public function testGetController()
141
	{
142
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
143
144
		$this->assertSame( $this->stub, $result );
145
	}
146
147
148
	protected function access( $name )
149
	{
150
		$class = new \ReflectionClass( '\Aimeos\Controller\Frontend\Order\Decorator\Base' );
151
		$method = $class->getMethod( $name );
152
		$method->setAccessible( true );
153
154
		return $method;
155
	}
156
}
157