Completed
Push — master ( 921503...9109fd )
by Aimeos
02:03
created

BaseTest::testGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
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
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 testGet()
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( 'get' )
107
			->will( $this->returnValue( $item ) );
108
109
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
110
	}
111
112
113
	public function testFind()
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( 'find' )
119
			->will( $this->returnValue( $item ) );
120
121
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'], 'color' ) );
122
	}
123
124
125
	public function testParse()
126
	{
127
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
128
129
		$this->stub->expects( $this->once() )->method( 'parse' )
130
			->will( $this->returnValue( $this->stub ) );
131
132
		$this->assertInstanceOf( $expected, $this->object->parse( [] ) );
133
	}
134
135
136
	public function testSearch()
137
	{
138
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->createItem();
139
		$expected = \Aimeos\MShop\Attribute\Item\Iface::class;
0 ignored issues
show
Unused Code introduced by
$expected is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
140
		$total = 0;
141
142
		$this->stub->expects( $this->once() )->method( 'search' )
143
			->will( $this->returnValue( [$item] ) );
144
145
		$this->assertEquals( [$item], $this->object->search( ['text'], $total ) );
146
	}
147
148
149
	public function testSlice()
150
	{
151
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
152
153
		$this->stub->expects( $this->once() )->method( 'slice' )
154
			->will( $this->returnValue( $this->stub ) );
155
156
		$this->assertInstanceOf( $expected, $this->object->slice( 0, 100 ) );
157
	}
158
159
160
	public function testSort()
161
	{
162
		$expected = \Aimeos\Controller\Frontend\Attribute\Iface::class;
163
164
		$this->stub->expects( $this->once() )->method( 'sort' )
165
			->will( $this->returnValue( $this->stub ) );
166
167
		$this->assertInstanceOf( $expected, $this->object->sort( 'position' ) );
168
	}
169
170
171
	public function testGetController()
172
	{
173
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
174
175
		$this->assertSame( $this->stub, $result );
176
	}
177
178
179
	protected function access( $name )
180
	{
181
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Attribute\Decorator\Base::class );
182
		$method = $class->getMethod( $name );
183
		$method->setAccessible( true );
184
185
		return $method;
186
	}
187
}
188