Passed
Push — master ( 62fde5...4f02ab )
by Aimeos
05:13
created

BaseTest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 55
c 4
b 0
f 0
dl 0
loc 149
rs 10
wmc 16

15 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 testCheckConfig() 0 6 1
A testUpdateSync() 0 8 1
A testCall() 0 7 2
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->object::macro( 'hasSomething', function( $name ) {
59
			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

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