Passed
Push — master ( 23e72e...dc62e4 )
by Aimeos
03:22
created

StandardTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 37
c 2
b 0
f 0
dl 0
loc 78
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testRun() 0 31 1
A testGetName() 0 4 1
A tearDown() 0 3 1
A setUp() 0 4 1
A testGetDescription() 0 4 1
A testRunException() 0 11 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Customer\Email\Watch;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $aimeos;
16
17
18
	protected function setUp() : void
19
	{
20
		$this->context = \TestHelperJobs::context();
21
		$this->aimeos = \TestHelperJobs::getAimeos();
22
	}
23
24
25
	protected function tearDown() : void
26
	{
27
		unset( $this->context, $this->aimeos );
28
	}
29
30
31
	public function testGetName()
32
	{
33
		$object = new \Aimeos\Controller\Jobs\Customer\Email\Watch\Standard( $this->context, $this->aimeos );
34
		$this->assertEquals( 'Product notification e-mails', $object->getName() );
35
	}
36
37
38
	public function testGetDescription()
39
	{
40
		$object = new \Aimeos\Controller\Jobs\Customer\Email\Watch\Standard( $this->context, $this->aimeos );
41
		$this->assertEquals( 'Sends e-mails for watched products', $object->getDescription() );
42
	}
43
44
45
	public function testRun()
46
	{
47
		$mailStub = $this->getMockBuilder( '\\Aimeos\\Base\\Mail\\None' )
48
			->disableOriginalConstructor()
49
			->getMock();
50
51
		$mailMsgStub = $this->getMockBuilder( '\\Aimeos\\Base\\Mail\\Message\\None' )
52
			->disableOriginalConstructor()
53
			->disableOriginalClone()
54
			->setMethods( ['send'] )
55
			->getMock();
56
57
		$mailStub->expects( $this->once() )->method( 'create' )->will( $this->returnValue( $mailMsgStub ) );
58
		$mailMsgStub->expects( $this->once() )->method( 'send' );
59
60
		$this->context->setMail( $mailStub );
61
62
63
		$product = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNC', ['media', 'price', 'text'] );
64
		$price = $product->getRefItems( 'price', 'default', 'default' )->first();
65
66
		$object = $this->getMockBuilder( '\\Aimeos\\Controller\\Jobs\\Customer\\Email\\Watch\\Standard' )
67
			->setConstructorArgs( array( $this->context, $this->aimeos ) )
68
			->setMethods( ['products'] )
69
			->getMock();
70
71
		$object->expects( $this->once() )->method( 'products' )
72
			->will( $this->returnValue( [$product->set( 'price', $price )] ) );
73
74
75
		$object->run();
76
	}
77
78
79
	public function testRunException()
80
	{
81
		$object = $this->getMockBuilder( '\\Aimeos\\Controller\\Jobs\\Customer\\Email\\Watch\\Standard' )
82
			->setConstructorArgs( [$this->context, $this->aimeos] )
83
			->setMethods( ['products', 'send'] )
84
			->getMock();
85
86
		$object->expects( $this->once() )->method( 'products' )->will( $this->returnValue( [new \stdClass()] ) );
87
		$object->expects( $this->once() )->method( 'send' )->will( $this->throwException( new \RuntimeException() ) );
88
89
		$object->run();
90
	}
91
}
92