Passed
Push — master ( 8f16ed...3311dc )
by Aimeos
10:04
created

MShop/Coupon/Provider/Decorator/SupplierTest.php (10 issues)

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2018
6
 */
7
8
9
namespace Aimeos\MShop\Coupon\Provider\Decorator;
10
11
12
class SupplierTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $context;
16
	private $orderBase;
17
	private $couponItem;
18
19
20
	protected function setUp()
21
	{
22
		$this->context = \TestHelperMShop::getContext();
23
		$this->couponItem = \Aimeos\MShop\Coupon\Manager\Factory::create( $this->context )->createItem();
24
25
		$provider = new \Aimeos\MShop\Coupon\Provider\Example( $this->context, $this->couponItem, 'abcd' );
0 ignored issues
show
$this->couponItem of type Aimeos\MShop\Attribute\Item\Iface is incompatible with the type Aimeos\MShop\Coupon\Item\Iface expected by parameter $item of Aimeos\MShop\Coupon\Prov...\Example::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
		$provider = new \Aimeos\MShop\Coupon\Provider\Example( $this->context, /** @scrutinizer ignore-type */ $this->couponItem, 'abcd' );
Loading history...
26
		$this->object = new \Aimeos\MShop\Coupon\Provider\Decorator\Supplier( $provider, $this->context, $this->couponItem, 'abcd');
0 ignored issues
show
$this->couponItem of type Aimeos\MShop\Attribute\Item\Iface is incompatible with the type Aimeos\MShop\Coupon\Item\Iface expected by parameter $couponItem of Aimeos\MShop\Coupon\Prov...Supplier::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
		$this->object = new \Aimeos\MShop\Coupon\Provider\Decorator\Supplier( $provider, $this->context, /** @scrutinizer ignore-type */ $this->couponItem, 'abcd');
Loading history...
27
		$this->object->setObject( $this->object );
28
29
		$priceManager = \Aimeos\MShop::create( $this->context, 'price' );
30
		$serviceManager = \Aimeos\MShop::create( $this->context, 'service' );
31
		$service = $serviceManager->findItem( 'unitcode' );
32
33
		$orderServiceAttrManager = \Aimeos\MShop::create( $this->context, 'order/base/service/attribute' );
34
		$orderServiceAttr = $orderServiceAttrManager->createItem();
35
		$orderServiceAttr->setCode( 'supplier.code' );
36
		$orderServiceAttr->setType( 'delivery' );
37
		$orderServiceAttr->setValue( 'berlin' );
0 ignored issues
show
The method setValue() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
		$orderServiceAttr->/** @scrutinizer ignore-call */ 
38
                     setValue( 'berlin' );

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...
38
39
		$orderServiceManager = \Aimeos\MShop::create( $this->context, 'order/base/service' );
40
		$orderService = $orderServiceManager->createItem();
41
		$orderService->copyFrom( $service );
0 ignored issues
show
The method copyFrom() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
		$orderService->/** @scrutinizer ignore-call */ 
42
                 copyFrom( $service );

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...
42
		$orderService->setAttributeItems( [$orderServiceAttr] );
0 ignored issues
show
The method setAttributeItems() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
		$orderService->/** @scrutinizer ignore-call */ 
43
                 setAttributeItems( [$orderServiceAttr] );

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...
43
44
		$this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard( $priceManager->createItem(), $this->context->getLocale() );
0 ignored issues
show
$priceManager->createItem() of type Aimeos\MShop\Attribute\Item\Iface is incompatible with the type Aimeos\MShop\Price\Item\Iface expected by parameter $price of Aimeos\MShop\Order\Item\...Standard::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
		$this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard( /** @scrutinizer ignore-type */ $priceManager->createItem(), $this->context->getLocale() );
Loading history...
45
		$this->orderBase->addService( $orderService, \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY );
0 ignored issues
show
$orderService of type Aimeos\MShop\Attribute\Item\Iface is incompatible with the type Aimeos\MShop\Order\Item\Base\Service\Iface expected by parameter $service of Aimeos\MShop\Order\Item\Base\Base::addService(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
		$this->orderBase->addService( /** @scrutinizer ignore-type */ $orderService, \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY );
Loading history...
46
	}
47
48
49
	protected function tearDown()
50
	{
51
		unset( $this->object );
52
		unset( $this->orderBase );
53
		unset( $this->couponItem );
54
	}
55
56
57
	public function testGetConfigBE()
0 ignored issues
show
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
58
	{
59
		$result = $this->object->getConfigBE();
60
61
		$this->assertArrayHasKey( 'supplier.code', $result );
62
	}
63
64
65
	public function testCheckConfigBE()
0 ignored issues
show
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
66
	{
67
		$attributes = ['supplier.code' => 'test'];
68
		$result = $this->object->checkConfigBE( $attributes );
69
70
		$this->assertEquals( 1, count( $result ) );
71
		$this->assertInternalType( 'null', $result['supplier.code'] );
72
	}
73
74
75
	public function testCheckConfigBEFailure()
0 ignored issues
show
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
76
	{
77
		$result = $this->object->checkConfigBE( [] );
78
79
		$this->assertEquals( 1, count( $result ) );
80
		$this->assertInternalType( 'string', $result['supplier.code'] );
81
	}
82
83
84
	public function testIsAvailable()
85
	{
86
		$this->couponItem->setConfig( array( 'supplier.code' => 'berlin' ) );
87
88
		$this->assertTrue( $this->object->isAvailable( $this->orderBase ) );
89
	}
90
91
92
	public function testIsAvailableWrongSupplier()
93
	{
94
		$this->couponItem->setConfig( array( 'supplier.code' => 'hamburg' ) );
95
96
		$this->assertFalse( $this->object->isAvailable( $this->orderBase ) );
97
	}
98
99
100
	public function testIsAvailableNoSupplier()
101
	{
102
		$this->assertFalse( $this->object->isAvailable( $this->orderBase ) );
103
	}
104
}
105