Passed
Push — master ( 8b8a73...4b518d )
by Aimeos
03:02
created

BaseTest::testSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
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), 2018-2020
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Review\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\Review\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Review\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\Review\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\Review\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Review\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 testCompare()
69
	{
70
		$this->assertSame( $this->object, $this->object->compare( '==', 'supplier.status', 1 ) );
71
	}
72
73
74
	public function testDelete()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'review' )->createItem();
0 ignored issues
show
Unused Code introduced by
The assignment to $item is dead and can be removed.
Loading history...
77
78
		$this->stub->expects( $this->once() )->method( 'delete' );
79
80
		$this->assertSame( $this->object, $this->object->delete( '-1' ) );
81
	}
82
83
84
	public function testDomain()
85
	{
86
		$this->assertSame( $this->object, $this->object->domain( 'product' ) );
87
	}
88
89
90
	public function testFor()
91
	{
92
		$this->assertSame( $this->object, $this->object->for( 'product', '-1' ) );
93
	}
94
95
96
	public function testGet()
97
	{
98
		$item = \Aimeos\MShop::create( $this->context, 'review' )->createItem();
99
100
		$this->stub->expects( $this->once() )->method( 'get' )
101
			->will( $this->returnValue( $item ) );
102
103
		$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $this->object->get( -1 ) );
104
	}
105
106
107
	public function testList()
108
	{
109
		$item = \Aimeos\MShop::create( $this->context, 'review' )->createItem();
110
111
		$this->stub->expects( $this->once() )->method( 'list' )
112
			->will( $this->returnValue( map( [$item] ) ) );
113
114
		$this->assertEquals( [$item], $this->object->list()->toArray() );
115
	}
116
117
118
	public function testParse()
119
	{
120
		$this->assertSame( $this->object, $this->object->parse( [] ) );
121
	}
122
123
124
	public function testSave()
125
	{
126
		$item = \Aimeos\MShop::create( $this->context, 'review' )->createItem();
127
128
		$this->stub->expects( $this->once() )->method( 'save' )
129
			->will( $this->returnValue( $item ) );
130
131
		$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $this->object->save( $item ) );
132
	}
133
134
135
	public function testSearch()
136
	{
137
		$item = \Aimeos\MShop::create( $this->context, 'review' )->createItem();
138
139
		$this->stub->expects( $this->once() )->method( 'search' )
140
			->will( $this->returnValue( map( [$item] ) ) );
141
142
		$this->assertEquals( [$item], $this->object->search()->toArray() );
143
	}
144
145
146
	public function testSlice()
147
	{
148
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
149
	}
150
151
152
	public function testSort()
153
	{
154
		$this->assertSame( $this->object, $this->object->sort( 'interval' ) );
155
	}
156
157
158
	public function testGetController()
159
	{
160
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
161
	}
162
163
164
	protected function access( $name )
165
	{
166
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Review\Decorator\Base::class );
167
		$method = $class->getMethod( $name );
168
		$method->setAccessible( true );
169
170
		return $method;
171
	}
172
}
173