Passed
Push — master ( 9f10fb...4013e0 )
by Aimeos
05:50
created

BaseTest::testLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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