Completed
Push — master ( c1f25f...b3d94f )
by Aimeos
02:05
created

setup/unittest/CustomerAddLaravelTestData.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2018
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Adds Laravel customer test data.
14
 */
15
class CustomerAddLaravelTestData 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( 'TablesAddLaravelTestData' );
25
	}
26
27
28
	/**
29
	 * Adds attribute test data.
30
	 */
31
	public function migrate()
32
	{
33
		\Aimeos\MW\Common\Base::checkClass( '\\Aimeos\\MShop\\Context\\Item\\Iface', $this->additional );
34
35
		$this->msg( 'Adding Laravel customer test data', 0 );
36
		$this->additional->setEditor( 'ai-laravel:unittest' );
37
38
		$parentIds = [];
39
		$ds = DIRECTORY_SEPARATOR;
40
		$path = __DIR__ . $ds . 'data' . $ds . 'customer.php';
41
42
		if( ( $testdata = include( $path ) ) == false ){
43
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for customer domain', $path ) );
44
		}
45
46
47
		$customerManager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $this->additional, 'Laravel' );
48
		$customerAddressManager = $customerManager->getSubManager( 'address', 'Laravel' );
49
50
		$this->cleanupCustomerData( $customerManager, $customerAddressManager );
51
52
		$this->conn->begin();
53
54
		$parentIds = $this->addCustomerData( $testdata, $customerManager, $customerAddressManager->createItem() );
0 ignored issues
show
$customerAddressManager->createItem() is of type object<Aimeos\MShop\Attribute\Item\Iface>, but the function expects a object<Aimeos\MShop\Common\Item\Address\Iface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
		$this->addCustomerAddressData( $testdata, $customerAddressManager, $parentIds );
56
57
		$this->conn->commit();
58
59
60
		$this->status( 'done' );
61
	}
62
63
64
	/**
65
	 * Removes all customer unit test entries
66
	 *
67
	 * @param \Aimeos\MShop\Common\Manager\Iface $customerManager Customer manager
68
	 * @param \Aimeos\MShop\Common\Manager\Iface $customerAddressManager Customer address manager
69
	 */
70
	protected function cleanupCustomerData( \Aimeos\MShop\Common\Manager\Iface $customerManager, \Aimeos\MShop\Common\Manager\Iface $customerAddressManager )
71
	{
72
		$search = $customerManager->createSearch();
73
		$search->setConditions( $search->compare( '=~', 'customer.code', 'UTC00' ) );
74
		$customerItems = $customerManager->searchItems( $search );
75
76
		$search = $customerAddressManager->createSearch();
77
		$search->setConditions( $search->compare( '=~', 'customer.address.email', 'unitCustomer' ) );
78
		$addressItems = $customerAddressManager->searchItems( $search );
79
80
		$customerAddressManager->deleteItems( array_keys( $addressItems ) );
81
		$customerManager->deleteItems( array_keys( $customerItems ) );
82
	}
83
}
84