BaseTest   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 18
eloc 51
dl 0
loc 157
c 0
b 0
f 0
rs 10

18 Methods

Rating   Name   Duplication   Size   Complexity  
A testSlice() 0 3 1
A testGetController() 0 3 1
A testCall() 0 12 1
A access() 0 7 1
A testFor() 0 3 1
A testGet() 0 8 1
A testCompare() 0 3 1
A testDelete() 0 5 1
A testList() 0 8 1
A testSearch() 0 8 1
A testDomain() 0 3 1
A testSave() 0 8 1
A testSort() 0 3 1
A setUp() 0 9 1
A testParse() 0 3 1
A testAggregate() 0 6 1
A tearDown() 0 3 1
A testCreate() 0 4 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2024
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Review\Decorator;
10
11
12
class Example extends Base
13
{
14
}
15
16
17
class BaseTest extends \PHPUnit\Framework\TestCase
18
{
19
	private $context;
20
	private $object;
21
	private $stub;
22
23
24
	protected function setUp() : void
25
	{
26
		$this->context = \TestHelper::context();
27
28
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Review\Standard::class )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->object = new \Aimeos\Controller\Frontend\Review\Decorator\Example( $this->stub, $this->context );
33
	}
34
35
36
	protected function tearDown() : void
37
	{
38
		unset( $this->context, $this->object, $this->stub );
39
	}
40
41
42
	public function testCall()
43
	{
44
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Review\Standard::class )
45
			->disableOriginalConstructor()
46
			->onlyMethods( ['__call'] )
47
			->getMock();
48
49
		$object = new \Aimeos\Controller\Frontend\Review\Decorator\Example( $stub, $this->context );
50
51
		$stub->expects( $this->once() )->method( '__call' )->willReturn( true );
52
53
		$this->assertTrue( $object->invalid() );
0 ignored issues
show
Bug introduced by
The method invalid() does not exist on Aimeos\Controller\Fronte...eview\Decorator\Example. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

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