Passed
Push — master ( 3311dc...3c99d6 )
by Aimeos
05:26
created

lib/mshoplib/setup/unittest/PriceAddTestData.php (6 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
10
namespace Aimeos\MW\Setup\Task;
11
12
13
/**
14
 * Adds price test data.
15
 */
16
class PriceAddTestData extends \Aimeos\MW\Setup\Task\Base
17
{
18
	/**
19
	 * Returns the list of task names which this task depends on.
20
	 *
21
	 * @return string[] List of task names
22
	 */
23
	public function getPreDependencies()
24
	{
25
		return ['MShopSetLocale'];
26
	}
27
28
29
	/**
30
	 * Adds price test data.
31
	 */
32
	public function migrate()
33
	{
34
		\Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Context\Item\Iface::class, $this->additional );
35
36
		$this->msg( 'Adding price test data', 0 );
37
		$this->additional->setEditor( 'core:lib/mshoplib' );
38
39
		$ds = DIRECTORY_SEPARATOR;
40
		$path = __DIR__ . $ds . 'data' . $ds . 'price.php';
41
42
		if( ( $testdata = include( $path ) ) == false ) {
43
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for price domain', $path ) );
44
		}
45
46
		$this->addPriceData( $testdata );
47
48
		$this->status( 'done' );
49
	}
50
51
52
	/**
53
	 * Adds the price test data.
54
	 *
55
	 * @param array $testdata Associative list of key/list pairs
56
	 * @throws \Aimeos\MW\Setup\Exception If a required ID is not available
57
	 */
58
	private function addPriceData( array $testdata )
59
	{
60
		$priceManager = \Aimeos\MShop\Price\Manager\Factory::create( $this->additional, 'Standard' );
61
		$priceTypeManager = $priceManager->getSubManager( 'type', 'Standard' );
62
63
		$ptype = $priceTypeManager->createItem();
64
65
		$priceManager->begin();
66
67
		foreach( $testdata['price/type'] as $key => $dataset )
68
		{
69
			$ptype->setId( null );
70
			$ptype->setCode( $dataset['code'] );
71
			$ptype->setDomain( $dataset['domain'] );
72
			$ptype->setLabel( $dataset['label'] );
73
			$ptype->setStatus( $dataset['status'] );
74
75
			$priceTypeManager->saveItem( $ptype );
76
		}
77
78
		$price = $priceManager->createItem();
79
		foreach( $testdata['price'] as $key => $dataset )
80
		{
81
			$price->setId( null );
82
			$price->setCurrencyId( $dataset['currencyid'] );
0 ignored issues
show
The method setCurrencyId() 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

82
			$price->/** @scrutinizer ignore-call */ 
83
           setCurrencyId( $dataset['currencyid'] );

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...
83
			$price->setType( $dataset['type'] );
84
			$price->setDomain( $dataset['domain'] );
85
			$price->setLabel( $dataset['label'] );
86
			$price->setQuantity( $dataset['quantity'] );
0 ignored issues
show
The method setQuantity() 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

86
			$price->/** @scrutinizer ignore-call */ 
87
           setQuantity( $dataset['quantity'] );

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...
87
			$price->setValue( $dataset['value'] );
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

87
			$price->/** @scrutinizer ignore-call */ 
88
           setValue( $dataset['value'] );

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...
88
			$price->setCosts( $dataset['shipping'] );
0 ignored issues
show
The method setCosts() 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

88
			$price->/** @scrutinizer ignore-call */ 
89
           setCosts( $dataset['shipping'] );

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...
89
			$price->setRebate( $dataset['rebate'] );
0 ignored issues
show
The method setRebate() 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

89
			$price->/** @scrutinizer ignore-call */ 
90
           setRebate( $dataset['rebate'] );

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...
90
			$price->setTaxRate( $dataset['taxrate'] );
0 ignored issues
show
The method setTaxRate() 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

90
			$price->/** @scrutinizer ignore-call */ 
91
           setTaxRate( $dataset['taxrate'] );

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...
91
			$price->setStatus( $dataset['status'] );
92
93
			$priceManager->saveItem( $price, false );
94
		}
95
96
		$priceManager->commit();
97
	}
98
}
99