Completed
Push — master ( 3ff2c1...c2a44b )
by Aimeos
09:24
created

CustomerAddFosUserTestData::migrate()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 37
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 37
rs 8.8571
cc 3
eloc 22
nc 3
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Adds Laravel customer test data.
14
 */
15
class CustomerAddFosUserTestData extends \Aimeos\MW\Setup\Task\CustomerAddTestData
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 getPreDependencies()
23
	{
24
		return array( 'TablesAddFosUserTestData' );
25
	}
26
27
28
	/**
29
	 * Adds attribute test data.
30
	 */
31
	public function migrate()
32
	{
33
		$iface = '\\Aimeos\\MShop\\Context\\Item\\Iface';
34
		if( !( $this->additional instanceof $iface ) ) {
35
			throw new \Aimeos\MW\Setup\Exception( sprintf( 'Additionally provided object is not of type "%1$s"', $iface ) );
36
		}
37
38
		$this->msg( 'Adding Fos user bundle customer test data', 0 );
39
40
		$parentIds = array();
41
		$ds = DIRECTORY_SEPARATOR;
42
		$this->additional->setEditor( 'ai-symfony:unittest' );
43
		$path = __DIR__ . $ds . 'data' . $ds . 'customer.php';
44
45
		if( ( $testdata = include( $path ) ) === false ){
46
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for customer domain', $path ) );
47
		}
48
49
50
		$customerManager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $this->additional, 'FosUser' );
51
		$customerAddressManager = $customerManager->getSubManager( 'address', 'FosUser' );
52
53
		$search = $customerManager->createSearch();
54
		$search->setConditions( $search->compare( '=~', 'customer.code', 'UTC00' ) );
55
		$items = $customerManager->searchItems( $search );
56
57
		$this->conn->begin();
58
59
		$customerManager->deleteItems( array_keys( $items ) );
60
		$parentIds = $this->addCustomerData( $testdata, $customerManager, $customerAddressManager->createItem() );
61
		$this->addCustomerAddressData( $testdata, $customerAddressManager, $parentIds );
62
63
		$this->conn->commit();
64
65
66
		$this->status( 'done' );
67
	}
68
}
69