Completed
Push — master ( 33a95e...daccbb )
by Aimeos
09:31
created

StandardTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 153
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A tearDown() 0 4 1
A testGetName() 0 4 1
A testGetDescription() 0 5 1
A testRun() 0 69 1
B testRunException() 0 35 1
1
<?php
2
3
namespace Aimeos\Controller\Jobs\Order\Email\Delivery;
4
5
6
/**
7
 * @copyright Metaways Infosystems GmbH, 2014
8
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
9
 * @copyright Aimeos (aimeos.org), 2015
10
 */
11
class StandardTest extends \PHPUnit_Framework_TestCase
12
{
13
	private $object;
14
15
16
	/**
17
	 * Sets up the fixture, for example, opens a network connection.
18
	 * This method is called before a test is executed.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function setUp()
23
	{
24
		$context = \TestHelperJobs::getContext();
25
		$aimeos = \TestHelperJobs::getAimeos();
26
27
		$this->object = new \Aimeos\Controller\Jobs\Order\Email\Delivery\Standard( $context, $aimeos );
28
	}
29
30
31
	/**
32
	 * Tears down the fixture, for example, closes a network connection.
33
	 * This method is called after a test is executed.
34
	 *
35
	 * @access protected
36
	 */
37
	protected function tearDown()
38
	{
39
		$this->object = null;
40
	}
41
42
43
	public function testGetName()
44
	{
45
		$this->assertEquals( 'Order delivery related e-mails', $this->object->getName() );
46
	}
47
48
49
	public function testGetDescription()
50
	{
51
		$text = 'Sends order delivery status update e-mails';
52
		$this->assertEquals( $text, $this->object->getDescription() );
53
	}
54
55
56
	public function testRun()
57
	{
58
		$context = \TestHelperJobs::getContext();
59
		$aimeos = \TestHelperJobs::getAimeos();
60
61
62
		$mailStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\None' )
63
			->disableOriginalConstructor()
64
			->getMock();
65
66
		$mailMsgStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' )
67
			->disableOriginalConstructor()
68
			->disableOriginalClone()
69
			->getMock();
70
71
		$mailStub->expects( $this->once() )
72
			->method( 'createMessage' )
73
			->will( $this->returnValue( $mailMsgStub ) );
74
75
		$mailStub->expects( $this->once() )->method( 'send' );
76
77
		$context->setMail( $mailStub );
78
79
80
		$orderAddressItem = \Aimeos\MShop\Order\Manager\Factory::createManager( $context )
81
			->getSubManager( 'base' )->getSubManager( 'address' )->createItem();
82
83
84
		$name = 'ControllerJobsEmailDeliveryDefaultRun';
85
		$context->getConfig()->set( 'mshop/order/manager/name', $name );
86
87
		$orderManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
88
			->setMethods( array( 'searchItems', 'getSubManager' ) )
89
			->setConstructorArgs( array( $context ) )
90
			->getMock();
91
92
		$orderStatusManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Status\\Standard' )
93
			->setMethods( array( 'saveItem' ) )
94
			->setConstructorArgs( array( $context ) )
95
			->getMock();
96
97
		$orderBaseManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Standard' )
98
			->setMethods( array( 'load' ) )
99
			->setConstructorArgs( array( $context ) )
100
			->getMock();
101
102
		\Aimeos\MShop\Order\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Order\\Manager\\' . $name, $orderManagerStub );
103
104
105
		$orderItem = new \Aimeos\MShop\Order\Item\Standard( array( 'ctime' => '2000-01-01 00:00:00' ) );
106
		$orderBaseItem = $orderBaseManagerStub->createItem();
107
		$orderBaseItem->setAddress( $orderAddressItem );
108
109
110
		$orderManagerStub->expects( $this->exactly( 2 ) )->method( 'getSubManager' )
111
			->will( $this->onConsecutiveCalls( $orderStatusManagerStub, $orderBaseManagerStub ) );
112
113
		$orderManagerStub->expects( $this->exactly( 4 ) )->method( 'searchItems' )
114
			->will( $this->onConsecutiveCalls( array( $orderItem ), array(), array(), array() ) );
115
116
		$orderBaseManagerStub->expects( $this->once() )->method( 'load' )
117
			->will( $this->returnValue( $orderBaseItem ) );
118
119
		$orderStatusManagerStub->expects( $this->once() )->method( 'saveItem' );
120
121
122
		$object = new \Aimeos\Controller\Jobs\Order\Email\Delivery\Standard( $context, $aimeos );
123
		$object->run();
124
	}
125
126
127
	public function testRunException()
128
	{
129
		$context = \TestHelperJobs::getContext();
130
		$aimeos = \TestHelperJobs::getAimeos();
131
132
133
		$mailStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\None' )
134
			->disableOriginalConstructor()
135
			->getMock();
136
137
		$context->setMail( $mailStub );
138
139
140
		$name = 'ControllerJobsEmailDeliveryDefaultRun';
141
		$context->getConfig()->set( 'mshop/order/manager/name', $name );
142
143
144
		$orderManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' )
145
			->setMethods( array( 'searchItems' ) )
146
			->setConstructorArgs( array( $context ) )
147
			->getMock();
148
149
		\Aimeos\MShop\Order\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Order\\Manager\\' . $name, $orderManagerStub );
150
151
152
		$orderItem = $orderManagerStub->createItem();
153
154
155
		$orderManagerStub->expects( $this->exactly( 4 ) )->method( 'searchItems' )
156
			->will( $this->onConsecutiveCalls( array( $orderItem ), array(), array(), array() ) );
157
158
159
		$object = new \Aimeos\Controller\Jobs\Order\Email\Delivery\Standard( $context, $aimeos );
160
		$object->run();
161
	}
162
163
}
164