Skip to content

Commit

Permalink
Merge pull request #108 from AmpersandHQ/plugin-removed-issue-99
Browse files Browse the repository at this point in the history
Report plugins on non-existent classes (fix issue #99)
  • Loading branch information
convenient authored Aug 4, 2023
2 parents bc32b4f + 9d870c0 commit 47eb4b6
Show file tree
Hide file tree
Showing 11 changed files with 368 additions and 6 deletions.
8 changes: 7 additions & 1 deletion dev/phpunit/functional/expected_output/magentom23.out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::afterCanSendCommentEmail |
| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::aroundCanSendCommentEmail |
| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::beforeCanSendCommentEmail |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::beforeGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::afterGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::aroundGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::beforeGetUpdatedAt |
| WARN | Preference | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Api/ExampleInterface.php | Ampersand\Test\Model\Example |
| WARN | Preference | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/SomeClass.php | Ampersand\Test\Model\ThirdPartyClass |
| WARN | Preference | vendor/magento/framework/Locale/Format.php | Ampersand\Test\Model\Locale\Format |
Expand All @@ -58,6 +64,6 @@
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndDelete.php | Ampersand\Test\Model\ToPreferenceAndDelete |
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndExtendAndDelete.php | Ampersand\Test\Model\ToPreferenceAndExtendAndDelete |
+-------+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
WARN count: 56
WARN count: 62
INFO count: 309 (to view re-run this tool with --show-info)
For docs on each check see https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/master/docs/CHECKS_AVAILABLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::afterCanSendCommentEmail |
| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::aroundCanSendCommentEmail |
| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::beforeCanSendCommentEmail |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::beforeGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::afterGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::aroundGetUpdatedAt |
| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::beforeGetUpdatedAt |
| WARN | Preference | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Api/ExampleInterface.php | Ampersand\Test\Model\Example |
| WARN | Preference | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/SomeClass.php | Ampersand\Test\Model\ThirdPartyClass |
| WARN | Preference | vendor/magento/framework/Locale/Format.php | Ampersand\Test\Model\Locale\Format |
Expand All @@ -59,6 +65,6 @@
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndDelete.php | Ampersand\Test\Model\ToPreferenceAndDelete |
| WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndExtendAndDelete.php | Ampersand\Test\Model\ToPreferenceAndExtendAndDelete |
+-------+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+
WARN count: 57
WARN count: 63
INFO count: 314 (to view re-run this tool with --show-info)
For docs on each check see https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/master/docs/CHECKS_AVAILABLE.md
138 changes: 138 additions & 0 deletions dev/phpunit/unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,142 @@ public function testClassPlugins()
];
$this->assertEquals($expectedWarnings, $warnings);
}

/**
*
*/
public function testClassPluginsOnDeletedClass()
{
$this->m2->expects($this->any())
->method('getAreaConfig')
->willReturn(
[
'frontend' => [
'somePluginClassOnDeleteTarget' => [
'type' => 'Some_Plugin_Class_On_Delete_Target'
],
'Magento\AdobeIms\Model\FunBusinessLogic' => [
'plugins' => [
[
'disabled' => false,
'instance' => 'somePluginClassOnDeleteTarget'
]
]
]
],
'adminhtml' => [
'Magento\AdobeIms\Model\FunBusinessLogic' => [
'plugins' => [
[
'disabled' => false,
'instance' => 'Some_Plugin_Class_On_Delete_Target'
]
]
]
],
]
);

$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 part of the patchfile

$appCodeGetter = new GetAppCodePathFromVendorPath($this->m2, $entry);
$appCodeFilePath = $appCodeGetter->getAppCodePathFromVendorPath();
$this->assertEquals(
'app/code/Magento/AdobeIms/Model/FunBusinessLogic.php',
$appCodeFilePath
);

$warnings = $infos = [];

$check = new ClassPluginPhp($this->m2, $entry, $appCodeFilePath, $warnings, $infos, []);
$this->assertTrue($check->canCheck(), 'Check should be checkable');
$check->check();

$this->assertEmpty($infos, 'We should have no info level items');
$this->assertNotEmpty($warnings, 'We should have a warning');
$expectedWarnings = [
'Plugin Disabled' => [
'Some_Plugin_Class_On_Delete_Target::beforeGetUpdatedAt',
'Some_Plugin_Class_On_Delete_Target::afterGetUpdatedAt',
'Some_Plugin_Class_On_Delete_Target::aroundGetUpdatedAt',
]
];
$this->assertEquals($expectedWarnings, $warnings);
}

/**
*
*/
public function testClassPluginsOnCreatedClass()
{
$this->m2->expects($this->any())
->method('getAreaConfig')
->willReturn(
[
'frontend' => [
'somePluginClassOnDeleteTarget' => [
'type' => 'Some_Plugin_Class_On_Created_Target'
],
'Magento\AdobeIms\Model\NewBusinessLogic' => [
'plugins' => [
[
'disabled' => false,
'instance' => 'somePluginClassOnDeleteTarget'
]
]
]
],
'adminhtml' => [
'Magento\AdobeIms\Model\NewBusinessLogic' => [
'plugins' => [
[
'disabled' => false,
'instance' => 'Some_Plugin_Class_On_Created_Target'
]
]
]
],
]
);

$reader = new Reader(
$this->testResourcesDir . 'vendor.patch'
);

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

$entry = $entries[2]; // Third part of the patchfile

$appCodeGetter = new GetAppCodePathFromVendorPath($this->m2, $entry);
$appCodeFilePath = $appCodeGetter->getAppCodePathFromVendorPath();
$this->assertEquals(
'app/code/Magento/AdobeIms/Model/NewBusinessLogic.php',
$appCodeFilePath
);

$warnings = $infos = [];

$check = new ClassPluginPhp($this->m2, $entry, $appCodeFilePath, $warnings, $infos, []);
$this->assertTrue($check->canCheck(), 'Check should be checkable');
$check->check();

$this->assertEmpty($infos, 'We should have no info level items');
$this->assertNotEmpty($warnings, 'We should have a warning');
$expectedWarnings = [
'Plugin Enabled' => [
'Some_Plugin_Class_On_Created_Target::beforeGetUpdatedAt',
'Some_Plugin_Class_On_Created_Target::afterGetUpdatedAt',
'Some_Plugin_Class_On_Created_Target::aroundGetUpdatedAt',
]
];
$this->assertEquals($expectedWarnings, $warnings);
}
}
59 changes: 59 additions & 0 deletions dev/phpunit/unit/resources/checks/ClassPluginPhp/Plugins.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
if (!class_exists('Magento\AdobeIms\Model\NewBusinessLogic')) {
require_once __DIR__ . '/vendor/magento/module-adobe-ims/Model/NewBusinessLogic.php';
}

if (!class_exists('Some_Plugin_Class', false)) {
class Some_Plugin_Class
{
Expand All @@ -19,6 +23,61 @@ public function aroundGetUpdatedAt($subject, callable $proceed)
}
}

if (!class_exists('Some_Plugin_Class_On_Delete_Target', false)) {
class Some_Plugin_Class_On_Delete_Target
{
public function beforeGetUpdatedAt($subject)
{
// do stuff
}

public function afterGetUpdatedAt($subject, $result)
{
return $result;
}

public function aroundGetUpdatedAt($subject, callable $proceed)
{
return $proceed();
}

public function notRelevant()
{
return false;
}
}
}

if (!class_exists('Some_Plugin_Class_On_Created_Target', false)) {
class Some_Plugin_Class_On_Created_Target
{
public function beforeGetUpdatedAt($subject)
{
// do stuff
}

public function beforeNothing($subject)
{
// do stuff
}

public function afterGetUpdatedAt($subject, $result)
{
return $result;
}

public function aroundGetUpdatedAt($subject, callable $proceed)
{
return $proceed();
}

public function notRelevant()
{
return false;
}
}
}

if (!class_exists('Some_Admin_Plugin_Class', false)) {
class Some_Admin_Plugin_Class
{
Expand Down
42 changes: 40 additions & 2 deletions dev/phpunit/unit/resources/checks/ClassPluginPhp/vendor.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
diff -ur -N vendor_orig/magento/module-adobe-ims/Model/UserProfile.php vendor/magento/module-adobe-ims/Model/UserProfile.php
--- vendor_orig/magento/module-adobe-ims/Model/UserProfile.php 2022-11-14 16:08:33.000000000 +0000
+++ vendor/magento/module-adobe-ims/Model/UserProfile.php 2022-11-14 16:18:49.000000000 +0000
--- vendor_orig/magento/module-adobe-ims/Model/UserProfile.php 2023-01-30 09:49:48
+++ vendor/magento/module-adobe-ims/Model/UserProfile.php 2023-01-30 09:49:48
@@ -10,6 +10,7 @@
*/
public function getUpdatedAt(): string
Expand All @@ -11,3 +11,41 @@ diff -ur -N vendor_orig/magento/module-adobe-ims/Model/UserProfile.php vendor/ma
-}
\ No newline at end of file
+}
diff -ur -N vendor_orig/magento/module-adobe-ims/Model/FunBusinessLogic.php vendor/magento/module-adobe-ims/Model/FunBusinessLogic.php
--- vendor_orig/magento/module-adobe-ims/Model/FunBusinessLogic.php 2023-08-04 11:54:25
+++ vendor/magento/module-adobe-ims/Model/FunBusinessLogic.php 1970-01-01 01:00:00
@@ -1,15 +0,0 @@
-<?php
-namespace Magento\AdobeIms\Model;
-
-class FunBusinessLogic
-{
- private const UPDATED_AT = 'updated_at';
-
- /**
- * @inheritdoc
- */
- public function getUpdatedAt(): string
- {
- return $this->getData(self::UPDATED_AT);
- }
-}
diff -ur -N vendor_orig/magento/module-adobe-ims/Model/NewBusinessLogic.php vendor/magento/module-adobe-ims/Model/NewBusinessLogic.php
--- vendor_orig/magento/module-adobe-ims/Model/NewBusinessLogic.php 1970-01-01 01:00:00
+++ vendor/magento/module-adobe-ims/Model/NewBusinessLogic.php 2023-08-04 12:06:14
@@ -0,0 +1,15 @@
+<?php
+namespace Magento\AdobeIms\Model;
+
+class NewBusinessLogic
+{
+ private const UPDATED_AT = 'updated_at';
+
+ /**
+ * @inheritdoc
+ */
+ public function getUpdatedAt(): string
+ {
+ return $this->getData(self::UPDATED_AT);
+ }
+}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Magento\AdobeIms\Model;

class NewBusinessLogic
{
private const UPDATED_AT = 'updated_at';

/**
* @inheritdoc
*/
public function getUpdatedAt(): string
{
return $this->getData(self::UPDATED_AT);
}

public function someOtherFunction()
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace Magento\AdobeIms\Model;

class FunBusinessLogic
{
private const UPDATED_AT = 'updated_at';

/**
* @inheritdoc
*/
public function getUpdatedAt(): string
{
return $this->getData(self::UPDATED_AT);
}
}
Loading

0 comments on commit 47eb4b6

Please sign in to comment.