Completed
Push — master ( 325f51...2c9b99 )
by Aimeos
12:01
created

TraitsTest::tearDown()   A

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), 2018
6
 */
7
8
9
namespace Aimeos\MShop\Common\Item\PropertyRef;
10
11
12
class TraitsClass
13
{
14
	use \Aimeos\MShop\Common\Item\PropertyRef\Traits;
15
16
	public function setPropertyItems( $list )
17
	{
18
		$this->propItems = $list;
19
	}
20
}
21
22
23
class TraitsTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
24
{
25
	private $object;
26
	private $propItem;
27
	private $propItem2;
28
29
30
	protected function setUp()
31
	{
32
		$this->propItem = new \Aimeos\MShop\Common\Item\Property\Standard( 'c.', ['languageid' => 'de', 'c.type' => 'test']);
33
		$this->propItem2 = new \Aimeos\MShop\Common\Item\Property\Standard( 'c.', ['languageid' => 'de', 'c.languageid' => 'en', 'c.type' => 'test2']);
34
35
		$this->object = new TraitsClass();
36
		$this->object->setPropertyItems( [$this->propItem, $this->propItem2] );
37
	}
38
39
40
	protected function tearDown()
41
	{
42
		unset( $this->object, $this->propItem, $this->propItem2 );
43
	}
44
45
46
	public function testGetPropertyItems()
47
	{
48
		$expected = [$this->propItem, $this->propItem2];
49
		$this->assertEquals( $expected, $this->object->getPropertyItems( null, false ) );
50
	}
51
52
53
	public function testGetPropertyItemsActive()
54
	{
55
		$this->assertEquals( [$this->propItem], $this->object->getPropertyItems() );
56
	}
57
58
59
	public function testGetPropertyItemsWithType()
60
	{
61
		$this->assertEquals( [1 => $this->propItem2], $this->object->getPropertyItems( 'test2', false ) );
62
	}
63
64
65
	public function testGetPropertyItemsWithTypes()
66
	{
67
		$expected = [$this->propItem, $this->propItem2];
68
		$this->assertEquals( $expected, $this->object->getPropertyItems( ['test', 'test2'], false ) );
69
	}
70
71
72
	public function testGetPropertyItemsDeleted()
73
	{
74
		$this->assertEquals( [], $this->object->getPropertyItemsDeleted() );
75
	}
76
77
78
	public function testAddPropertyItem()
79
	{
80
		$object = new TraitsClass();
81
		$object->addPropertyItem( $this->propItem );
82
83
		$this->assertEquals( ['id-0' => $this->propItem], $object->getPropertyItems() );
84
	}
85
86
87
	public function testDeletePropertyItem()
88
	{
89
		$this->object->deletePropertyItem( $this->propItem->setId( 123 ) );
90
91
		$this->assertEquals( [1 => $this->propItem2], $this->object->getPropertyItems( null, false ) );
92
		$this->assertEquals( [123 => $this->propItem], $this->object->getPropertyItemsDeleted() );
93
	}
94
95
96
	public function testDeletePropertyItemException()
97
	{
98
		$object = new TraitsClass();
99
100
		$this->setExpectedException( '\Aimeos\MShop\Exception' );
101
		$object->deletePropertyItem( $this->propItem );
102
	}
103
}
104