Passed
Push — master ( ffa4cd...db3132 )
by Aimeos
02:35
created

EzpublishTest::testClear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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), 2016-2018
6
 */
7
8
9
namespace Aimeos\MShop\Customer\Manager\Group;
10
11
12
class EzpublishTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
17
18
	protected function setUp() : void
19
	{
20
		$this->context = \TestHelper::getContext();
21
		$customer = new \Aimeos\MShop\Customer\Manager\Ezpublish( $this->context );
22
23
		$this->object = $customer->getSubManager( 'group', 'Ezpublish' );
24
	}
25
26
27
	protected function tearDown() : void
28
	{
29
		unset( $this->object );
30
	}
31
32
33
	public function testClear()
34
	{
35
		$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( array( -1 ) ) );
36
	}
37
38
39
	public function testDeleteItems()
40
	{
41
		$this->expectException( '\\Aimeos\\MShop\\Exception' );
42
		$this->object->deleteItems( array( -1 ) );
43
	}
44
45
46
	public function testGetSearchAttributes()
47
	{
48
		$attributes = $this->object->getSearchAttributes();
49
		$this->assertGreaterThan( 0, count( $attributes ) );
50
51
		foreach( $attributes as $attribute ) {
52
			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute );
53
		}
54
	}
55
56
57
	public function testGetSubManager()
58
	{
59
		$this->expectException( '\\Aimeos\\MShop\\Exception' );
60
		$this->object->getSubManager( 'unknown' );
61
	}
62
63
64
	public function testSaveItem()
65
	{
66
		$this->expectException( '\\Aimeos\\MShop\\Customer\\Exception' );
67
		$this->object->saveItem( new \Aimeos\MShop\Customer\Item\Group\Standard() );
68
	}
69
70
71
	public function testSearchItems()
72
	{
73
		$mock = $this->getMockBuilder( \Aimeos\MShop\Customer\Manager\Group\Ezpublish::class )
74
			->setConstructorArgs( array( \TestHelper::getContext() ) )
75
			->setMethods( array( 'searchItemsBase' ) )
76
			->getMock();
77
78
		$result = $this->getMockBuilder( \Aimeos\MW\DB\Result\Iface::class )
79
			->setMethods( array( 'affectedRows', 'fetch', 'finish', 'nextResult' ) )
80
			->getMock();
81
82
		$mock->expects( $this->once() )->method( 'searchItemsBase' )
83
			->will( $this->returnValue( $result ) );
84
85
		$result->expects( $this->exactly( 2 ) )->method( 'fetch' )
86
			->will( $this->onConsecutiveCalls( array( 'customer.group.id' => 1 ), null ) );
87
88
		$result = $mock->searchItems( $mock->createSearch() );
89
90
		$this->assertEquals( 1, count( $result ) );
91
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Group\Iface::class, $result[1] );
92
	}
93
94
95
	public function testSearchItemsException()
96
	{
97
		$mock = $this->getMockBuilder( \Aimeos\MShop\Customer\Manager\Group\Ezpublish::class )
98
			->setConstructorArgs( array( \TestHelper::getContext() ) )
99
			->setMethods( array( 'searchItemsBase' ) )
100
			->getMock();
101
102
		$mock->expects( $this->once() )->method( 'searchItemsBase' )
103
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
104
105
		$this->expectException( '\\Aimeos\\MShop\\Exception' );
106
		$mock->searchItems( $mock->createSearch() );
107
	}
108
}
109