Completed
Push — master ( 9d3f5c...f136ad )
by Aimeos
02:22
created

StandardTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 6
dl 0
loc 112
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A tearDown() 0 4 1
A testAddEditSaveDeleteItem() 0 22 1
A testCreateItem() 0 5 1
A testGetItem() 0 11 1
A testFindItem() 0 5 1
A testAddEditSaveDeleteAddressItem() 0 17 1
A testCreateAddressItem() 0 5 1
A testGetAddressItem() 0 15 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Customer;
10
11
12
class StandardTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $context;
15
	private $object;
16
17
18
	protected function setUp()
19
	{
20
		$this->context = \TestHelperFrontend::getContext();
21
		$this->object = new \Aimeos\Controller\Frontend\Customer\Standard( $this->context );
22
	}
23
24
25
	protected function tearDown()
26
	{
27
		unset( $this->context, $this->object );
28
	}
29
30
31
	public function testAddEditSaveDeleteItem()
32
	{
33
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' );
34
		$id = $manager->findItem( 'UTC001' )->getId();
35
36
		$this->context->setUserId( $id );
37
		$item = $this->object->addItem( ['customer.code' => 'unittest-ctnl', 'customer.status' => 1] );
38
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $item );
39
40
		$this->context->setUserId( $item->getId() );
41
		$item = $this->object->editItem( $item->getId(), ['customer.code' => 'unittest-ctnl2'] );
42
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $item );
43
44
		$item->setStatus( 0 );
45
		$this->object->saveItem( $item );
46
		$this->assertEquals( 0, $item->getStatus() );
47
48
		$this->object->deleteItem( $item->getId() );
49
50
		$this->setExpectedException( '\Aimeos\MShop\Exception' );
51
		$manager->findItem( 'unittest-ctnl' );
52
	}
53
54
55
	public function testCreateItem()
56
	{
57
		$result = $this->object->createItem();
58
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $result );
59
	}
60
61
62
	public function testGetItem()
63
	{
64
		$id = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->findItem( 'UTC001' )->getId();
65
		$this->context->setUserId( $id );
66
67
		$result = $this->object->getItem( $id, ['address', 'text'] );
68
69
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $result );
70
		$this->assertEquals( 1, count( $result->getRefItems( 'text' ) ) );
71
		$this->assertEquals( 1, count( $result->getAddressItems() ) );
0 ignored issues
show
Bug introduced by
The method getAddressItems() does not seem to exist on object<Aimeos\MShop\Customer\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
	}
73
74
75
	public function testFindItem()
76
	{
77
		$result = $this->object->findItem( 'UTC001' );
78
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $result );
79
	}
80
81
82
	public function testAddEditSaveDeleteAddressItem()
83
	{
84
		$customer = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->findItem( 'UTC001' );
85
		$this->context->setUserId( $customer->getId() );
86
87
		$item = $this->object->addAddressItem( ['customer.address.lastname' => 'unittest-ctnl'] );
88
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $item );
89
90
		$item = $this->object->editAddressItem( $item->getId(), ['customer.address.lastname' => 'unittest-ctnl2'] );
91
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $item );
92
93
		$item->setLastName( 'test' );
0 ignored issues
show
Bug introduced by
The method setLastName() does not seem to exist on object<Aimeos\MShop\Customer\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
94
		$this->object->saveAddressItem( $item );
0 ignored issues
show
Documentation introduced by
$item is of type object<Aimeos\MShop\Customer\Item\Iface>, but the function expects a object<Aimeos\MShop\Customer\Item\Address\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
95
		$this->assertEquals( 'test', $item->getLastName() );
0 ignored issues
show
Bug introduced by
The method getLastName() does not seem to exist on object<Aimeos\MShop\Customer\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
96
97
		$this->object->deleteAddressItem( $item->getId() );
98
	}
99
100
101
	public function testCreateAddressItem()
102
	{
103
		$result = $this->object->createAddressItem();
104
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $result );
105
	}
106
107
108
	public function testGetAddressItem()
109
	{
110
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/address' );
111
		$search = $manager->createSearch();
112
		$search->setSlice( 0, 1 );
113
		$result = $manager->searchItems( $search );
114
115
		if( ( $item = reset( $result ) ) === false ) {
116
			throw new \RuntimeException( 'No customer address available' );
117
		}
118
119
		$this->context->setUserId( $item->getParentId() );
120
		$result = $this->object->getAddressItem( $item->getId() );
121
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $result );
122
	}
123
}
124