1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maketok\DataMigration\IntegrationTest\ComplexStructure; |
4
|
|
|
|
5
|
|
|
use Maketok\DataMigration\Action\ConfigInterface; |
6
|
|
|
use Maketok\DataMigration\Action\Type\AssembleInput; |
7
|
|
|
use Maketok\DataMigration\Action\Type\Dump; |
8
|
|
|
use Maketok\DataMigration\Action\Type\ReverseMove; |
9
|
|
|
use Maketok\DataMigration\ArrayMap; |
10
|
|
|
use Maketok\DataMigration\Expression\HelperExpressionsProvider; |
11
|
|
|
use Maketok\DataMigration\Expression\LanguageAdapter; |
12
|
|
|
use Maketok\DataMigration\Input\ArrayInput; |
13
|
|
|
use Maketok\DataMigration\QueueWorkflow; |
14
|
|
|
use Maketok\DataMigration\Storage\Db\DBALMysqlResource; |
15
|
|
|
use Maketok\DataMigration\Unit\SimpleBag; |
16
|
|
|
use Maketok\DataMigration\Unit\Type\Unit; |
17
|
|
|
use Maketok\DataMigration\Workflow\Result; |
18
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
19
|
|
|
|
20
|
|
|
class ComplexTreeTest extends \PHPUnit_Extensions_Database_TestCase |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ConfigInterface |
24
|
|
|
*/ |
25
|
|
|
private $config; |
26
|
|
|
/** |
27
|
|
|
* @var DBALMysqlResource |
28
|
|
|
*/ |
29
|
|
|
private $resource; |
30
|
|
|
/** |
31
|
|
|
* @var \PDO |
32
|
|
|
*/ |
33
|
|
|
private $pdo; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
protected function setUp() |
39
|
|
|
{ |
40
|
|
|
$config = include dirname(__DIR__) . '/Storage/Db/assets/config.php'; |
41
|
|
|
if (isset($config) && $config instanceof ConfigInterface) { |
42
|
|
|
$this->config = $config; |
43
|
|
|
$this->config['tmp_folder'] = __DIR__ . '/assets'; |
44
|
|
|
$this->config['tmp_file_mask'] = 'tmp%2$s/%1$s.csv'; |
45
|
|
|
$this->config['tmp_table_mask'] = 'tmp_%1$s_%2$s'; |
46
|
|
|
$this->config['local_infile'] = true; |
47
|
|
|
$this->resource = new DBALMysqlResource($this->config); |
48
|
|
|
$ref1 = new \ReflectionProperty(get_class($this->resource->getConnection()), '_conn'); |
49
|
|
|
$ref1->setAccessible(true); |
50
|
|
|
$this->pdo = $ref1->getValue($this->resource->getConnection()); |
51
|
|
|
} else { |
52
|
|
|
throw new \Exception("Can't find config file."); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
parent::setUp(); |
56
|
|
|
|
57
|
|
|
// assert that 2 pdo's are same |
58
|
|
|
$pdo1 = $this->getConnection()->getConnection(); |
59
|
|
|
$pdo2 = $ref1->getValue($this->resource->getConnection()); |
60
|
|
|
|
61
|
|
|
$this->assertSame($pdo1, $pdo2); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function tearDown() |
65
|
|
|
{ |
66
|
|
|
parent::tearDown(); |
67
|
|
|
$this->resource->close(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return LanguageAdapter |
72
|
|
|
*/ |
73
|
|
|
public function getLanguageAdapter() |
74
|
|
|
{ |
75
|
|
|
$language = new ExpressionLanguage(); |
76
|
|
|
$language->registerProvider(new HelperExpressionsProvider()); |
77
|
|
|
return new LanguageAdapter($language); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set Up Schema |
82
|
|
|
*/ |
83
|
|
|
public static function setUpBeforeClass() |
84
|
|
|
{ |
85
|
|
|
require_once __DIR__ . '/bootstrap.php'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
protected function getConnection() |
92
|
|
|
{ |
93
|
|
|
if (isset($this->pdo)) { |
94
|
|
|
return $this->createDefaultDBConnection($this->pdo); |
95
|
|
|
} |
96
|
|
|
throw new \Exception("Can't find pdo in config."); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
|
|
protected function getDataSet() |
103
|
|
|
{ |
104
|
|
|
return $this->createXMLDataSet(__DIR__ . '/assets/initialStructure.xml'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* ===========order========= |
109
|
|
|
* / / | \ |
110
|
|
|
* invoice item shipment address |
111
|
|
|
* | // \\ | |
112
|
|
|
* item item |
113
|
|
|
* |
114
|
|
|
* | == parent-child |
115
|
|
|
* || == sibling |
116
|
|
|
*/ |
117
|
|
|
public function testExport1() |
118
|
|
|
{ |
119
|
|
|
// SET THESE TO TRUE TO DEBUG |
120
|
|
|
$this->config['db_debug'] = false; |
121
|
|
|
$this->config['file_debug'] = false; |
122
|
|
|
//=========================== |
123
|
|
|
$order = new Unit('order'); |
124
|
|
|
$order->setMapping([]); |
125
|
|
|
$order->setReversedMapping([]); |
126
|
|
|
$invoice = new Unit('invoice'); |
127
|
|
|
$invoice->setMapping([]); |
128
|
|
|
$shipment = new Unit('shipment'); |
129
|
|
|
$shipment->setMapping([]); |
130
|
|
|
$address = new Unit('address'); |
131
|
|
|
$address->setMapping([]); |
132
|
|
|
$orderItem = new Unit('order_item'); |
133
|
|
|
$orderItem->setMapping([]); |
134
|
|
|
$invoiceItem = new Unit('invoice_item'); |
135
|
|
|
$invoiceItem->setMapping([]); |
136
|
|
|
$shipmentItem = new Unit('shipment_item'); |
137
|
|
|
$shipmentItem->setMapping([]); |
138
|
|
|
|
139
|
|
|
$invoiceItem->setParent($invoice); |
140
|
|
|
$invoice->setParent($order); |
141
|
|
|
$shipmentItem->setParent($shipment); |
142
|
|
|
$shipment->setParent($invoice); |
143
|
|
|
$address->setParent($order); |
144
|
|
|
$orderItem->setParent($order); |
145
|
|
|
$orderItem->addSibling($invoiceItem); |
146
|
|
|
$orderItem->addSibling($shipmentItem); |
147
|
|
|
|
148
|
|
|
$bag = new SimpleBag(); |
149
|
|
|
$bag->addSet([$order, $invoice, $shipment, $address, $orderItem, $invoiceItem, $shipmentItem]); |
150
|
|
|
|
151
|
|
|
$input = new ArrayInput(); |
152
|
|
|
|
153
|
|
|
$reverseMove = new ReverseMove($bag, $this->config, $this->resource); |
154
|
|
|
$dump = new Dump($bag, $this->config, $this->resource); |
155
|
|
|
$assemble = new AssembleInput($bag, $this->config, $this->getLanguageAdapter(), $input, new ArrayMap()); |
156
|
|
|
|
157
|
|
|
$result = new Result(); |
158
|
|
|
$workflow = new QueueWorkflow($this->config, $result); |
159
|
|
|
$workflow->add($reverseMove); |
160
|
|
|
$workflow->add($dump); |
161
|
|
|
$workflow->add($assemble); |
162
|
|
|
|
163
|
|
|
// $workflow->execute(); |
164
|
|
|
//===================================================================== |
165
|
|
|
// assert that customers are in the file |
166
|
|
|
|
167
|
|
|
// TODO assertions |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|