Passed
Push — master ( 98fa9f...39cd3b )
by Aimeos
03:45
created

StandardTest::testRenewAfter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 23
rs 9.7333
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2020
6
 */
7
8
namespace Aimeos\Controller\Common\Subscription\Process\Processor\Email;
9
10
11
class StandardTest extends \PHPUnit\Framework\TestCase
12
{
13
	protected function setUp() : void
14
	{
15
		\Aimeos\MShop::cache( true );
16
	}
17
18
19
	protected function tearDown() : void
20
	{
21
		\Aimeos\MShop::cache( false );
22
	}
23
24
25
	public function testRenewAfter()
26
	{
27
		$context = \TestHelperCntl::getContext();
28
29
		$mailStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\None' )
30
			->disableOriginalConstructor()
31
			->getMock();
32
33
		$mailMsgStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' )
34
			->disableOriginalConstructor()
35
			->disableOriginalClone()
36
			->getMock();
37
38
		$mailStub->expects( $this->once() )
39
			->method( 'createMessage' )
40
			->will( $this->returnValue( $mailMsgStub ) );
41
42
		$context->setMail( $mailStub );
43
		$subscription = $this->getSubscription( $context )->setReason( \Aimeos\MShop\Subscription\Item\Iface::REASON_PAYMENT );
44
		$order = \Aimeos\MShop::create( $context, 'order' )->createItem();
45
46
		$object = new \Aimeos\Controller\Common\Subscription\Process\Processor\Email\Standard( $context );
47
		$object->renewAfter( $subscription, $order );
48
	}
49
50
51
	public function testEnd()
52
	{
53
		$context = \TestHelperCntl::getContext();
54
55
		$mailStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\None' )
56
			->disableOriginalConstructor()
57
			->getMock();
58
59
		$mailMsgStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' )
60
			->disableOriginalConstructor()
61
			->disableOriginalClone()
62
			->getMock();
63
64
		$mailStub->expects( $this->once() )
65
			->method( 'createMessage' )
66
			->will( $this->returnValue( $mailMsgStub ) );
67
68
		$context->setMail( $mailStub );
69
70
		$object = new \Aimeos\Controller\Common\Subscription\Process\Processor\Email\Standard( $context );
71
		$object->end( $this->getSubscription( $context ) );
0 ignored issues
show
Bug introduced by
It seems like $this->getSubscription($context) can also be of type null; however, parameter $subscription of Aimeos\Controller\Common...r\Email\Standard::end() does only seem to accept Aimeos\MShop\Subscription\Item\Iface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
		$object->end( /** @scrutinizer ignore-type */ $this->getSubscription( $context ) );
Loading history...
72
	}
73
74
75
	protected function getSubscription( $context )
76
	{
77
		$manager = \Aimeos\MShop::create( $context, 'subscription' );
78
79
		$search = $manager->createSearch();
80
		$search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) );
81
82
		if( ( $item = $manager->searchItems( $search )->first() ) === null ) {
83
			throw new \Exception( 'No subscription item found' );
84
		}
85
86
		return $item;
87
	}
88
}
89