Passed
Push — master ( 331f12...0643a3 )
by Aimeos
03:43
created

StandardTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 65
dl 0
loc 142
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 3 1
A testCreate() 0 9 1
A testSave() 0 39 1
A testGet() 0 9 1
A testSearch() 0 3 1
A setUp() 0 9 1
A testCopy() 0 9 1
A testDelete() 0 6 1
A testGetSubClient() 0 4 1
A testSaveException() 0 17 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2019
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Service\Price\Property;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
	private $context;
15
	private $object;
16
	private $view;
17
18
19
	protected function setUp()
20
	{
21
		$this->view = \TestHelperJqadm::getView();
22
		$this->context = \TestHelperJqadm::getContext();
23
24
		$this->object = new \Aimeos\Admin\JQAdm\Service\Price\Property\Standard( $this->context );
25
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
26
		$this->object->setAimeos( \TestHelperJqadm::getAimeos() );
27
		$this->object->setView( $this->view );
28
	}
29
30
31
	protected function tearDown()
32
	{
33
		unset( $this->object, $this->view, $this->context );
34
	}
35
36
37
	public function testCreate()
38
	{
39
		$manager = \Aimeos\MShop::create( $this->context, 'service' );
40
41
		$this->view->item = $manager->createItem();
42
		$result = $this->object->create();
43
44
		$this->assertContains( 'Price properties', $result );
45
		$this->assertNull( $this->view->get( 'errors' ) );
46
	}
47
48
49
	public function testCopy()
50
	{
51
		$manager = \Aimeos\MShop::create( $this->context, 'service' );
52
53
		$this->view->item = $manager->findItem( 'unitcode', ['price'] );
54
		$result = $this->object->copy();
55
56
		$this->assertNull( $this->view->get( 'errors' ) );
57
		$this->assertContains( 'item-price-property', $result );
58
	}
59
60
61
	public function testDelete()
62
	{
63
		$result = $this->object->delete();
64
65
		$this->assertNull( $this->view->get( 'errors' ) );
66
		$this->assertNull( $result );
67
	}
68
69
70
	public function testGet()
71
	{
72
		$manager = \Aimeos\MShop::create( $this->context, 'service' );
73
74
		$this->view->item = $manager->findItem( 'unitcode', ['price'] );
75
		$result = $this->object->get();
76
77
		$this->assertNull( $this->view->get( 'errors' ) );
78
		$this->assertContains( 'item-price-property', $result );
79
	}
80
81
82
	public function testSave()
83
	{
84
		$manager = \Aimeos\MShop::create( $this->context, 'service' );
85
86
		$item = $manager->findItem( 'unitcode', ['price'] );
87
		$item->setCode( 'jqadm-test-price-property' );
88
		$item->setId( null );
89
90
		$this->view->item = $manager->saveItem( $item );
91
92
		$param = array(
93
			'site' => 'unittest',
94
			'price' => array(
95
				0 => array(
96
					'property' => array(
97
						0 => array(
98
							'price.property.id' => '',
99
							'price.property.type' => 'taxrate-local',
100
						),
101
					),
102
				),
103
			),
104
		);
105
106
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
107
		$this->view->addHelper( 'param', $helper );
108
109
110
		$result = $this->object->save();
111
112
113
		$manager->deleteItem( $this->view->item->getId() );
114
115
		$this->assertNull( $this->view->get( 'errors' ) );
116
		$this->assertNull( $result );
117
118
		$priceItems = $this->view->item->getRefItems( 'price' );
0 ignored issues
show
Bug introduced by
The method getRefItems() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Common\Item\ListRef\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Media\Item\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Supplier\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\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

118
		/** @scrutinizer ignore-call */ 
119
  $priceItems = $this->view->item->getRefItems( 'price' );
Loading history...
119
		$this->assertGreaterThanOrEqual( 1, count( $priceItems ) );
120
		$this->assertEquals( 1, count( reset( $priceItems )->getPropertyItems() ) );
121
	}
122
123
124
	public function testSaveException()
125
	{
126
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Service\Price\Property\Standard::class )
127
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
128
			->setMethods( array( 'fromArray' ) )
129
			->getMock();
130
131
		$object->expects( $this->once() )->method( 'fromArray' )
132
			->will( $this->throwException( new \RuntimeException() ) );
133
134
		$this->view = \TestHelperJqadm::getView();
135
		$this->view->item = \Aimeos\MShop::create( $this->context, 'service' )->createItem();
136
137
		$object->setView( $this->view );
138
139
		$this->setExpectedException( \RuntimeException::class );
140
		$object->save();
141
	}
142
143
144
	public function testSearch()
145
	{
146
		$this->assertNull( $this->object->search() );
147
	}
148
149
150
	public function testGetSubClient()
151
	{
152
		$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class );
153
		$this->object->getSubClient( 'unknown' );
154
	}
155
}
156