Completed
Push — master ( 764ed5...7b4a42 )
by Aimeos
02:43
created

BaseTest::testUses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
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-2020
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() : void
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Order\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Order\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 testConstructException()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Iface::class )->getMock();
42
43
		$this->expectException( \Aimeos\MW\Common\Exception::class );
44
45
		$this->getMockBuilder( \Aimeos\Controller\Frontend\Order\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\Order\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Order\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( -1, [] ) );
72
	}
73
74
75
	public function testCompare()
76
	{
77
		$this->assertSame( $this->object, $this->object->compare( '==', 'order.type', 'test' ) );
78
	}
79
80
81
	public function testGet()
82
	{
83
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
84
		$expected = \Aimeos\MShop\Order\Item\Iface::class;
85
86
		$this->stub->expects( $this->once() )->method( 'get' )->will( $this->returnValue( $item ) );
87
88
		$this->assertInstanceOf( $expected, $this->object->get( -1, false ) );
89
	}
90
91
92
	public function testParse()
93
	{
94
		$this->assertSame( $this->object, $this->object->parse( [] ) );
95
	}
96
97
98
	public function testSave()
99
	{
100
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
101
		$expected = \Aimeos\MShop\Order\Item\Iface::class;
102
103
		$this->stub->expects( $this->once() )->method( 'save' )->will( $this->returnArgument( 0 ) );
104
105
		$this->assertInstanceOf( $expected, $this->object->save( $item ) );
106
	}
107
108
109
	public function testSearch()
110
	{
111
		$total = 0;
112
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
113
114
		$this->stub->expects( $this->once() )->method( 'search' )
115
			->will( $this->returnValue( map( [$item] ) ) );
116
117
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
118
	}
119
120
121
	public function testSlice()
122
	{
123
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
124
	}
125
126
127
	public function testSort()
128
	{
129
		$this->assertSame( $this->object, $this->object->sort( 'order.id' ) );
130
	}
131
132
133
	public function testStore()
134
	{
135
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
136
137
		$this->stub->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $item ) );
138
139
		$this->assertEquals( $item, $this->object->store() );
140
	}
141
142
143
	public function testUses()
144
	{
145
		$this->assertSame( $this->object, $this->object->uses( ['order/base'] ) );
146
	}
147
148
149
	public function testGetController()
150
	{
151
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
152
153
		$this->assertSame( $this->stub, $result );
154
	}
155
156
157
	protected function access( $name )
158
	{
159
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Order\Decorator\Base::class );
160
		$method = $class->getMethod( $name );
161
		$method->setAccessible( true );
162
163
		return $method;
164
	}
165
}
166