Skip to content

Commit

Permalink
Merge pull request #105 from AmpersandHQ/dbschema-reduce-severity-of-…
Browse files Browse the repository at this point in the history
…no-changes-handling

Improve edge case handling of db_schema.xml
  • Loading branch information
convenient authored Jul 13, 2023
2 parents 63698a0 + a5323dd commit 4e944da
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
33 changes: 33 additions & 0 deletions dev/phpunit/unit/Ampersand/PatchHelper/Checks/DbSchemaXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function setUp(): void
->willReturn(
[
'vendor/ampersand/upgrade-patch-helper-test-module/' => 'Ampersand_UpgradePatchHelperTestModule',
'vendor/ampersand/upgrade-patch-helper-test-module-2/' => 'Ampersand_UpgradePatchHelperTestModule2',
]
);
}
Expand Down Expand Up @@ -119,4 +120,36 @@ public function testDbSchemaXml()
];
$this->assertEquals($expectedWarns, $warnings);
}

/**
*
*/
public function testDbSchemaXmlNoChanges()
{
$reader = new Reader(
$this->testResourcesDir . 'vendor.patch'
);

$entries = $reader->getFiles();
$this->assertNotEmpty($entries, 'We should have a patch file to read');

$entry = $entries[1]; // second patch file

$appCodeGetter = new GetAppCodePathFromVendorPath($this->m2, $entry);
$appCodeFilePath = $appCodeGetter->getAppCodePathFromVendorPath();
$this->assertEquals(
'app/code/Ampersand/UpgradePatchHelperTestModule2/src/module/etc/db_schema.xml',
$appCodeFilePath
);

$warnings = $infos = [];

$check = new DbSchemaXml($this->m2, $entry, $appCodeFilePath, $warnings, $infos);
chdir($this->testResourcesDir);
$this->assertTrue($check->canCheck(), 'Check should be checkable');
$check->check();

$this->assertEmpty($infos, 'We should not have infos');
$this->assertEmpty($warnings, 'We should not have warnings');
}
}
21 changes: 19 additions & 2 deletions dev/phpunit/unit/resources/checks/DbSchemaXml/vendor.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff -ur -N vendor_orig/ampersand/upgrade-patch-helper-test-module/src/module/etc/db_schema.xml vendor/ampersand/upgrade-patch-helper-test-module/src/module/etc/db_schema.xml
--- vendor_orig/ampersand/upgrade-patch-helper-test-module/src/module/etc/db_schema.xml 2022-11-15 16:39:40.000000000 +0000
+++ vendor/ampersand/upgrade-patch-helper-test-module/src/module/etc/db_schema.xml 2022-11-15 16:39:40.000000000 +0000
--- vendor_orig/ampersand/upgrade-patch-helper-test-module/src/module/etc/db_schema.xml 2023-01-30 09:49:48
+++ vendor/ampersand/upgrade-patch-helper-test-module/src/module/etc/db_schema.xml 2023-01-30 09:49:48
@@ -2,22 +2,22 @@
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
Expand Down Expand Up @@ -29,3 +29,20 @@ diff -ur -N vendor_orig/ampersand/upgrade-patch-helper-test-module/src/module/et
<column xsi:type="int" name="some_id" identity="true" nullable="false" comment="some_id"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="some_id"/>
diff -ur -N vendor_orig/ampersand/upgrade-patch-helper-test-module-2/src/module/etc/db_schema.xml vendor/ampersand/upgrade-patch-helper-test-module-2/src/module/etc/db_schema.xml
--- vendor_orig/ampersand/upgrade-patch-helper-test-module-2/src/module/etc/db_schema.xml 2023-07-11 18:07:48
+++ vendor/ampersand/upgrade-patch-helper-test-module-2/src/module/etc/db_schema.xml 2023-07-11 18:08:28
@@ -1,9 +1,11 @@
<?xml version="1.0"?>
+<!-- Added a comment -->
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
-
+ <!-- Added a comment -->
<table name="some_test_table_123" resource="default">
<column xsi:type="int" name="some_new_column" nullable="true" comment="some_new_column"/>
</table>
-
+ <!-- Added a comment -->
</schema>
+<!-- Added a comment -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!-- Added a comment -->
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<!-- Added a comment -->
<table name="some_test_table_123" resource="default">
<column xsi:type="int" name="some_new_column" nullable="true" comment="some_new_column"/>
</table>
<!-- Added a comment -->
</schema>
<!-- Added a comment -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">

<table name="some_test_table_123" resource="default">
<column xsi:type="int" name="some_new_column" nullable="true" comment="some_new_column"/>
</table>

</schema>
2 changes: 1 addition & 1 deletion src/Ampersand/PatchHelper/Checks/DbSchemaXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function check()
empty($this->infos[Checks::TYPE_DB_SCHEMA_ADDED]) &&
empty($this->infos[Checks::TYPE_DB_SCHEMA_REMOVED])
) {
throw new \InvalidArgumentException("$vendorFile could not work out db schema changes for this diff");
return; // No semantic changes in this diff, most likely formatting or comments
}

/*
Expand Down

0 comments on commit 4e944da

Please sign in to comment.