Skip to content

Instantly share code, notes, and snippets.

@Vinai
Last active October 18, 2016 17:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vinai/64abcb4290a33807269e to your computer and use it in GitHub Desktop.
Save Vinai/64abcb4290a33807269e to your computer and use it in GitHub Desktop.
Simple Magento 1 bootstrap for PHPUnit.
<?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 = [];
<?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