Skip to content

Commit 361f270

Browse files
author
Sergii Kovalenko
committed
MAGETWO-89402: Make 'db:status' command works properly
--fix static tests
1 parent 565300e commit 361f270

File tree

8 files changed

+152
-126
lines changed

8 files changed

+152
-126
lines changed

lib/internal/Magento/Framework/Setup/Declaration/Schema/Diff/Diff.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Holds 2 items:
1919
* - new (Should be changed to)
2020
* - old ()
21+
* @api
2122
*/
2223
class Diff implements DiffInterface
2324
{
@@ -147,13 +148,15 @@ private function getWhiteListTables()
147148
* Check whether element can be registered.
148149
*
149150
* For example, if element is not in db_schema_whitelist.json it cant
150-
* be registered due to backward incompatibility.
151+
* be registered due to backward incompatibility
152+
* Extensibility point: if you want to add some dynamic rules of applying or ignoring any schema elements
153+
* you can do this by pluginizing this method
151154
*
152155
* @param ElementInterface | Table $object
153156
* @param string $operation
154157
* @return bool
155158
*/
156-
private function canBeRegistered(ElementInterface $object, $operation)
159+
public function canBeRegistered(ElementInterface $object, $operation)
157160
{
158161
if (!isset($this->destructiveOperations[$operation])) {
159162
return true;

lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Db/SchemaBuilderTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ private function createTable($name)
164164
$name,
165165
'table',
166166
'default',
167-
'resource'
167+
'resource',
168+
'utf-8',
169+
'utf-8',
170+
''
168171
);
169172
}
170173

@@ -334,8 +337,8 @@ private function prepareSchemaMocks(array $columns, array $references, array $co
334337
->method('getTableOptions')
335338
->withConsecutive(...array_values($withContext))
336339
->willReturnOnConsecutiveCalls(
337-
['Engine' => 'innodb', 'Comment' => ''],
338-
['Engine' => 'innodb', 'Comment' => 'Not null comment']
340+
['engine' => 'innodb', 'comment' => '', 'charset' => 'utf-8', 'collation' => 'utf-8'],
341+
['engine' => 'innodb', 'comment' => 'Not null comment', 'charset' => 'utf-8', 'collation' => 'utf-8']
339342
);
340343
$this->dbSchemaReaderMock->expects($this->any())
341344
->method('readColumns')
@@ -383,7 +386,9 @@ private function prepareSchemaMocks(array $columns, array $references, array $co
383386
'name' =>'first_table',
384387
'resource' => 'default',
385388
'engine' => 'innodb',
386-
'comment' => null
389+
'comment' => null,
390+
'charset' => 'utf-8',
391+
'collation' => 'utf-8'
387392
]
388393
],
389394
[
@@ -433,7 +438,9 @@ private function prepareSchemaMocks(array $columns, array $references, array $co
433438
'name' =>'second_table',
434439
'resource' => 'default',
435440
'engine' => 'innodb',
436-
'comment' => 'Not null comment'
441+
'comment' => 'Not null comment',
442+
'charset' => 'utf-8',
443+
'collation' => 'utf-8'
437444
]
438445
],
439446
[

lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Declaration/SchemaBuilderTest.php

Lines changed: 8 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ private function createTable($name)
192192
$name,
193193
'table',
194194
'default',
195-
'resource'
195+
'resource',
196+
'utf-8',
197+
'utf-8',
198+
''
196199
);
197200
}
198201

@@ -314,110 +317,12 @@ public function testBuild(array $tablesData)
314317
$refColumn,
315318
'CASCADE'
316319
);
317-
$table->addColumns([$firstColumn, $foreignColumn, $timestampColumn]);
318-
$table->addConstraints([$foreignKey, $primaryKey]);
320+
$firstTableColumns = [$firstColumn, $foreignColumn, $timestampColumn];
321+
$firstTableConstraints = [$foreignKey, $primaryKey];
322+
$table->addColumns($firstTableColumns);
323+
$table->addConstraints($firstTableConstraints);
319324
$this->elementFactoryMock->expects(self::exactly(9))
320325
->method('create')
321-
->withConsecutive(
322-
[
323-
'table',
324-
[
325-
'name' =>'first_table',
326-
'resource' => 'default',
327-
'engine' => 'innodb',
328-
'comment' => null,
329-
'onCreate' => ''
330-
]
331-
],
332-
[
333-
'int',
334-
[
335-
'name' => 'first_column',
336-
'type' => 'int',
337-
'table' => $table,
338-
'padding' => 10,
339-
'identity' => true,
340-
'nullable' => false,
341-
'resource' => 'default'
342-
]
343-
],
344-
[
345-
'int',
346-
[
347-
'name' => 'foreign_column',
348-
'type' => 'int',
349-
'table' => $table,
350-
'padding' => 10,
351-
'nullable' => false,
352-
'resource' => 'default'
353-
]
354-
],
355-
[
356-
'timestamp',
357-
[
358-
'name' => 'second_column',
359-
'type' => 'timestamp',
360-
'table' => $table,
361-
'default' => 'CURRENT_TIMESTAMP',
362-
'on_update' => true,
363-
'resource' => 'default'
364-
]
365-
],
366-
[
367-
'table',
368-
[
369-
'name' =>'second_table',
370-
'resource' => 'default',
371-
'engine' => 'innodb',
372-
'comment' => null,
373-
'onCreate' => ''
374-
]
375-
],
376-
[
377-
'int',
378-
[
379-
'name' => 'ref_column',
380-
'type' => 'int',
381-
'table' => $refTable,
382-
'padding' => 10,
383-
'nullable' => false,
384-
'resource' => 'default'
385-
]
386-
],
387-
[
388-
'index',
389-
[
390-
'name' => 'FIRST_INDEX',
391-
'table' => $refTable,
392-
'column' => ['ref_column'],
393-
'columns' => [$refColumn],
394-
'resource' => 'default'
395-
]
396-
],
397-
[
398-
'foreign',
399-
[
400-
'name' => 'some_foreign_key',
401-
'type' => 'foreign',
402-
'column' => $foreignColumn,
403-
'table' => $table,
404-
'referenceTable' => $refTable,
405-
'referenceColumn' => $refColumn,
406-
'resource' => 'default'
407-
]
408-
],
409-
[
410-
'primary',
411-
[
412-
'name' => 'PRIMARY',
413-
'type' => 'primary',
414-
'columns' => [$firstColumn],
415-
'table' => $table,
416-
'column' => ['first_column'],
417-
'resource' => 'default'
418-
]
419-
]
420-
)
421326
->willReturnOnConsecutiveCalls(
422327
$table,
423328
$firstColumn,

lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Diff/DiffManagerTest.php

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ protected function setUp()
5050
public function testShouldBeCreated()
5151
{
5252
$elements = ['first' => new \stdClass(), 'second' => new \stdClass()];
53-
$table = new Table('name', 'name', 'table', 'default', 'innodb');
53+
$table = new Table(
54+
'name',
55+
'name',
56+
'table',
57+
'default',
58+
'innodb',
59+
'utf-8',
60+
'utf_8_general_ci',
61+
''
62+
);
5463
$element = new Column('third', 'int', $table);
5564
$existingElement = new Column('second', 'int', $table);
5665
self::assertTrue($this->model->shouldBeCreated($elements, $element));
@@ -63,7 +72,16 @@ public function testRegisterModification()
6372
$diff = $this->getMockBuilder(Diff::class)
6473
->disableOriginalConstructor()
6574
->getMock();
66-
$table = new Table('name', 'name', 'table', 'default', 'innodb');
75+
$table = new Table(
76+
'name',
77+
'name',
78+
'table',
79+
'default',
80+
'innodb',
81+
'utf-8',
82+
'utf_8_general_ci',
83+
''
84+
);
6785
$element = new Column('third', 'int', $table);
6886
$generatedElement = new Column('third', 'int', $table, 'Previous column');
6987
$diff->expects(self::once())
@@ -78,7 +96,16 @@ public function testRegisterIndexModification()
7896
$diff = $this->getMockBuilder(Diff::class)
7997
->disableOriginalConstructor()
8098
->getMock();
81-
$table = new Table('name', 'name', 'table', 'default', 'innodb');
99+
$table = new Table(
100+
'name',
101+
'name',
102+
'table',
103+
'default',
104+
'innodb',
105+
'utf-8',
106+
'utf_8_general_ci',
107+
''
108+
);
82109
$column = new Column('third', 'int', $table, 'Previous column');
83110
$index = new Index('index_type', 'index', $table, [$column], 'btree');
84111
$generatedIndex = new Index('index_type', 'index', $table, [$column], 'hash');
@@ -94,13 +121,25 @@ public function testRegisterRemovalReference()
94121
$diff = $this->getMockBuilder(Diff::class)
95122
->disableOriginalConstructor()
96123
->getMock();
97-
$table = new Table('name', 'name', 'table', 'default', 'innodb');
124+
$table = new Table(
125+
'name',
126+
'name',
127+
'table',
128+
'default',
129+
'innodb',
130+
'utf-8',
131+
'utf_8_general_ci',
132+
''
133+
);
98134
$refTable = new Table(
99135
'ref_table',
100136
'ref_table',
101137
'table',
102138
'default',
103-
'innodb'
139+
'innodb',
140+
'utf-8',
141+
'utf-8',
142+
''
104143
);
105144
$column = new Column('third', 'int', $table, 'Previous column');
106145
$reference = new Reference('ref', 'foreign', $table, $column, $refTable, $column, 'CASCADE');
@@ -119,7 +158,16 @@ public function testRegisterCreation()
119158
$diff = $this->getMockBuilder(Diff::class)
120159
->disableOriginalConstructor()
121160
->getMock();
122-
$table = new Table('name', 'name', 'table', 'default', 'innodb');
161+
$table = new Table(
162+
'name',
163+
'name',
164+
'table',
165+
'default',
166+
'innodb',
167+
'utf-8',
168+
'utf_8_general_ci',
169+
''
170+
);
123171
$column = new Column('third', 'int', $table, 'Previous column');
124172
$reference = new Reference('ref', 'foreign', $table, $column, $table, $column, 'CASCADE');
125173
$diff->expects(self::exactly(3))
@@ -140,13 +188,25 @@ public function testRegisterTableModificationWhenChangeResource()
140188
$diff = $this->getMockBuilder(Diff::class)
141189
->disableOriginalConstructor()
142190
->getMock();
143-
$table = new Table('name', 'name', 'table', 'default', 'innodb');
191+
$table = new Table(
192+
'name',
193+
'name',
194+
'table',
195+
'default',
196+
'innodb',
197+
'utf-8',
198+
'utf_8_general_ci',
199+
''
200+
);
144201
$generateTable = new Table(
145202
'name',
146203
'name',
147204
'table',
148205
'sales',
149-
'innodb'
206+
'innodb',
207+
'utf-8',
208+
'utf_8_general_ci',
209+
''
150210
);
151211
$diff->expects(self::once())
152212
->method('register')
@@ -160,13 +220,25 @@ public function testRegisterTableModificationWhenChangeEngine()
160220
$diff = $this->getMockBuilder(Diff::class)
161221
->disableOriginalConstructor()
162222
->getMock();
163-
$table = new Table('name', 'name', 'table', 'default', 'innodb');
223+
$table = new Table(
224+
'name',
225+
'name',
226+
'table',
227+
'default',
228+
'innodb',
229+
'utf-8',
230+
'utf_8_general_ci',
231+
''
232+
);
164233
$generateTable = new Table(
165234
'name',
166235
'name',
167236
'table',
168237
'default',
169-
'memory'
238+
'memory',
239+
'utf-8',
240+
'utf_8_general_ci',
241+
''
170242
);
171243
$diff->expects(self::once())
172244
->method('register')

lib/internal/Magento/Framework/Setup/Test/Unit/Declaration/Schema/Dto/Factories/TableTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
99
use Magento\Framework\Setup\Declaration\Schema\Dto\Table;
1010

11+
/**
12+
* Test table factory
13+
*/
1114
class TableTest extends \PHPUnit\Framework\TestCase
1215
{
1316
/** @var \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Table */
@@ -53,7 +56,10 @@ public function testCreate()
5356
$expectedData = [
5457
'name' => 'pf_some_table',
5558
'engine' => 'innodb',
56-
'nameWithoutPrefix' => 'some_table'
59+
'nameWithoutPrefix' => 'some_table',
60+
'charset' => 'utf8',
61+
'collation' => 'utf8_general_ci',
62+
'onCreate' => ''
5763
];
5864
$this->objectManagerMock->expects(self::once())
5965
->method('create')
@@ -74,7 +80,10 @@ public function testCreateWithPrefix()
7480
$expectedData = [
7581
'name' => 'pf_some_table',
7682
'engine' => 'memory',
77-
'nameWithoutPrefix' => 'some_table'
83+
'nameWithoutPrefix' => 'some_table',
84+
'charset' => 'utf8',
85+
'collation' => 'utf8_general_ci',
86+
'onCreate' => ''
7887
];
7988
$this->objectManagerMock->expects(self::once())
8089
->method('create')

0 commit comments

Comments
 (0)