Passed
Push — master ( 0a4aac...7f04e0 )
by Aimeos
05:24
created

TraitsTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A tearDown() 0 3 1
A testGetProperties() 0 3 1
A testGetPropertyItemsWithType() 0 3 1
A testGetPropertyItem() 0 3 1
A testGetPropertyItemsWithTypes() 0 4 1
A testGetPropertyItemsDeleted() 0 3 1
A testGetPropertyItems() 0 4 1
A testGetPropertyItemsActive() 0 3 1
A testDeletePropertyItemException() 0 6 1
A testAddPropertyItem() 0 6 1
A testDeletePropertyItem() 0 6 1
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
17
18
class TraitsTest extends \PHPUnit\Framework\TestCase
19
{
20
	private $object;
21
	private $propItem;
22
	private $propItem2;
23
24
25
	protected function setUp()
26
	{
27
		$this->propItem = new \Aimeos\MShop\Common\Item\Property\Standard( 'c.', ['languageid' => 'de', 'c.type' => 'test', 'c.value' => 'value']);
28
		$this->propItem2 = new \Aimeos\MShop\Common\Item\Property\Standard( 'c.', ['languageid' => 'de', 'c.languageid' => 'en', 'c.type' => 'test2']);
29
30
		$this->object = new TraitsClass();
31
		$this->object->addPropertyItem( $this->propItem );
32
		$this->object->addPropertyItem( $this->propItem2 );
33
	}
34
35
36
	protected function tearDown()
37
	{
38
		unset( $this->object, $this->propItem, $this->propItem2 );
39
	}
40
41
42
	public function testGetProperties()
43
	{
44
		$this->assertEquals( ['value'], array_values( $this->object->getProperties( 'test' ) ) );
45
	}
46
47
48
	public function testGetPropertyItem()
49
	{
50
		$this->assertEquals( $this->propItem, $this->object->getPropertyItem( 'test', null, 'value', false ) );
51
	}
52
53
54
	public function testGetPropertyItems()
55
	{
56
		$expected = [$this->propItem, $this->propItem2];
57
		$this->assertEquals( $expected, array_values( $this->object->getPropertyItems( null, false ) ) );
58
	}
59
60
61
	public function testGetPropertyItemsActive()
62
	{
63
		$this->assertEquals( [$this->propItem], array_values( $this->object->getPropertyItems() ) );
64
	}
65
66
67
	public function testGetPropertyItemsWithType()
68
	{
69
		$this->assertEquals( [$this->propItem2], array_values( $this->object->getPropertyItems( 'test2', false ) ) );
70
	}
71
72
73
	public function testGetPropertyItemsWithTypes()
74
	{
75
		$expected = [$this->propItem, $this->propItem2];
76
		$this->assertEquals( $expected, array_values( $this->object->getPropertyItems( ['test', 'test2'], false ) ) );
77
	}
78
79
80
	public function testGetPropertyItemsDeleted()
81
	{
82
		$this->assertEquals( [], $this->object->getPropertyItemsDeleted() );
83
	}
84
85
86
	public function testAddPropertyItem()
87
	{
88
		$object = new TraitsClass();
89
		$object->addPropertyItem( $this->propItem );
90
91
		$this->assertEquals( ['_test__value' => $this->propItem], $object->getPropertyItems() );
92
	}
93
94
95
	public function testDeletePropertyItem()
96
	{
97
		$this->object->deletePropertyItem( $this->propItem->setId( 123 ) );
98
99
		$this->assertEquals( [$this->propItem2], array_values( $this->object->getPropertyItems( null, false ) ) );
100
		$this->assertEquals( [$this->propItem], array_values( $this->object->getPropertyItemsDeleted() ) );
101
	}
102
103
104
	public function testDeletePropertyItemException()
105
	{
106
		$object = new TraitsClass();
107
108
		$this->setExpectedException( \Aimeos\MShop\Exception::class );
109
		$object->deletePropertyItem( $this->propItem );
110
	}
111
}
112