use Phalcon\Db;
use Phalcon\Di;
use Phalcon\Di\FactoryDefault;
use Phalcon\Loader;
ini_set("display_errors", 1);
error_reporting(E_ALL);
//define("ROOT_PATH",dirname(__DIR__));
define("APP_PATH",substr(__DIR__,0,strrpos(__DIR__,DIRECTORY_SEPARATOR)));
set_include_path(APP_PATH . PATH_SEPARATOR . get_include_path());
// Required for phalcon/incubator
include APP_PATH . "/app/library/incubator-master/vendor/autoload.php";
include APP_PATH . "/tests/UnitTestCase.php";
include APP_PATH . "/app/config/LoggerStub.php";
// Use the application autoloader to autoload the classes
// Autoload the dependencies found in composer
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader = new Phalcon\Loader();
$loader->registerDirs([
APP_PATH,
APP_PATH . "/app/helpers",
APP_PATH . "/app/model"
]);
$loader->register();
$di = new FactoryDefault();
Di::reset();
// Add any needed services to the DI here
Di::setDefault($di);
$configFile = APP_PATH . "/app/config/config.php";
if (is_readable($configFile)) {
$config = include $configFile;
$di->set("config", $config);
}
$di->set('db', function() use ($config) {
try {
$dbConfig = $config->database->toArray();
$adapter = $dbConfig['adapter'];
unset($dbConfig['adapter']);
$stub = $this->getMockBuilder('Phalcon\Db\Adapter\Pdo\\' . $adapter)
->disableOriginalConstructor()
->getMock();
$stub->expects($this->at(0))
->method('tableExists')
->will($this->returnCallback(function(){
return true;
}));
$stub->expects($this->at(1))
->method('getMetadata')
->will($this->returnCallback(function(){
// This was where I realized that I have to stub out
// all calls made internally by Phalcon\Mvc\Model
}));
return $stub;
}
catch (Exception $e) {
die("Test case not able run");
}
});
Я работаю над тестированием Phpunit для платформы phalcon.Мой вопрос в этом коде.Я использую код выше для соединения заглушки с базой данных pgsql для фиктивного объекта, который будет привязан к базе данных, но это не повредит базе данных.В настоящее время проблема заключается в том, что он не работает с заглушкой, которая используется выше, запускается из этой функции "getMockBuilder ()".