public function createApplication() { $app = new ApplicationTest(); $app['route_class'] = 'Euskadi31\\Silex\\Controller\\RouteTest'; $app['debug'] = true; //unset($app['exception_handler']); $app->mount('/', new AuthorizeControllerProvider()); $app->error(function (Exception $exception, $code) use($app) { $e = FlattenException::create($exception); $headers = []; if ($exception instanceof HttpExceptionInterface) { $headers = $exception->getHeaders(); $code = $exception->getStatusCode(); } else { $code = $exception->getCode(); } if ($code < 100 || $code >= 600) { $code = 500; } $error = ['error' => ['message' => $exception->getMessage(), 'type' => join('', array_slice(explode('\\', get_class($exception)), -1)), 'code' => $code]]; if ($this->app['debug']) { $error['error']['exception'] = $e->toArray(); } return new Response($app->json($error, $code, $headers)); }); return $app; }
public function getConnection() { if ($this->conn === null) { $dsn = 'mysql:dbname=' . $_SERVER['PM_UNIT_DB_NAME'] . ';host=' . $_SERVER['PM_UNIT_DB_HOST']; if (self::$pdo == null) { self::$pdo = new PDO($dsn, $_SERVER['PM_UNIT_DB_USER'], $_SERVER['PM_UNIT_DB_PASS']); } $this->conn = $this->createDefaultDBConnection(self::$pdo, $_SERVER['PM_UNIT_DB_NAME']); } return $this->conn; }
protected function getApplication() { $app = new ApplicationTest(); $app->register(new RestServiceProvider()); $users = [['id' => 1234, 'first_name' => 'Axel', 'last_name' => 'Etcheverry', 'email' => '*****@*****.**'], ['id' => 1235, 'first_name' => 'Rui', 'last_name' => 'Avelino', 'email' => '*****@*****.**'], new ArrayObject(['id' => 1236, 'first_name' => 'William', 'last_name' => 'Rudent', 'email' => '*****@*****.**'])]; $app->get('/me', function () use($app, $users) { return $app->json($users[0]); }); $app->get('/users', function () use($app, $users) { return $app->json($users); }); return $app; }
<?php $GLOBALS['dirpre'] = isset($GLOBALS['dirpre']) ? $GLOBALS['dirpre'] : '../'; require_once $GLOBALS['dirpre'] . 'includes/header.php'; Model::$test = true; require_once $GLOBALS['dirpre'] . 'tests/models/StudentModelTest.php'; StudentModelTest::run(); require_once $GLOBALS['dirpre'] . 'tests/controllers/modules/application/QuestionTest.php'; QuestionTest::run(); require_once $GLOBALS['dirpre'] . 'tests/controllers/modules/application/StudentProfileTest.php'; StudentProfileTest::run(); require_once $GLOBALS['dirpre'] . 'tests/controllers/modules/application/ApplicationTest.php'; ApplicationTest::run();
public static function end() { self::$MApplicationTest = null; }