Trouble testing plugin with object manager

Issue: When attempting to test a plugin "after" method with $objectManager->create('Shopgate\Base\Model\Config')->startup(), the original startup() method is called but not my plugins afterStartup()

Steps Taken:

  • [✔] Confirm module enabled & loaded
  • [✔] Clear cache with magento cache:clean config
  • [✔] Empty generated code with rm -r generated/*
  • [✔] Register plugin as shown below:

In my etc/di.xml, I have the following:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Shopgate\Base\Model\Config">
        <plugin name="bugFixEnableGetSettings" type="MoninGlobal\ShopgateBugfix\Plugin\ShopgateConfig" sortOrder="9999" />
    </type>
</config>

In MoninGlobal\ShopgateBugfix\Plugin\ShopgateConfig I have:

    public function afterStartup($subject, $result){
        var_dump(get_class($subject));
        var_dump($result);

        return $result;
    }

The same occurs when using get() instead of create() on the object manager.

Any insight into what I am missing here would be greatly appreciated.

Solutions

Despite Magento showing that the module had been loaded and enabled, my registration.php was incorrect:

Bad

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'MoninGlobal_Template', # <--- BAD REFERENCE
    __DIR__
);

Good

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'MoninGlobal_ShopgateBugfix',
    __DIR__
);

Similar questions

Incorrect plugin instalation with Magento Connect Manager on v1.9.2.4
I am testing my plugin on Magento version 1.9.2.4. Installation on Magento Connect Manager seems to be ok but when I try to find it in configuration tab in Admin Panel - it's not there (it works on earlier versions for example 1.9), so I went to directories where it should be installed and I found something strange... Magento changed every php file...
Magento 2 instantiating classes through object manager factory
In magento 2 the classes are instantiated using an object manager factory: \Magento\Framework\ObjectManager\Factory\Factory::create(). So far so goo. But there is something that I don't understand here. After checking if there are no circular references in the arguments that should be passed to the constructor for DI and after the arguments are det...
why i should not use object manager directly in magento2?
Magento 2 uses dependency injection means when ever client required any services we have to pass in constructor. So magento take care like automatically create objects recursively.. but there is a statement like we should not use object manager. I'm very confusing on this part. Can you some one explain ?
Why Object manager can not instantiate Non-injectable?
Magento 2 uses Object manager to create all objects. Injectable Non-injectable these statements are very confusing.can you any one explain ?
Magento 2 - Object manager tries to instantiate Abstract class. ( Fatal error )
Playing around with Magento 2 but run into a problem I can not wrap my head around. The object manager tries to instantiate Abstract class, this gives an Fatal Error. Does someone know what might cause this or point me in the right direction? The Error The Problem My module has a model that extends the \Magento\Quote\Model\Quote. The constructor of...
How to obtain the Object Manager in Unit-Tests?
I've created the second unit-test for my second class. The second class will take a dependency of a first class instance and in one test I'd like to use the object manager to create the second class. How do I manage that my unit-test gets the object manager injected in Magento 2 so that I can use it?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.