8000 GitHub - mattwellss/Mage_Wrapper: Non-static wrapper for Magento's Mage class
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

mattwellss/Mage_Wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mage Wrapper

Non-static wrapper for Magento's Mage class

Introduction

Testing is fun, but not when static classes are everywhere in your code! Use Mage Wrapper as a replacement for Mage static calls.

Example

class Foo_Bar_Model_Baz extends Mage_Core_Model_Abstract
{
    // ...
    
    
    public function getSomeProduct($id)
    {
        return $this->mage->getModel('catalog/product')->load($id);
    }
    
    // ...
}

Notes

You must ensure that $this->mage resolves to an instance of Mage_Wrapper yourself. The simplest solution is to implement _construct and set it there:

class Foo_Bar_Model_Baz extends Mage_Core_Model_Abstract
{
    // ...
    
    
    protected function _construct()
    {
        $this->mage = new Mage_Wrapper();
        parent::_construct();
    }
    
    // ...
}

However, such techniques mean that your Mage_Wrapper dependency cannot be mocked, so the author recommends a setter:

class Foo_Bar_Model_Baz extends Mage_Core_Model_Abstract
{
    protected $mage;
    
    // ...
    
    protected function _construct()
    {
        $this->setMage(new Mage_Wrapper());
        parent::_construct();
    }
    
    public function setMage(Mage_Wrapper $mage)
    {
        $this->mage = $mage;
    }
    
    // ...
}

Final notes

Have fun!

About

Non-static wrapper for Magento's Mage class

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0