Completed
Push — master ( 32309c...101584 )
by Aimeos
03:33
created

BaseTest::testFor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
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 testCreate()
75
	{
76
		$result = $this->object->create( ['review.rating' => 5] );
77
		$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $result );
78
	}
79
80
81
	public function testDelete()
82
	{
83
		$this->stub->expects( $this->once() )->method( 'delete' );
84
85
		$this->assertSame( $this->object, $this->object->delete( '-1' ) );
86
	}
87
88
89
	public function testDomain()
90
	{
91
		$this->assertSame( $this->object, $this->object->domain( 'product' ) );
92
	}
93
94
95
	public function testFor()
96
	{
97
		$this->assertSame( $this->object, $this->object->for( 'product', '-1' ) );
98
	}
99
100
101
	public function testGet()
102
	{
103
		$item = \Aimeos\MShop::create( $this->context, 'review' )->createItem();
104
105
		$this->stub->expects( $this->once() )->method( 'get' )
106
			->will( $this->returnValue( $item ) );
107
108
		$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $this->object->get( -1 ) );
109
	}
110
111
112
	public function testList()
113
	{
114
		$item = \Aimeos\MShop::create( $this->context, 'review' )->createItem();
115
116
		$this->stub->expects( $this->once() )->method( 'list' )
117
			->will( $this->returnValue( map( [$item] ) ) );
118
119
		$this->assertEquals( [$item], $this->object->list()->toArray() );
120
	}
121
122
123
	public function testParse()
124
	{
125
		$this->assertSame( $this->object, $this->object->parse( [] ) );
126
	}
127
128
129
	public function testSave()
130
	{
131
		$item = \Aimeos\MShop::create( $this->context, 'review' )->createItem();
132
133
		$this->stub->expects( $this->once() )->method( 'save' )
134
			->will( $this->returnValue( $item ) );
135
136
		$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $this->object->save( $item ) );
137
	}
138
139
140
	public function testSearch()
141
	{
142
		$item = \Aimeos\MShop::create( $this->context, 'review' )->createItem();
143
144
		$this->stub->expects( $this->once() )->method( 'search' )
145
			->will( $this->returnValue( map( [$item] ) ) );
146
147
		$this->assertEquals( [$item], $this->object->search()->toArray() );
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( 'interval' ) );
160
	}
161
162
163
	public function testGetController()
164
	{
165
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
166
	}
167
168
169
	protected function access( $name )
170
	{
171
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Review\Decorator\Base::class );
172
		$method = $class->getMethod( $name );
173
		$method->setAccessible( true );
174
175
		return $method;
176
	}
177
}
178