StandardTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 164
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 86
c 2
b 0
f 0
dl 0
loc 164
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A tearDown() 0 4 1
A testGetDescription() 0 4 1
A testGetName() 0 3 1
A testRun() 0 44 1
A testRunExceptionProcess() 0 45 1
A testRunExceptionProvider() 0 33 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2014
6
 * @copyright Aimeos (aimeos.org), 2015-2025
7
 */
8
9
10
namespace Aimeos\Controller\Jobs\Order\Service\Delivery;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
17
18
	protected function setUp() : void
19
	{
20
		\Aimeos\MShop::cache( true );
21
22
		$context = \TestHelper::context();
23
		$aimeos = \TestHelper::getAimeos();
24
25
		$this->object = new \Aimeos\Controller\Jobs\Order\Service\Delivery\Standard( $context, $aimeos );
26
	}
27
28
29
	protected function tearDown() : void
30
	{
31
		\Aimeos\MShop::cache( false );
32
		unset( $this->object );
33
	}
34
35
36
	public function testGetName()
37
	{
38
		$this->assertEquals( 'Process order delivery services', $this->object->getName() );
39
	}
40
41
42
	public function testGetDescription()
43
	{
44
		$text = 'Sends paid orders to the ERP system or logistic partner';
45
		$this->assertEquals( $text, $this->object->getDescription() );
46
	}
47
48
49
	public function testRun()
50
	{
51
		$context = \TestHelper::context();
52
		$aimeos = \TestHelper::getAimeos();
53
54
55
		$serviceManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' )
56
			->onlyMethods( array( 'getProvider', 'iterate' ) )
57
			->setConstructorArgs( array( $context ) )
58
			->getMock();
59
60
		$orderManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
61
			->onlyMethods( array( 'save', 'iterate' ) )
62
			->setConstructorArgs( array( $context ) )
63
			->getMock();
64
65
		\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Service\\Manager\\Standard', $serviceManagerStub );
66
		\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Order\\Manager\\Standard', $orderManagerStub );
67
68
69
		$serviceItem = $serviceManagerStub->create()->setType( '' );
70
		$orderItem = $orderManagerStub->create();
71
72
		$serviceProviderStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Standard' )
73
			->setConstructorArgs( array( $context, $serviceItem ) )
74
			->getMock();
75
76
77
		$serviceManagerStub->expects( $this->exactly( 2 ) )->method( 'iterate' )
78
			->willReturn( map( [$serviceItem] ), null );
79
80
		$serviceManagerStub->expects( $this->once() )->method( 'getProvider' )
81
			->willReturn( $serviceProviderStub );
82
83
		$orderManagerStub->expects( $this->exactly( 2 ) )->method( 'iterate' )
84
			->willReturn( map( [$orderItem] ), null );
85
86
		$serviceProviderStub->expects( $this->once() )->method( 'push' );
87
88
		$orderManagerStub->expects( $this->once() )->method( 'save' );
89
90
91
		$object = new \Aimeos\Controller\Jobs\Order\Service\Delivery\Standard( $context, $aimeos );
92
		$object->run();
93
	}
94
95
96
	public function testRunExceptionProcess()
97
	{
98
		$context = \TestHelper::context();
99
		$aimeos = \TestHelper::getAimeos();
100
101
102
		$orderManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
103
			->onlyMethods( array( 'save', 'iterate' ) )
104
			->setConstructorArgs( array( $context ) )
105
			->getMock();
106
107
		$serviceManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' )
108
			->onlyMethods( array( 'getProvider', 'iterate' ) )
109
			->setConstructorArgs( array( $context ) )
110
			->getMock();
111
112
		\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Order\\Manager\\Standard', $orderManagerStub );
113
		\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Service\\Manager\\Standard', $serviceManagerStub );
114
115
116
		$serviceItem = $serviceManagerStub->create()->setType( '' );
117
		$orderItem = $orderManagerStub->create();
118
119
		$serviceProviderStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Delivery\\Standard' )
120
			->setConstructorArgs( array( $context, $serviceItem ) )
121
			->getMock();
122
123
124
		$serviceManagerStub->expects( $this->exactly( 2 ) )->method( 'iterate' )
125
			->willReturn( map( [$serviceItem] ), null );
126
127
		$serviceManagerStub->expects( $this->once() )->method( 'getProvider' )
128
			->willReturn( $serviceProviderStub );
129
130
		$orderManagerStub->expects( $this->exactly( 2 ) )->method( 'iterate' )
131
			->willReturn( map( [$orderItem] ), null );
132
133
		$serviceProviderStub->expects( $this->once() )->method( 'push' )
134
			->will( $this->throwException( new \Aimeos\MShop\Service\Exception( 'test order service delivery: process' ) ) );
135
136
		$orderManagerStub->expects( $this->never() )->method( 'save' );
137
138
139
		$object = new \Aimeos\Controller\Jobs\Order\Service\Delivery\Standard( $context, $aimeos );
140
		$object->run();
141
	}
142
143
144
	public function testRunExceptionProvider()
145
	{
146
		$context = \TestHelper::context();
147
		$aimeos = \TestHelper::getAimeos();
148
149
150
		$orderManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
151
			->onlyMethods( array( 'save', 'iterate' ) )
152
			->setConstructorArgs( array( $context ) )
153
			->getMock();
154
155
		$serviceManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Manager\\Standard' )
156
			->onlyMethods( array( 'getProvider', 'iterate' ) )
157
			->setConstructorArgs( array( $context ) )
158
			->getMock();
159
160
		\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Order\\Manager\\Standard', $orderManagerStub );
161
		\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Service\\Manager\\Standard', $serviceManagerStub );
162
163
164
		$serviceItem = $serviceManagerStub->create()->setType( '' );
165
166
		$serviceManagerStub->expects( $this->exactly( 2 ) )->method( 'iterate' )
167
			->willReturn( map( [$serviceItem] ), null );
168
169
		$serviceManagerStub->expects( $this->once() )->method( 'getProvider' )
170
			->will( $this->throwException( new \Aimeos\MShop\Service\Exception() ) );
171
172
		$orderManagerStub->expects( $this->never() )->method( 'iterate' );
173
174
175
		$object = new \Aimeos\Controller\Jobs\Order\Service\Delivery\Standard( $context, $aimeos );
176
		$object->run();
177
	}
178
}
179