|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the DbImporter package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Mauro Cassani<https://github.com/mauretto78> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace DbImporter\Tests; |
|
12
|
|
|
|
|
13
|
|
|
use DbImporter\Importer; |
|
14
|
|
|
|
|
15
|
|
|
class ImporterTest extends BaseTestCase |
|
16
|
|
|
{ |
|
17
|
|
|
const TABLE_NAME = 'photos_table'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
private $config; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* setUp |
|
26
|
|
|
*/ |
|
27
|
|
|
public function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->config = require __DIR__.'/../app/bootstrap.php'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @test |
|
34
|
|
|
* @expectedException \DbImporter\Exceptions\NotAllowedDriverException |
|
35
|
|
|
* @expectedExceptionMessage The driver sqlsrv is not allowed. Drivers allowed are: [pdo_mysql,pdo_pgsql,pdo_sqlite] |
|
36
|
|
|
*/ |
|
37
|
|
|
public function it_throws_NotAllowedDriverException_if_a_not_yet_supported_driver_is_provided() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->makeTest( |
|
40
|
|
|
$this->config['sqlsrv_url'], |
|
41
|
|
|
'single', |
|
42
|
|
|
$this->createPhotosArray(3) |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @test |
|
48
|
|
|
* @expectedException \DbImporter\Exceptions\NotAllowedModeException |
|
49
|
|
|
* @expectedExceptionMessage The mode not-allowed-insert-mode is not allowed. Drivers allowed are: [single,multiple] |
|
50
|
|
|
*/ |
|
51
|
|
|
public function it_throws_NotAllowedModeException_if_a_not_yet_supported_driver_is_provided() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->makeTest( |
|
54
|
|
|
$this->config['mysql_url'], |
|
55
|
|
|
'not-allowed-insert-mode', |
|
56
|
|
|
$this->createPhotosArray(3) |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @test |
|
62
|
|
|
* @expectedException \DbImporter\Exceptions\NotIterableDataException |
|
63
|
|
|
* @expectedExceptionMessage Data is not iterable |
|
64
|
|
|
*/ |
|
65
|
|
|
public function it_throws_NotIterableDataException_if_data_provided_is_not_iterable() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->makeTest( |
|
68
|
|
|
$this->config['mysql_url'], |
|
69
|
|
|
'single', |
|
70
|
|
|
'string' |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @test |
|
76
|
|
|
*/ |
|
77
|
|
|
public function execute_the_multiple_import_query_with_mysql_driver() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->makeTest( |
|
80
|
|
|
$this->config['mysql_url'], |
|
81
|
|
|
'multiple', |
|
82
|
|
|
$this->createPhotosStdClassArray(5000) |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
$this->makeTest( |
|
86
|
|
|
$this->config['mysql_url'], |
|
87
|
|
|
'multiple', |
|
88
|
|
|
$this->createPhotosArray(5000) |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
$this->makeTest( |
|
92
|
|
|
$this->config['mysql_url'], |
|
93
|
|
|
'multiple', |
|
94
|
|
|
$this->createPhotosCollection(5000) |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @test |
|
100
|
|
|
*/ |
|
101
|
|
|
public function execute_the_multiple_import_query_with_pgsql_driver() |
|
102
|
|
|
{ |
|
103
|
|
|
$this->makeTest( |
|
104
|
|
|
$this->config['pgsql_url'], |
|
105
|
|
|
'multiple', |
|
106
|
|
|
$this->createPhotosStdClassArray(5000) |
|
107
|
|
|
); |
|
108
|
|
|
|
|
109
|
|
|
$this->makeTest( |
|
110
|
|
|
$this->config['pgsql_url'], |
|
111
|
|
|
'multiple', |
|
112
|
|
|
$this->createPhotosArray(5000) |
|
113
|
|
|
); |
|
114
|
|
|
|
|
115
|
|
|
$this->makeTest( |
|
116
|
|
|
$this->config['pgsql_url'], |
|
117
|
|
|
'multiple', |
|
118
|
|
|
$this->createPhotosCollection(5000) |
|
119
|
|
|
); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @test |
|
124
|
|
|
*/ |
|
125
|
|
|
public function execute_the_multiple_import_query_with_sqlite_driver() |
|
126
|
|
|
{ |
|
127
|
|
|
$this->makeTest( |
|
128
|
|
|
$this->config['sqlite_url'], |
|
129
|
|
|
'multiple', |
|
130
|
|
|
$this->createPhotosStdClassArray(100) |
|
131
|
|
|
); |
|
132
|
|
|
|
|
133
|
|
|
$this->makeTest( |
|
134
|
|
|
$this->config['sqlite_url'], |
|
135
|
|
|
'multiple', |
|
136
|
|
|
$this->createPhotosArray(100) |
|
137
|
|
|
); |
|
138
|
|
|
|
|
139
|
|
|
$this->makeTest( |
|
140
|
|
|
$this->config['sqlite_url'], |
|
141
|
|
|
'multiple', |
|
142
|
|
|
$this->createPhotosCollection(100) |
|
143
|
|
|
); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @test |
|
148
|
|
|
*/ |
|
149
|
|
|
public function execute_the_single_import_query_with_mysql_driver() |
|
150
|
|
|
{ |
|
151
|
|
|
$this->makeTest( |
|
152
|
|
|
$this->config['mysql_url'], |
|
153
|
|
|
'single', |
|
154
|
|
|
$this->createPhotosStdClassArray(5000) |
|
155
|
|
|
); |
|
156
|
|
|
|
|
157
|
|
|
$this->makeTest( |
|
158
|
|
|
$this->config['mysql_url'], |
|
159
|
|
|
'single', |
|
160
|
|
|
$this->createPhotosArray(5000) |
|
161
|
|
|
); |
|
162
|
|
|
|
|
163
|
|
|
$this->makeTest( |
|
164
|
|
|
$this->config['mysql_url'], |
|
165
|
|
|
'single', |
|
166
|
|
|
$this->createPhotosCollection(5000) |
|
167
|
|
|
); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @test |
|
172
|
|
|
*/ |
|
173
|
|
|
public function execute_the_single_import_query_with_pgsql_driver() |
|
174
|
|
|
{ |
|
175
|
|
|
$this->makeTest( |
|
176
|
|
|
$this->config['pgsql_url'], |
|
177
|
|
|
'single', |
|
178
|
|
|
$this->createPhotosStdClassArray(5000) |
|
179
|
|
|
); |
|
180
|
|
|
|
|
181
|
|
|
$this->makeTest( |
|
182
|
|
|
$this->config['pgsql_url'], |
|
183
|
|
|
'single', |
|
184
|
|
|
$this->createPhotosArray(5000) |
|
185
|
|
|
); |
|
186
|
|
|
|
|
187
|
|
|
$this->makeTest( |
|
188
|
|
|
$this->config['pgsql_url'], |
|
189
|
|
|
'single', |
|
190
|
|
|
$this->createPhotosCollection(5000) |
|
191
|
|
|
); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @test |
|
196
|
|
|
*/ |
|
197
|
|
|
public function execute_the_single_import_query_with_sqlite_driver() |
|
198
|
|
|
{ |
|
199
|
|
|
$this->makeTest( |
|
200
|
|
|
$this->config['sqlite_url'], |
|
201
|
|
|
'single', |
|
202
|
|
|
$this->createPhotosStdClassArray(100) |
|
203
|
|
|
); |
|
204
|
|
|
|
|
205
|
|
|
$this->makeTest( |
|
206
|
|
|
$this->config['sqlite_url'], |
|
207
|
|
|
'single', |
|
208
|
|
|
$this->createPhotosArray(100) |
|
209
|
|
|
); |
|
210
|
|
|
|
|
211
|
|
|
$this->makeTest( |
|
212
|
|
|
$this->config['sqlite_url'], |
|
213
|
|
|
'single', |
|
214
|
|
|
$this->createPhotosCollection(100) |
|
215
|
|
|
); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @param $url |
|
220
|
|
|
* @param $mode |
|
221
|
|
|
* @param $data |
|
222
|
|
|
*/ |
|
223
|
|
|
private function makeTest($url, $mode, $data) |
|
224
|
|
|
{ |
|
225
|
|
|
$connection = $this->getConnection($url); |
|
226
|
|
|
|
|
227
|
|
|
$mapping = [ |
|
228
|
|
|
'id' => 'id', |
|
229
|
|
|
'album_id' => 'albumId', |
|
230
|
|
|
'titolo' => 'title', |
|
231
|
|
|
'url' => 'url', |
|
232
|
|
|
'thumbnail_url' => 'thumbnailUrl', |
|
233
|
|
|
]; |
|
234
|
|
|
|
|
235
|
|
|
$keys = [ |
|
236
|
|
|
'id' => 'integer', |
|
237
|
|
|
'album_id' => 'integer', |
|
238
|
|
|
'titolo' => 'string', |
|
239
|
|
|
'url' => 'string', |
|
240
|
|
|
'thumbnail_url' => 'string', |
|
241
|
|
|
]; |
|
242
|
|
|
|
|
243
|
|
|
$uniqueKeys = ['id']; |
|
244
|
|
|
|
|
245
|
|
|
$importer = Importer::init( |
|
246
|
|
|
$connection, |
|
247
|
|
|
self::TABLE_NAME, |
|
248
|
|
|
$mapping, |
|
249
|
|
|
$data, |
|
250
|
|
|
true, |
|
251
|
|
|
$mode |
|
252
|
|
|
); |
|
253
|
|
|
|
|
254
|
|
|
$this->executeImportQueryAndPerformTests( |
|
255
|
|
|
$importer, |
|
256
|
|
|
$connection, |
|
257
|
|
|
self::TABLE_NAME, |
|
258
|
|
|
$keys, |
|
259
|
|
|
$uniqueKeys |
|
260
|
|
|
); |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|