Last active
October 18, 2016 17:16
-
-
Save Vinai/64abcb4290a33807269e to your computer and use it in GitHub Desktop.
Simple Magento 1 bootstrap for PHPUnit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL); | |
require __DIR__ . '/../../../../../../Mage.php'; | |
require __DIR__ . '/util/Magento_IntegrationTest_Config.php'; | |
Mage::setIsDeveloperMode(true); | |
Mage::app('', 'store', ['config_model' => Magento_IntegrationTest_Config::class]); | |
$magentoHandler = set_error_handler(function () { | |
$usePhpErrorHandlingReturnValue = false; | |
return $usePhpErrorHandlingReturnValue; | |
}); | |
set_error_handler(function ($errno, $errstr, $errfile) use ($magentoHandler) { | |
if (substr($errfile, -19) === 'Varien/Autoload.php') { | |
$ignoreErrorReturnValue = null; | |
return $ignoreErrorReturnValue; | |
} | |
return is_callable($magentoHandler) ? | |
call_user_func_array($magentoHandler, func_get_args()) : | |
false; | |
}); | |
$_SESSION = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Magento_IntegrationTest_Config extends Mage_Core_Model_Config | |
{ | |
private $modelTestDoubles = []; | |
private $resourceModelTestDoubles = []; | |
public function setModelTestDouble($modelClass, $testDouble) | |
{ | |
$this->modelTestDoubles[$modelClass] = $testDouble; | |
} | |
public function getModelInstance($modelClass = '', $constructArguments = []) | |
{ | |
if (isset($this->modelTestDoubles[(string) $modelClass])) { | |
return $this->modelTestDoubles[(string) $modelClass]; | |
} | |
return parent::getModelInstance($modelClass, $constructArguments); | |
} | |
public function setResourceModelTestDouble($modelClass, $testDouble) | |
{ | |
$this->resourceModelTestDoubles[$modelClass] = $testDouble; | |
} | |
public function getResourceModelInstance($modelClass = '', $constructArguments = []) | |
{ | |
if (isset($this->resourceModelTestDoubles[(string) $modelClass])) { | |
return $this->resourceModelTestDoubles[(string) $modelClass]; | |
} | |
return parent::getResourceModelInstance($modelClass, $constructArguments); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment