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

BaseTest::testSearch()   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), 2017-2023
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Service\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\Service\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\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\Service\Standard::class )
42
			->disableOriginalConstructor()
43
			->onlyMethods( ['__call'] )
44
			->getMock();
45
46
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\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 testCompare()
57
	{
58
		$this->assertSame( $this->object, $this->object->compare( '==', 'service.type', 'delivery' ) );
59
	}
60
61
62
	public function testFind()
63
	{
64
		$item = \Aimeos\MShop::create( $this->context, 'service' )->create();
65
66
		$this->stub->expects( $this->once() )->method( 'find' )
67
			->will( $this->returnValue( $item ) );
68
69
		$this->assertSame( $item, $this->object->find( 'test' ) );
70
	}
71
72
73
	public function testFunction()
74
	{
75
		$this->stub->expects( $this->once() )->method( 'function' )
76
			->will( $this->returnValue( 'service:has("domain","type","refid")' ) );
77
78
		$str = $this->object->function( 'service:has', ['domain', 'type', 'refid'] );
79
		$this->assertEquals( 'service:has("domain","type","refid")', $str );
80
	}
81
82
83
	public function testGet()
84
	{
85
		$item = \Aimeos\MShop::create( $this->context, 'service' )->create();
86
87
		$this->stub->expects( $this->once() )->method( 'get' )
88
			->will( $this->returnValue( $item ) );
89
90
		$this->assertSame( $item, $this->object->get( -1 ) );
91
	}
92
93
94
	public function testGetProvider()
95
	{
96
		$manager = \Aimeos\MShop::create( $this->context, 'service' );
97
		$provider = $manager->getProvider( $manager->find( 'unitdeliverycode', [], 'service', 'delivery' ), 'delivery' );
98
99
		$this->stub->expects( $this->once() )->method( 'getProvider' )
100
			->will( $this->returnValue( $provider ) );
101
102
		$this->assertSame( $provider, $this->object->getProvider( -1 ) );
103
	}
104
105
106
	public function testGetProviders()
107
	{
108
		$this->stub->expects( $this->once() )->method( 'getProviders' )
109
			->will( $this->returnValue( map() ) );
110
111
		$this->assertEquals( [], $this->object->getProviders( 'payment' )->toArray() );
112
	}
113
114
115
	public function testParse()
116
	{
117
		$this->assertSame( $this->object, $this->object->parse( [] ) );
118
	}
119
120
121
	public function testProcess()
122
	{
123
		$item = \Aimeos\MShop::create( $this->context, 'order' )->create();
124
125
		$this->stub->expects( $this->once() )->method( 'process' )
126
			->will( $this->returnValue( new \Aimeos\MShop\Common\Helper\Form\Standard() ) );
127
128
		$this->assertInstanceOf( 'Aimeos\MShop\Common\Helper\Form\Iface', $this->object->process( $item, -1, [], [] ) );
129
	}
130
131
132
	public function testSearch()
133
	{
134
		$total = 0;
135
		$item = \Aimeos\MShop::create( $this->context, 'service' )->create();
136
137
		$this->stub->expects( $this->once() )->method( 'search' )
138
			->will( $this->returnValue( map( [$item] ) ) );
139
140
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
141
	}
142
143
144
	public function testSlice()
145
	{
146
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
147
	}
148
149
150
	public function testSort()
151
	{
152
		$this->assertSame( $this->object, $this->object->sort( 'type' ) );
153
	}
154
155
156
	public function testUpdatePush()
157
	{
158
		$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock();
159
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
160
161
		$this->stub->expects( $this->once() )->method( 'updatePush' )
162
			->will( $this->returnValue( $response ) );
163
164
		$this->assertInstanceOf( \Psr\Http\Message\ResponseInterface::class, $this->object->updatePush( $request, $response, 'test' ) );
165
	}
166
167
168
	public function testUpdateSync()
169
	{
170
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
171
		$item = \Aimeos\MShop::create( $this->context, 'order' )->create();
172
173
		$this->stub->expects( $this->once() )->method( 'updateSync' )
174
			->will( $this->returnValue( $item ) );
175
176
		$this->assertInstanceOf( 'Aimeos\MShop\Order\Item\Iface', $this->object->updateSync( $request, 'test', -1 ) );
177
	}
178
179
180
	public function testUses()
181
	{
182
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
183
	}
184
185
186
	public function testGetController()
187
	{
188
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
189
	}
190
191
192
	protected function access( $name )
193
	{
194
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Service\Decorator\Base::class );
195
		$method = $class->getMethod( $name );
196
		$method->setAccessible( true );
197
198
		return $method;
199
	}
200
}
201