public function request($method, $path, $options = array()) { $this->loadDatabaseDemo(); Database::getInstance($this->dsn); ob_start(); $env = Environment::mock(array_merge(['REQUEST_METHOD' => $method, 'REQUEST_URI' => $path], $options)); $app = (require 'src/bootstrap.php'); $app = (require 'src/routes.php'); $this->response = $app->run(); $output = ob_get_clean(); $this->databaseDestroy(); return $output; }
<?php use App\Todo\TaskBundle\TaskRepository; use App\Lib\Database; $container = isset($container) ? $container : new \Slim\Container(); $dsn = getenv('DB'); $container['db'] = function () use($dsn) { return Database::getInstance($dsn); }; $container['repository'] = function () use($container) { return new TaskRepository($container->get('db')); }; if (isset($env) && !empty($env)) { $container['environment'] = function () use($env) { return $env; }; } return new \Slim\App($container);
<?php require_once __DIR__ . '/../vendor/autoload.php'; use App\Lib\Database; Database::getInstance('sqlite:db/database.sq3'); Database::exec("DROP TABLE IF EXISTS tasks"); Database::exec("CREATE TABLE tasks (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, done INTEGER NOT NULL DEFAULT 0)"); Database::exec("\n INSERT INTO tasks (title, done)\n VALUES\n ('Fazer desafio da iTFLEX', 0),\n ('Tomar um café', 1)\n");