Passed
Push — master ( 411768...2359f2 )
by Aimeos
02:19
created

BaseTest::testAttribute()   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
dl 0
loc 3
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
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
		$this->assertSame( $this->object, $this->object->attribute( [1, 3] ) );
71
	}
72
73
74
	public function testDomain()
75
	{
76
		$this->assertSame( $this->object, $this->object->domain( 'catalog' ) );
77
	}
78
79
80
	public function testCompare()
81
	{
82
		$this->assertSame( $this->object, $this->object->compare( '==', 'attribute.code', 'test' ) );
83
	}
84
85
86
	public function testFind()
87
	{
88
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->createItem();
89
		$expected = \Aimeos\MShop\Attribute\Item\Iface::class;
90
91
		$this->stub->expects( $this->once() )->method( 'find' )
92
			->will( $this->returnValue( $item ) );
93
94
		$this->assertInstanceOf( $expected, $this->object->find( 'test', 'color' ) );
95
	}
96
97
98
	public function testFunction()
99
	{
100
		$this->stub->expects( $this->once() )->method( 'function' )
101
			->will( $this->returnValue( 'attribute:prop("type",null,"value")' ) );
102
103
		$str = $this->object->function( 'attribute:prop', ['type', null, 'value'] );
104
		$this->assertEquals( 'attribute:prop("type",null,"value")', $str );
105
	}
106
107
108
	public function testGet()
109
	{
110
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->createItem();
111
		$expected = \Aimeos\MShop\Attribute\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 ) );
117
	}
118
119
120
	public function testHas()
121
	{
122
		$this->assertSame( $this->object, $this->object->has( 'price', 'default', -1 ) );
123
	}
124
125
126
	public function testParse()
127
	{
128
		$this->assertSame( $this->object, $this->object->parse( [] ) );
129
	}
130
131
132
	public function testProperty()
133
	{
134
		$this->assertSame( $this->object, $this->object->property( 'test', 'value' ) );
135
	}
136
137
138
	public function testSearch()
139
	{
140
		$item = \Aimeos\MShop::create( $this->context, 'attribute' )->createItem();
141
		$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...
142
		$total = 0;
143
144
		$this->stub->expects( $this->once() )->method( 'search' )
145
			->will( $this->returnValue( [$item] ) );
146
147
		$this->assertEquals( [$item], $this->object->search( $total ) );
148
	}
149
150
151
	public function testSlice()
152
	{
153
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
154
	}
155
156
157
	public function testSort()
158
	{
159
		$this->assertSame( $this->object, $this->object->sort( 'position' ) );
160
	}
161
162
163
	public function testUses()
164
	{
165
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
166
	}
167
168
169
	public function testGetController()
170
	{
171
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
172
173
		$this->assertSame( $this->stub, $result );
174
	}
175
176
177
	protected function access( $name )
178
	{
179
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Attribute\Decorator\Base::class );
180
		$method = $class->getMethod( $name );
181
		$method->setAccessible( true );
182
183
		return $method;
184
	}
185
}
186