N98\Magento\Command\TestCase::getApplication PHP Method

getApplication() public method

public getApplication ( ) : Application | PHPUnit_Framework_MockObject_MockObjec\PHPUnit_Framework_MockObject_MockObject
return N98\Magento\Application | PHPUnit_Framework_MockObject_MockObjec\PHPUnit_Framework_MockObject_MockObject
    public function getApplication()
    {
        if ($this->application === null) {
            $root = $this->getTestMagentoRoot();
            /** @var Application|PHPUnit_Framework_MockObject_MockObject $application */
            $application = $this->getMock('N98\\Magento\\Application', array('getMagentoRootFolder'));
            // Get the composer bootstrap
            if (defined('PHPUNIT_COMPOSER_INSTALL')) {
                $loader = (require PHPUNIT_COMPOSER_INSTALL);
            } elseif (file_exists(__DIR__ . '/../../../../../../autoload.php')) {
                // Installed via composer, already in vendor
                $loader = (require __DIR__ . '/../../../../../../autoload.php');
            } else {
                // Check if testing root package without PHPUnit
                $loader = (require __DIR__ . '/../../../../vendor/autoload.php');
            }
            $application->setAutoloader($loader);
            $application->expects($this->any())->method('getMagentoRootFolder')->will($this->returnValue($root));
            spl_autoload_unregister(array(\Varien_Autoload::instance(), 'autoload'));
            $application->init();
            $application->initMagento();
            if ($application->getMagentoMajorVersion() == Application::MAGENTO_MAJOR_VERSION_1) {
                spl_autoload_unregister(array(\Varien_Autoload::instance(), 'autoload'));
            }
            $this->application = $application;
        }
        return $this->application;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @throws \RuntimeException
  * @return \PHPUnit_Framework_MockObject_MockObject|\N98\Magento\Application
  */
 public function getApplication()
 {
     $application = parent::getApplication();
     if ($application::MAGENTO_MAJOR_VERSION_1 !== $application->getMagentoMajorVersion()) {
         return $application;
     }
     // FIXME #613 make install command work with 1.9+ and cache initialization
     $version = \Mage::getVersion();
     $against = '1.9.0.0';
     if ($application->isMagentoEnterprise()) {
         $against = '1.14.0.0';
     }
     if (-1 != version_compare($version, $against)) {
         $this->markTestSkipped(sprintf('Test skipped because it fails after new install of a Magento 1.9+ version (Magento version is: ' . '%s) which is the case on travis where we always have a new install.', $version));
     }
     return $application;
 }