Passed
Push — master ( 6cf50b...92e939 )
by Aimeos
01:45
created

BaseTest::testHas()   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\Attribute\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\Attribute\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Attribute\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\Attribute\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\Attribute\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Attribute\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 testAttribute()
69
	{
70
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
71
72
		$this->stub->expects( $this->once() )->method( 'attribute' )
73
			->will( $this->returnValue( $this->stub ) );
74
75
		$this->assertInstanceOf( $expected, $this->object->attribute( [1, 3] ) );
76
	}
77
78
79
	public function testDomain()
80
	{
81
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
82
83
		$this->stub->expects( $this->once() )->method( 'domain' )
84
			->will( $this->returnValue( $this->stub ) );
85
86
		$this->assertInstanceOf( $expected, $this->object->domain( 'catalog' ) );
87
	}
88
89
90
	public function testCompare()
91
	{
92
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
93
94
		$this->stub->expects( $this->once() )->method( 'compare' )
95
			->will( $this->returnValue( $this->stub ) );
96
97
		$this->assertInstanceOf( $expected, $this->object->compare( '==', 'attribute.code', 'test' ) );
98
	}
99
100
101
	public function testFind()
102
	{
103
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->createItem();
104
		$expected = \Aimeos\MShop\Attribute\Item\Iface::class;
105
106
		$this->stub->expects( $this->once() )->method( 'find' )
107
			->will( $this->returnValue( $item ) );
108
109
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'], 'color' ) );
110
	}
111
112
113
	public function testGet()
114
	{
115
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->createItem();
116
		$expected = \Aimeos\MShop\Attribute\Item\Iface::class;
117
118
		$this->stub->expects( $this->once() )->method( 'get' )
119
			->will( $this->returnValue( $item ) );
120
121
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
122
	}
123
124
125
	public function testHas()
126
	{
127
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
128
129
		$this->stub->expects( $this->once() )->method( 'has' )
130
			->will( $this->returnValue( $this->stub ) );
131
132
		$this->assertInstanceOf( $expected, $this->object->has( 'price', 'default', -1 ) );
133
	}
134
135
136
	public function testParse()
137
	{
138
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
139
140
		$this->stub->expects( $this->once() )->method( 'parse' )
141
			->will( $this->returnValue( $this->stub ) );
142
143
		$this->assertInstanceOf( $expected, $this->object->parse( [] ) );
144
	}
145
146
147
	public function testProperty()
148
	{
149
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
150
151
		$this->stub->expects( $this->once() )->method( 'property' )
152
			->will( $this->returnValue( $this->stub ) );
153
154
		$this->assertInstanceOf( $expected, $this->object->property( 'test', 'value' ) );
155
	}
156
157
158
	public function testSearch()
159
	{
160
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->createItem();
161
		$expected = \Aimeos\MShop\Attribute\Item\Iface::class;
0 ignored issues
show
Unused Code introduced by
The assignment to $expected is dead and can be removed.
Loading history...
162
		$total = 0;
163
164
		$this->stub->expects( $this->once() )->method( 'search' )
165
			->will( $this->returnValue( [$item] ) );
166
167
		$this->assertEquals( [$item], $this->object->search( ['text'], $total ) );
168
	}
169
170
171
	public function testSlice()
172
	{
173
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
174
175
		$this->stub->expects( $this->once() )->method( 'slice' )
176
			->will( $this->returnValue( $this->stub ) );
177
178
		$this->assertInstanceOf( $expected, $this->object->slice( 0, 100 ) );
179
	}
180
181
182
	public function testSort()
183
	{
184
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
185
186
		$this->stub->expects( $this->once() )->method( 'sort' )
187
			->will( $this->returnValue( $this->stub ) );
188
189
		$this->assertInstanceOf( $expected, $this->object->sort( 'position' ) );
190
	}
191
192
193
	public function testGetController()
194
	{
195
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
196
197
		$this->assertSame( $this->stub, $result );
198
	}
199
200
201
	protected function access( $name )
202
	{
203
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Attribute\Decorator\Base::class );
204
		$method = $class->getMethod( $name );
205
		$method->setAccessible( true );
206
207
		return $method;
208
	}
209
}
210