StandardTest::testGetDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2025
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 = \TestHelper::context();
21
		$this->aimeos = \TestHelper::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
		$mailerStub = $this->getMockBuilder( '\\Aimeos\\Base\\Mail\\Manager\\None' )
48
			->disableOriginalConstructor()
49
			->getMock();
50
51
		$mailStub = $this->getMockBuilder( '\\Aimeos\\Base\\Mail\\None' )
52
			->disableOriginalConstructor()
53
			->getMock();
54
55
		$mailMsgStub = $this->getMockBuilder( '\\Aimeos\\Base\\Mail\\Message\\None' )
56
			->disableOriginalConstructor()
57
			->disableOriginalClone()
58
			->onlyMethods( ['send'] )
59
			->getMock();
60
61
		$mailerStub->expects( $this->once() )->method( 'get' )->willReturn( $mailStub );
62
		$mailStub->expects( $this->once() )->method( 'create' )->willReturn( $mailMsgStub );
63
		$mailMsgStub->expects( $this->once() )->method( 'send' );
64
65
		$this->context->setMail( $mailerStub );
66
67
68
		$product = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNC', ['media', 'price', 'text'] );
69
		$price = $product->getRefItems( 'price', 'default', 'default' )->first();
70
71
		$object = $this->getMockBuilder( '\\Aimeos\\Controller\\Jobs\\Customer\\Email\\Watch\\Standard' )
72
			->setConstructorArgs( array( $this->context, $this->aimeos ) )
73
			->onlyMethods( ['products'] )
74
			->getMock();
75
76
		$object->expects( $this->once() )->method( 'products' )
77
			->willReturn( [$product->set( 'price', $price )] );
78
79
80
		$object->run();
81
	}
82
83
84
	public function testRunException()
85
	{
86
		$object = $this->getMockBuilder( '\\Aimeos\\Controller\\Jobs\\Customer\\Email\\Watch\\Standard' )
87
			->setConstructorArgs( [$this->context, $this->aimeos] )
88
			->onlyMethods( ['products', 'send'] )
89
			->getMock();
90
91
		$object->expects( $this->once() )->method( 'products' )->willReturn( [new \stdClass()] );
92
		$object->expects( $this->once() )->method( 'send' )->will( $this->throwException( new \RuntimeException() ) );
93
94
		$object->run();
95
	}
96
}
97