Passed
Push — master ( c9dfc7...a4ce90 )
by Aimeos
01:38
created

BaseTest::testGetProviders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
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-2018
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Service\Decorator;
10
11
12
class BaseTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
	private $context;
15
	private $object;
16
	private $stub;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
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()
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->setExpectedException( \Aimeos\MW\Common\Exception::class );
44
45
		$this->getMockBuilder( \Aimeos\Controller\Frontend\Service\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\Service\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Service\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( '==', 'service.type', 'delivery' ) );
71
	}
72
73
74
	public function testFind()
75
	{
76
		$item = \Aimeos\MShop::create( $this->context, 'service' )->createItem();
77
78
		$this->stub->expects( $this->once() )->method( 'find' )
79
			->will( $this->returnValue( $item ) );
80
81
		$this->assertSame( $item, $this->object->find( 'test' ) );
82
	}
83
84
85
	public function testGet()
86
	{
87
		$item = \Aimeos\MShop::create( $this->context, 'service' )->createItem();
88
89
		$this->stub->expects( $this->once() )->method( 'get' )
90
			->will( $this->returnValue( $item ) );
91
92
		$this->assertSame( $item, $this->object->get( -1 ) );
93
	}
94
95
96
	public function testGetProvider()
97
	{
98
		$manager = \Aimeos\MShop::create( $this->context, 'service' );
99
		$provider = $manager->getProvider( $manager->findItem( 'unitcode', [], 'service', 'delivery' ), 'delivery' );
100
101
		$this->stub->expects( $this->once() )->method( 'getProvider' )
102
			->will( $this->returnValue( $provider ) );
103
104
		$this->assertSame( $provider, $this->object->getProvider( -1 ) );
105
	}
106
107
108
	public function testGetProviders()
109
	{
110
		$this->stub->expects( $this->once() )->method( 'getProviders' )
111
			->will( $this->returnValue( [] ) );
112
113
		$this->assertEquals( [], $this->object->getProviders( 'payment' ) );
114
	}
115
116
117
	public function testParse()
118
	{
119
		$this->assertSame( $this->object, $this->object->parse( [] ) );
120
	}
121
122
123
	public function testProcess()
124
	{
125
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
126
127
		$this->stub->expects( $this->once() )->method( 'process' )
128
			->will( $this->returnValue( new \Aimeos\MShop\Common\Helper\Form\Standard() ) );
129
130
		$this->assertInstanceOf( 'Aimeos\MShop\Common\Helper\Form\Iface', $this->object->process( $item, -1, [], [] ) );
131
	}
132
133
134
	public function testSearch()
135
	{
136
		$total = 0;
137
		$item = \Aimeos\MShop::create( $this->context, 'service' )->createItem();
138
139
		$this->stub->expects( $this->once() )->method( 'search' )
140
			->will( $this->returnValue( [$item] ) );
141
142
		$this->assertEquals( [$item], $this->object->search( $total ) );
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( 'type' ) );
155
	}
156
157
158
	public function testUpdatePush()
159
	{
160
		$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock();
161
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
162
163
		$this->stub->expects( $this->once() )->method( 'updatePush' )
164
			->will( $this->returnValue( $response ) );
165
166
		$this->assertInstanceOf( \Psr\Http\Message\ResponseInterface::class, $this->object->updatePush( $request, $response, 'test' ) );
167
	}
168
169
170
	public function testUpdateSync()
171
	{
172
		$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock();
173
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
174
		$item = \Aimeos\MShop::create( $this->context, 'order' )->createItem();
175
176
		$this->stub->expects( $this->once() )->method( 'updateSync' )
177
			->will( $this->returnValue( $item ) );
178
179
		$this->assertInstanceOf( 'Aimeos\MShop\Order\Item\Iface', $this->object->updateSync( $request, $response, [], 'test', -1 ) );
180
	}
181
182
183
	public function testUses()
184
	{
185
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
186
	}
187
188
189
	public function testGetController()
190
	{
191
		$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) );
192
	}
193
194
195
	protected function access( $name )
196
	{
197
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Service\Decorator\Base::class );
198
		$method = $class->getMethod( $name );
199
		$method->setAccessible( true );
200
201
		return $method;
202
	}
203
}
204