Passed
Push — master ( 5b861b...ddbcd6 )
by Aimeos
16:40 queued 03:20
created

BaseTest::testConstructException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
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), 2018-2023
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 = \TestHelper::context();
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 testCall()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Review\Standard::class )
42
			->disableOriginalConstructor()
43
			->onlyMethods( ['__call'] )
44
			->getMock();
45
46
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Review\Decorator\Base::class )
47
			->setConstructorArgs( [$stub, $this->context] )
48
			->getMockForAbstractClass();
49
50
		$stub->expects( $this->once() )->method( '__call' )->will( $this->returnValue( true ) );
51
52
		$this->assertTrue( $object->invalid() );
53
	}
54
55
56
	public function testAggregate()
57
	{
58
		$this->stub->expects( $this->once() )->method( 'aggregate' )
59
			->will( $this->returnValue( map() ) );
60
61
		$this->assertEquals( [], $this->object->aggregate( 'test' )->toArray() );
62
	}
63
64
65
	public function testCompare()
66
	{
67
		$this->assertSame( $this->object, $this->object->compare( '==', 'supplier.status', 1 ) );
68
	}
69
70
71
	public function testCreate()
72
	{
73
		$result = $this->object->create( ['review.rating' => 5] );
74
		$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $result );
75
	}
76
77
78
	public function testDelete()
79
	{
80
		$this->stub->expects( $this->once() )->method( 'delete' );
81
82
		$this->assertSame( $this->object, $this->object->delete( '-1' ) );
83
	}
84
85
86
	public function testDomain()
87
	{
88
		$this->assertSame( $this->object, $this->object->domain( 'product' ) );
89
	}
90
91
92
	public function testFor()
93
	{
94
		$this->assertSame( $this->object, $this->object->for( 'product', '-1' ) );
95
	}
96
97
98
	public function testGet()
99
	{
100
		$item = \Aimeos\MShop::create( $this->context, 'review' )->create();
101
102
		$this->stub->expects( $this->once() )->method( 'get' )
103
			->will( $this->returnValue( $item ) );
104
105
		$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $this->object->get( -1 ) );
106
	}
107
108
109
	public function testList()
110
	{
111
		$item = \Aimeos\MShop::create( $this->context, 'review' )->create();
112
113
		$this->stub->expects( $this->once() )->method( 'list' )
114
			->will( $this->returnValue( map( [$item] ) ) );
115
116
		$this->assertEquals( [$item], $this->object->list()->toArray() );
117
	}
118
119
120
	public function testParse()
121
	{
122
		$this->assertSame( $this->object, $this->object->parse( [] ) );
123
	}
124
125
126
	public function testSave()
127
	{
128
		$item = \Aimeos\MShop::create( $this->context, 'review' )->create();
129
130
		$this->stub->expects( $this->once() )->method( 'save' )
131
			->will( $this->returnValue( $item ) );
132
133
		$this->assertInstanceOf( \Aimeos\MShop\Review\Item\Iface::class, $this->object->save( $item ) );
134
	}
135
136
137
	public function testSearch()
138
	{
139
		$item = \Aimeos\MShop::create( $this->context, 'review' )->create();
140
141
		$this->stub->expects( $this->once() )->method( 'search' )
142
			->will( $this->returnValue( map( [$item] ) ) );
143
144
		$this->assertEquals( [$item], $this->object->search()->toArray() );
145
	}
146
147
148
	public function testSlice()
149
	{
150
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
151
	}
152
153
154
	public function testSort()
155
	{
156
		$this->assertSame( $this->object, $this->object->sort( 'interval' ) );
157
	}
158
159
160
	public function testGetController()
161
	{
162
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
163
	}
164
165
166
	protected function access( $name )
167
	{
168
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Review\Decorator\Base::class );
169
		$method = $class->getMethod( $name );
170
		$method->setAccessible( true );
171
172
		return $method;
173
	}
174
}
175