Completed
Push — master ( 0010c2...5cb668 )
by Aimeos
02:18
created

StandardTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A tearDown() 0 5 1
B testProcess() 0 35 1
B testProcessUpdate() 0 36 1
B testProcessEmpty() 0 29 1
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\Common\Coupon\Import\Csv\Processor\Code;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $endpoint;
16
17
18
	protected function setUp()
19
	{
20
		\Aimeos\MShop\Factory::setCache( true );
21
22
		$this->context = \TestHelperCntl::getContext();
23
		$this->endpoint = new \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Done( $this->context, [] );
24
	}
25
26
27
	protected function tearDown()
28
	{
29
		\Aimeos\MShop\Factory::setCache( false );
30
		\Aimeos\MShop\Factory::clear();
31
	}
32
33
34
	public function testProcess()
35
	{
36
		$mapping = array(
37
			0 => 'coupon.code.code',
38
			1 => 'coupon.code.count',
39
			2 => 'coupon.code.datestart',
40
			3 => 'coupon.code.dateend',
41
		);
42
43
		$data = array(
44
			0 => 'jobimporttest',
45
			1 => '10',
46
			2 => '2000-01-01 00:00:00',
47
			3 => '',
48
		);
49
50
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon' );
51
		$codeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon/code' );
52
53
		$coupon = $manager->saveItem( $manager->createItem()->setProvider( 'test' ) );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $coupon is correct as $manager->saveItem($mana...)->setProvider('test')) (which targets Aimeos\MShop\Common\Manager\Iface::saveItem()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
54
		$couponCode = $codeManager->createItem();
55
		$couponCode->setParentId( $coupon->getId() );
0 ignored issues
show
Bug introduced by
The method getId cannot be called on $coupon (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
56
57
		$object = new \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Code\Standard( $this->context, $mapping, $this->endpoint );
58
		$object->process( $couponCode, $data );
0 ignored issues
show
Compatibility introduced by
$couponCode of type object<Aimeos\MShop\Common\Item\Iface> is not a sub-type of object<Aimeos\MShop\Coupon\Item\Code\Iface>. It seems like you assume a child interface of the interface Aimeos\MShop\Common\Item\Iface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
59
60
		$codeManager->deleteItem( $couponCode->getId() );
61
		$manager->deleteItem( $coupon->getId() );
0 ignored issues
show
Bug introduced by
The method getId cannot be called on $coupon (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
62
63
64
		$this->assertEquals( 10, $couponCode->getCount() );
65
		$this->assertEquals( 'jobimporttest', $couponCode->getCode() );
66
		$this->assertEquals( '2000-01-01 00:00:00', $couponCode->getDateStart() );
67
		$this->assertEquals( null, $couponCode->getDateEnd() );
68
	}
69
70
71
	public function testProcessUpdate()
72
	{
73
		$mapping = array(
74
			0 => 'coupon.code.code',
75
			1 => 'coupon.code.count',
76
		);
77
78
		$data = array(
79
			0 => 'jobimporttest',
80
			1 => '10',
81
		);
82
83
		$dataUpdate = array(
84
			0 => 'jobimporttest',
85
			1 => '5',
86
		);
87
88
89
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon' );
90
		$codeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon/code' );
91
92
		$coupon = $manager->saveItem( $manager->createItem()->setProvider( 'test' ) );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $coupon is correct as $manager->saveItem($mana...)->setProvider('test')) (which targets Aimeos\MShop\Common\Manager\Iface::saveItem()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
93
		$couponCode = $codeManager->createItem();
94
		$couponCode->setParentId( $coupon->getId() );
0 ignored issues
show
Bug introduced by
The method getId cannot be called on $coupon (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
95
96
		$object = new \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Code\Standard( $this->context, $mapping, $this->endpoint );
97
		$object->process( $couponCode, $data );
0 ignored issues
show
Compatibility introduced by
$couponCode of type object<Aimeos\MShop\Common\Item\Iface> is not a sub-type of object<Aimeos\MShop\Coupon\Item\Code\Iface>. It seems like you assume a child interface of the interface Aimeos\MShop\Common\Item\Iface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
98
		$object->process( $couponCode, $dataUpdate );
0 ignored issues
show
Compatibility introduced by
$couponCode of type object<Aimeos\MShop\Common\Item\Iface> is not a sub-type of object<Aimeos\MShop\Coupon\Item\Code\Iface>. It seems like you assume a child interface of the interface Aimeos\MShop\Common\Item\Iface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
99
100
		$codeManager->deleteItem( $couponCode->getId() );
101
		$manager->deleteItem( $coupon->getId() );
0 ignored issues
show
Bug introduced by
The method getId cannot be called on $coupon (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
102
103
104
		$this->assertEquals( 5, $couponCode->getCount() );
105
		$this->assertEquals( 'jobimporttest', $couponCode->getCode() );
106
	}
107
108
109
	public function testProcessEmpty()
110
	{
111
		$mapping = array(
112
			0 => 'coupon.code.code',
113
			1 => 'coupon.code.count',
114
		);
115
116
		$data = array(
117
			0 => 'jobimporttest',
118
			1 => '',
119
		);
120
121
122
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon' );
123
		$codeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon/code' );
124
125
		$coupon = $manager->saveItem( $manager->createItem()->setProvider( 'test' ) );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $coupon is correct as $manager->saveItem($mana...)->setProvider('test')) (which targets Aimeos\MShop\Common\Manager\Iface::saveItem()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
126
		$couponCode = $codeManager->createItem();
127
		$couponCode->setParentId( $coupon->getId() );
0 ignored issues
show
Bug introduced by
The method getId cannot be called on $coupon (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
128
129
		$object = new \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Code\Standard( $this->context, $mapping, $this->endpoint );
130
		$object->process( $couponCode, $data );
0 ignored issues
show
Compatibility introduced by
$couponCode of type object<Aimeos\MShop\Common\Item\Iface> is not a sub-type of object<Aimeos\MShop\Coupon\Item\Code\Iface>. It seems like you assume a child interface of the interface Aimeos\MShop\Common\Item\Iface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
131
132
		$codeManager->deleteItem( $couponCode->getId() );
133
		$manager->deleteItem( $coupon->getId() );
0 ignored issues
show
Bug introduced by
The method getId cannot be called on $coupon (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
134
135
136
		$this->assertEquals( 0, $couponCode->getCount() );
137
	}
138
}