Completed
Push — master ( 7313f0...a0f3ba )
by Aimeos
02:53
created

StandardTest::testRunException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Subscription\Process\End;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
17
18
	protected function setUp()
19
	{
20
		$aimeos = \TestHelperJobs::getAimeos();
21
		$this->context = \TestHelperJobs::getContext();
22
23
		$this->object = new \Aimeos\Controller\Jobs\Subscription\Process\End\Standard( $this->context, $aimeos );
24
25
		\Aimeos\MShop\Factory::setCache( true );
26
	}
27
28
29
	protected function tearDown()
30
	{
31
		\Aimeos\MShop\Factory::setCache( false );
32
		\Aimeos\MShop\Factory::clear();
33
34
		unset( $this->object, $this->context );
35
	}
36
37
38
	public function testGetName()
39
	{
40
		$this->assertEquals( 'Subscription process end', $this->object->getName() );
41
	}
42
43
44
	public function testGetDescription()
45
	{
46
		$this->assertEquals( 'Terminates expired subscriptions', $this->object->getDescription() );
47
	}
48
49
50
	public function testRun()
51
	{
52
		$item = $this->getSubscription();
53
54
		$managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Subscription\\Manager\\Standard' )
55
			->setConstructorArgs( [$this->context] )
56
			->setMethods( ['searchItems', 'saveItem'] )
57
			->getMock();
58
59
		\Aimeos\MShop\Factory::injectManager( $this->context, 'subscription', $managerStub );
60
61
		$managerStub->expects( $this->once() )->method( 'searchItems' )
62
			->will( $this->returnValue( [$item] ) );
63
64
		$managerStub->expects( $this->once() )->method( 'saveItem' );
65
66
		$this->object->run();
67
	}
68
69
70
	public function testRunException()
71
	{
72
		$item = $this->getSubscription();
73
74
		$managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Subscription\\Manager\\Standard' )
75
			->setConstructorArgs( [$this->context] )
76
			->setMethods( ['searchItems', 'saveItem'] )
77
			->getMock();
78
79
		\Aimeos\MShop\Factory::injectManager( $this->context, 'subscription', $managerStub );
80
81
		$managerStub->expects( $this->once() )->method( 'searchItems' )
82
			->will( $this->returnValue( [$item] ) );
83
84
		$managerStub->expects( $this->once() )->method( 'saveItem' )
85
			->will( $this->throwException( new \Exception() ) );
86
87
		$this->object->run();
88
	}
89
90
91
	protected function getSubscription()
92
	{
93
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'subscription' );
94
95
		$search = $manager->createSearch();
96
		$search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) );
97
98
		$items = $manager->searchItems( $search );
99
100
		if( ( $item = reset( $items ) ) !== false ) {
101
			return $item;
102
		}
103
104
		throw new \Exception( 'No subscription item found' );
105
	}
106
}
107