@unlink($db_config['database']); } require __DIR__ . '/../src/bootstrap/connection.php'; Hook\Http\Router::setInstance($app); // // Ensure that tests will run against an valid fresh app // if (Hook\Model\AppKey::count() == 0) { $app->environment->offsetSet('PATH_INFO', '/apps'); $app->environment->offsetSet('slim.request.form_hash', array('app' => array('name' => 'testing'))); $app_controller = new Hook\Controllers\ApplicationController(); $app_controller->create(); } // Force application key for testing Hook\Application\Context::setTablePrefix(''); Hook\Application\Context::setKey(Hook\Model\AppKey::with('app')->first()); $app->log->setWriter(new Hook\Logger\LogWriter(storage_dir() . '/logs.txt')); class TestCase extends PHPUnit_Framework_TestCase { } class HTTP_TestCase extends PHPUnit_Framework_TestCase { // protected $base_url = 'http://localhost/index.php/'; // protected $base_url = 'http://localhost/index.php/'; protected $base_url = 'http://hook.dev/public/index.php/'; protected $app_keys = array(); protected $app_key = array(); // protected $base_url = 'http://dl-api.dev/index.php/'; public function setUp() { $this->useApp('default');
// auto-set app_id/key if (!$app->request->headers->get('X-App-Id')) { // Create default application if it doesn't exists if (Hook\Model\AppKey::count() == 0) { $application = Hook\Model\App::create(array('name' => "Application")); $hook_config = $application->keys[0]->toArray(); $hook_config['endpoint'] = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']; file_put_contents($app->config('paths')['root'] . '.hook-config', json_encode($hook_config)); // Migrate application tables Hook\Application\Context::setKey($application->keys[0]); Hook\Application\Context::migrate(); Hook\Application\Context::setTablePrefix(''); } if ($app->request->isAjax()) { $app_key = Hook\Model\AppKey::where('type', Hook\Model\AppKey::TYPE_BROWSER)->first(); } else { $app_key = Hook\Model\AppKey::where('type', Hook\Model\AppKey::TYPE_SERVER)->first(); } $app->request->headers->set('X-App-Id', $app_key->app_id); $app->request->headers->set('X-App-Key', $app_key->key); } foreach ($app->config('aliases') as $alias => $source) { class_alias($source, $alias); } // configure view/template library (lightncandy) $app->config("templates.path", $app->config('paths')['root'] . "app/views"); $app->config("templates.helpers_path", ROOT_DIR . '/app/helpers'); $app->config("view", new Hook\Framework\View()); // bind application routes require ROOT_DIR . 'config/routes.php'; $app->run();