Passed
Push — master ( ba8d5b...7aac8f )
by Aimeos
02:06
created

BaseTest::testResolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
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\Product\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\Product\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\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\Product\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\Product\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\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 testAggregate()
69
	{
70
		$this->stub->expects( $this->once() )->method( 'aggregate' )
71
			->will( $this->returnValue( [] ) );
72
73
		$this->assertEquals( [], $this->object->aggregate( 'test' ) );
74
	}
75
76
77
	public function testAllOf()
78
	{
79
		$this->assertSame( $this->object, $this->object->allOf( [1, 2] ) );
80
	}
81
82
83
	public function testCategory()
84
	{
85
		$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE;
86
		$this->assertSame( $this->object, $this->object->category( 1, 'default', $level ) );
87
	}
88
89
90
	public function testCompare()
91
	{
92
		$this->assertSame( $this->object, $this->object->compare( '==', 'product.code', 'test' ) );
93
	}
94
95
96
	public function testFind()
97
	{
98
		$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
99
		$expected = \Aimeos\MShop\Product\Item\Iface::class;
100
101
		$this->stub->expects( $this->once() )->method( 'find' )
102
			->will( $this->returnValue( $item ) );
103
104
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
105
	}
106
107
108
	public function testGet()
109
	{
110
		$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
111
		$expected = \Aimeos\MShop\Product\Item\Iface::class;
112
113
		$this->stub->expects( $this->once() )->method( 'get' )
114
			->will( $this->returnValue( $item ) );
115
116
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
117
	}
118
119
120
	public function testHas()
121
	{
122
		$this->assertSame( $this->object, $this->object->has( 'attribute', 'default', -1 ) );
123
	}
124
125
126
	public function testOneOf()
127
	{
128
		$this->assertSame( $this->object, $this->object->oneOf( [1, 2] ) );
129
	}
130
131
132
	public function testParse()
133
	{
134
		$this->assertSame( $this->object, $this->object->parse( [] ) );
135
	}
136
137
138
	public function testProduct()
139
	{
140
		$this->assertSame( $this->object, $this->object->product( [1, 3] ) );
141
	}
142
143
144
	public function testProperty()
145
	{
146
		$this->assertSame( $this->object, $this->object->property( 'test', 'value' ) );
147
	}
148
149
150
	public function testResolve()
151
	{
152
		$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
153
154
		$this->stub->expects( $this->once() )->method( 'resolve' )
155
			->will( $this->returnValue( $item ) );
156
157
		$this->assertEquals( $item, $this->object->resolve( 'test' ) );
158
	}
159
160
161
	public function testSearch()
162
	{
163
		$total = 0;
164
		$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
165
166
		$this->stub->expects( $this->once() )->method( 'search' )
167
			->will( $this->returnValue( [$item] ) );
168
169
		$this->assertEquals( [$item], $this->object->search( $total ) );
170
	}
171
172
173
	public function testSlice()
174
	{
175
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
176
	}
177
178
179
	public function testSort()
180
	{
181
		$this->assertSame( $this->object, $this->object->sort( 'code' ) );
182
	}
183
184
185
	public function testSupplier()
186
	{
187
		$this->assertSame( $this->object, $this->object->supplier( [1], 'default' ) );
188
	}
189
190
191
	public function testText()
192
	{
193
		$this->assertSame( $this->object, $this->object->text( 'test' ) );
194
	}
195
196
197
	public function testUses()
198
	{
199
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
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\Product\Decorator\Base::class );
214
		$method = $class->getMethod( $name );
215
		$method->setAccessible( true );
216
217
		return $method;
218
	}
219
}
220