Passed
Push — master ( 248c2a...d86f73 )
by Aimeos
05:10
created

BasketTestData   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomer() 0 4 1
A after() 0 3 1
A up() 0 20 3
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2022-2025
6
 */
7
8
9
namespace Aimeos\Upscheme\Task;
10
11
12
/**
13
 * Adds basket test data.
14
 */
15
class BasketTestData extends Base
16
{
17
	/**
18
	 * Returns the list of task names which this task depends on.
19
	 *
20
	 * @return string[] List of task names
21
	 */
22
	public function after() : array
23
	{
24
		return ['Order'];
25
	}
26
27
28
	/**
29
	 * Adds basket test data.
30
	 */
31
	public function up()
32
	{
33
		$this->info( 'Adding basket test data', 'vv' );
34
		$context = $this->context()->setEditor( 'core' );
0 ignored issues
show
Bug introduced by
The method context() does not exist on Aimeos\Upscheme\Task\BasketTestData. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

34
		$context = $this->/** @scrutinizer ignore-call */ context()->setEditor( 'core' );
Loading history...
35
36
		$path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'basket.php';
37
38
		if( ( $testdata = include( $path ) ) == false ) {
39
			throw new \RuntimeException( sprintf( 'No file "%1$s" found for baskets', $path ) );
40
		}
41
42
		$orderManager = \Aimeos\MShop::create( $context, 'order', 'Standard' );
43
		$manager = \Aimeos\MShop::create( $context, 'basket', 'Standard' );
44
		$manager->begin();
45
46
		foreach( $testdata as $entry ) {
47
			$manager->save( $manager->create()->fromArray( $entry, true )->setItem( $orderManager->create() ) );
48
		}
49
50
		$manager->commit();
51
	}
52
53
54
	protected function getCustomer() : \Aimeos\MShop\Customer\Item\Iface
55
	{
56
		$manager = \Aimeos\MShop::create( $this->context(), 'customer', 'Standard' );
57
		return $manager->find( '[email protected]' );
58
	}
59
}
60