Skip to content

Commit 84e57ee

Browse files
committed
ACP2E-3871: Issue with upgrade 2.4.7-p5 due to added new validation
1 parent c8ba4ab commit 84e57ee

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
3+
* Copyright 2017 Adobe All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
declare(strict_types=1);
@@ -86,6 +86,7 @@ public function build(Schema $schema)
8686
$tablesWithJsonTypeField = [];
8787
if (isset($data['table'])) {
8888
foreach ($data['table'] as $keyTable => $tableColumns) {
89+
$tableColumns['column'] ??= [];
8990
foreach ($tableColumns['column'] as $keyColumn => $columnData) {
9091
if ($columnData['type'] == 'json') {
9192
$tablesWithJsonTypeField[$keyTable] = $keyColumn;

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

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
3+
* Copyright 2018 Adobe All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
declare(strict_types=1);
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Framework\DB\Adapter\SqlVersionProvider;
12+
use Magento\Framework\Setup\Declaration\Schema\Declaration\ReaderComposite;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1314
use Magento\Framework\Setup\Declaration\Schema\Db\DbSchemaReaderInterface;
1415
use Magento\Framework\Setup\Declaration\Schema\Db\SchemaBuilder;
@@ -330,6 +331,87 @@ public function testBuildUnknownIndexColumn(array $columns, array $references, a
330331
$this->model->build($schema);
331332
}
332333

334+
/**
335+
* This test verifies that the system does not crash or throw unexpected errors when attempting to build
336+
* a schema with missing column definitions.
337+
*
338+
* @return void
339+
* @throws \PHPUnit\Framework\MockObject\Exception
340+
*/
341+
public function testBuildHandlesMissingColumnsGracefully()
342+
{
343+
$data = [
344+
'table' => [
345+
'test_table' => [
346+
'name' => 'test_table_fail',
347+
'resource' => 'default',
348+
'engine' => 'innodb',
349+
'comment' => 'test table',
350+
'disabled' => 'true',
351+
]
352+
]
353+
];
354+
355+
$this->shardingMock->expects(self::once())
356+
->method('getResources')
357+
->willReturn(['default']);
358+
359+
$this->dbSchemaReaderMock->expects(self::once())
360+
->method('readTables')
361+
->with('default')
362+
->willReturn(['test_table']);
363+
364+
$this->dbSchemaReaderMock->expects(self::once())
365+
->method('readColumns')
366+
->with('test_table')
367+
->willReturn([]);
368+
369+
$this->dbSchemaReaderMock->expects(self::once())
370+
->method('readIndexes')
371+
->with('test_table')
372+
->willReturn([]);
373+
374+
$this->dbSchemaReaderMock->expects(self::once())
375+
->method('readReferences')
376+
->willReturn([]);
377+
378+
$this->dbSchemaReaderMock->expects(self::once())
379+
->method('readConstraints')
380+
->with('test_table')
381+
->willReturn([]);
382+
383+
$this->dbSchemaReaderMock->expects(self::once())
384+
->method('getTableOptions')
385+
->with('test_table')
386+
->willReturn([
387+
'engine' => 'innodb',
388+
'comment' => '',
389+
'charset' => 'utf-8',
390+
'collation' => 'utf-8'
391+
]);
392+
393+
$this->elementFactoryMock->expects($this->any())
394+
->method('create')
395+
->willReturn($this->createMock(Table::class));
396+
397+
$readerCompositeMock = $this->getMockBuilder(ReaderComposite::class)
398+
->disableOriginalConstructor()
399+
->getMock();
400+
$readerCompositeMock->expects($this->once())
401+
->method('read')
402+
->willReturn($data);
403+
404+
$schemaBuilder = new SchemaBuilder(
405+
$this->elementFactoryMock,
406+
$this->dbSchemaReaderMock,
407+
$this->shardingMock,
408+
$readerCompositeMock
409+
);
410+
411+
$schemaBuilder->build($this->createMock(Schema::class));
412+
$this->assertTrue(true, 'System did not crash when columns were missing.');
413+
}
414+
333415
/**
334416
* Prepare mocks for test.
335417
*
@@ -338,6 +420,8 @@ public function testBuildUnknownIndexColumn(array $columns, array $references, a
338420
* @param array $constraints
339421
* @param array $indexes
340422
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
423+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
424+
* @SuppressWarnings(PHPMD.NPathComplexity)
341425
*/
342426
private function prepareSchemaMocks(array $columns, array $references, array $constraints, array $indexes)
343427
{

0 commit comments

Comments
 (0)