Passed
Push — master ( f72d01...db0b8d )
by Aimeos
04:47
created

BaseTest   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 56
c 4
b 0
f 0
dl 0
loc 155
rs 10
wmc 17

16 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 5 1
A setUp() 0 11 1
A testCheckConfigBE() 0 3 1
A testGetConfigValue() 0 6 1
A testSetCustomerData() 0 15 1
A access() 0 7 1
A testUpdatePush() 0 10 1
A testLog() 0 4 1
A testGetCustomerData() 0 6 1
A testUpdateAsync() 0 3 1
A testQuery() 0 6 1
A testThrow() 0 4 1
A testCallFallback() 0 7 2
A testCheckConfig() 0 6 1
A testCall() 0 3 1
A testUpdateSync() 0 8 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2015-2021
7
 */
8
9
10
namespace Aimeos\MShop\Service\Provider;
11
12
13
class BaseTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $context;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->context = \TestHelperMShop::getContext();
22
		$serviceItem = \Aimeos\MShop\Service\Manager\Factory::create( $this->context )->create()->setId( -1 );
23
24
		$this->object = $this->getMockBuilder( TestBase::class )
25
			->setConstructorArgs( [$this->context, $serviceItem] )
26
			->setMethods( ['test'] )
27
			->getMock();
28
29
		\Aimeos\MShop::cache( true );
30
	}
31
32
33
	protected function tearDown() : void
34
	{
35
		\Aimeos\MShop::cache( false );
36
37
		unset( $this->object );
38
	}
39
40
41
	public function testCheckConfigBE()
42
	{
43
		$this->assertEquals( [], $this->object->checkConfigBE( [] ) );
44
	}
45
46
47
	public function testGetConfigValue()
48
	{
49
		$this->object->injectGlobalConfigBE( ['payment.url-success' => 'https://url.to/ok'] );
50
		$result = $this->access( 'getConfigValue' )->invokeArgs( $this->object, ['payment.url-success'] );
51
52
		$this->assertEquals( 'https://url.to/ok', $result );
53
	}
54
55
56
	public function testCall()
57
	{
58
		$this->assertFalse( $this->object->call( 'updateAsync', [] ) );
59
	}
60
61
62
	public function testCallFallback()
63
	{
64
		$this->object::method( 'hasSomething', function( $name ) {
65
			return $this->getConfigValue( $name ) ? true : false;
0 ignored issues
show
Bug introduced by
The method getConfigValue() does not exist on Aimeos\MShop\Service\Provider\BaseTest. ( Ignorable by Annotation )

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

65
			return $this->/** @scrutinizer ignore-call */ getConfigValue( $name ) ? true : false;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
		} );
67
68
		$this->assertFalse( $this->object->hasSomething( 'test' ) );
69
	}
70
71
72
	public function testLog()
73
	{
74
		$result = $this->access( 'log' )->invokeArgs( $this->object, [['data' => 'test'], 500] );
75
		$this->assertInstanceOf( \Aimeos\MShop\Service\Provider\Iface::class, $result );
76
	}
77
78
79
	public function testQuery()
80
	{
81
		$item = \Aimeos\MShop\Order\Manager\Factory::create( $this->context )->create();
82
83
		$this->expectException( \Aimeos\MShop\Service\Exception::class );
84
		$this->object->query( $item );
85
	}
86
87
88
	public function testUpdateAsync()
89
	{
90
		$this->assertFalse( $this->object->updateAsync() );
91
	}
92
93
94
	public function testUpdatePush()
95
	{
96
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
97
		$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock();
98
99
		$response->expects( $this->once() )->method( 'withStatus' )->will( $this->returnValue( $response ) );
100
101
		$result = $this->object->updatePush( $request, $response );
102
103
		$this->assertInstanceOf( \Psr\Http\Message\ResponseInterface::class, $result );
104
	}
105
106
107
	public function testUpdateSync()
108
	{
109
		$orderItem = \Aimeos\MShop\Order\Manager\Factory::create( $this->context )->create();
110
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
111
112
		$result = $this->object->updateSync( $request, $orderItem );
113
114
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $result );
115
	}
116
117
118
	public function testCheckConfig()
119
	{
120
		$this->expectException( \Aimeos\MShop\Exception::class );
121
122
		$args = [['key' => ['code' => 'key', 'type' => 'invalid', 'required' => true]], ['key' => 'abc']];
123
		$this->access( 'checkConfig' )->invokeArgs( $this->object, $args );
124
	}
125
126
127
	public function testGetCustomerData()
128
	{
129
		$manager = \Aimeos\MShop::create( $this->context, 'customer' );
130
		$customerId = $manager->find( '[email protected]' )->getId();
131
132
		$this->assertNull( $this->access( 'getCustomerData' )->invokeArgs( $this->object, [$customerId, 'token'] ) );
133
	}
134
135
136
	public function testSetCustomerData()
137
	{
138
		$stub = $this->getMockBuilder( \Aimeos\MShop\Customer\Manager\Standard::class )
139
			->setConstructorArgs( [$this->context] )
140
			->setMethods( ['save'] )
141
			->getMock();
142
143
		\Aimeos\MShop::inject( 'customer', $stub );
144
145
		$stub->expects( $this->once() )->method( 'save' );
146
147
		$manager = \Aimeos\MShop::create( $this->context, 'customer' );
148
		$customerId = $manager->find( '[email protected]' )->getId();
149
150
		$this->access( 'setCustomerData' )->invokeArgs( $this->object, [$customerId, 'token', 'abcd'] );
151
	}
152
153
154
	public function testThrow()
155
	{
156
		$this->expectException( \Aimeos\MShop\Service\Exception::class );
157
		$this->access( 'throw' )->invokeArgs( $this->object, ['Test message', 'mshop'] );
158
	}
159
160
161
	protected function access( $name )
162
	{
163
		$class = new \ReflectionClass( \Aimeos\MShop\Service\Provider\Base::class );
164
		$method = $class->getMethod( $name );
165
		$method->setAccessible( true );
166
167
		return $method;
168
	}
169
}
170
171
172
class TestBase
173
	extends \Aimeos\MShop\Service\Provider\Base
174
	implements \Aimeos\MShop\Service\Provider\Iface
175
{
176
	public function setConfigFE( \Aimeos\MShop\Order\Item\Base\Service\Iface $orderServiceItem,
177
		array $attributes ) : \Aimeos\MShop\Order\Item\Base\Service\Iface
178
	{
179
		return $orderServiceItem;
180
	}
181
}
182