Passed
Push — master ( 63bc59...352b21 )
by Aimeos
148:01 queued 75:12
created

PriceAddTestData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPreDependencies() 0 3 1
A getData() 0 9 2
A process() 0 8 1
A getManager() 0 7 2
A migrate() 0 10 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2020
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\BaseAddTestData
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() : array
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
38
		$this->additional->setEditor( 'core:lib/mshoplib' );
39
		$this->process( $this->getData() );
40
41
		$this->status( 'done' );
42
	}
43
44
45
	/**
46
	 * Returns the test data array
47
	 *
48
	 * @return array Multi-dimensional array of test data
49
	 */
50
	protected function getData()
51
	{
52
		$path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'price.php';
53
54
		if( ( $testdata = include( $path ) ) == false ) {
55
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for price domain', $path ) );
56
		}
57
58
		return $testdata;
59
	}
60
61
62
	/**
63
	 * Returns the manager for the current setup task
64
	 *
65
	 * @param string $domain Domain name of the manager
66
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object
67
	 */
68
	protected function getManager( $domain )
69
	{
70
		if( $domain === 'price' ) {
71
			return \Aimeos\MShop\Price\Manager\Factory::create( $this->additional, 'Standard' );
72
		}
73
74
		return parent::getManager( $domain );
75
	}
76
77
78
	/**
79
	 * Adds the price data from the given array
80
	 *
81
	 * @param array Multi-dimensional array of test data
0 ignored issues
show
Documentation Bug introduced by
The doc comment Multi-dimensional at position 0 could not be parsed: Unknown type name 'Multi-dimensional' at position 0 in Multi-dimensional.
Loading history...
82
	 */
83
	protected function process( array $testdata )
84
	{
85
		$manager = $this->getManager( 'price' );
86
		$manager->begin();
87
88
		$this->storeTypes( $testdata, ['price/type', 'price/lists/type', 'price/property/type'] );
89
90
		$manager->commit();
91
	}
92
}
93