Skip to content

Commit

Permalink
fix: testing, application setup
Browse files Browse the repository at this point in the history
removed parallel testing
added env definition console command
updated framework architecture
  • Loading branch information
eliseekn committed Oct 11, 2021
1 parent da82b94 commit d9debb3
Show file tree
Hide file tree
Showing 33 changed files with 318 additions and 295 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
APP_ENV=development
APP_ENV=local
APP_NAME=TinyMVC
APP_URL=http://127.0.0.1:8080/
APP_LANG=en

DB_DRIVER=mysql
DB_NAME=tinymvc
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=tinymvc
DB_USERNAME=
DB_PASSWORD=

Expand All @@ -16,4 +16,4 @@ MAILER_PORT=1025
MAILER_USERNAME=
MAILER_PASSWORD=

ENCRYPTION_KEY=6a6e690053b3f816a6c6b22634e44624beaf28ce2fb25ec9631b1b1fce25
ENCRYPTION_KEY=
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
SHELL := /bin/bash

.PHONY: tests
.PHONY: tests, docker

tests:
php console db:delete
php console db:create
php console migrations:run
php console tests:run
php console tests:run

docker:
docker-compose up --build
3 changes: 2 additions & 1 deletion app/Database/Seeds/Seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace App\Database\Seeds;

use App\Database\Factories\UserFactory;
use App\Database\Models\User;

/**
Expand All @@ -17,6 +18,6 @@ class Seeder
{
public static function run()
{
User::factory(5)->create();
User::factory(UserFactory::class, 5)->create();
}
}
8 changes: 6 additions & 2 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ class AuthController
{
public function login(Request $request, Response $response)
{
if (!Auth::check($request)) $response->view('auth.login');
if (!Auth::check($request)) {
$response->view('auth.login');
}

$uri = !Session::has('intended') ? Auth::HOME : Session::pull('intended');
$response->redirect()->to($uri)->go();
}

public function signup(Request $request, Response $response)
{
if (!Auth::check($request)) $response->view('auth.signup');
if (!Auth::check($request)) {
$response->view('auth.signup');
}

$uri = !Session::has('intended') ? Auth::HOME : Session::pull('intended');
$response->redirect()->to($uri)->go();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Validators/AuthRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace App\Http\Validators;

use Core\Http\Validator\GUMPValidator as Validator;
use Core\Http\Validator\GUMPValidator;

class AuthRequest extends Validator
class AuthRequest extends GUMPValidator
{
/**
* Validation rules
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Validators/RegisterUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

namespace App\Http\Validators;

use Core\Http\Validator\GUMPValidator as Validator;
use Core\Http\Validator\GUMPValidator;
use Core\Database\Repository;

class RegisterUser extends Validator
class RegisterUser extends GUMPValidator
{
/**
* Validation rules
Expand Down
21 changes: 6 additions & 15 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,52 @@
* @link https://github.com/eliseekn/tinymvc
*/

use Core\Http\Request;
use Core\Routing\Route;
use Core\Support\Config;
use Core\Support\Whoops;
use Core\Support\Storage;

/**
* Define application environnement
* Setup application
*/

//application root path
define('DS', DIRECTORY_SEPARATOR);
define('APP_ROOT', __DIR__ . DS);

//register whoops error handler
Whoops::register();

//setup storages
$storage = Storage::path(absolute_path('storage'));

if (!$storage->isDir()) $storage->createDir();
if (!$storage->path(config('storage.logs'))->isDir()) $storage->createDir();
if (!$storage->path(config('storage.cache'))->isDir()) $storage->createDir();
if (!$storage->path(config('storage.sqlite'))->isDir()) $storage->createDir();

//errors display
if (config('errors.display') === true) {
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
} else {
ini_set('display_errors', 0);
}

//errors logging
if (config('errors.log') === true) {
ini_set('log_errors', 1);
ini_set('error_log', Storage::path(config('storage.logs'))->file('tinymvc_' . date('m_d_y') . '.log'));
} else {
ini_set('log_errors', 0);
}

//handle exceptions
function handleExceptions($e)
{
throw new ErrorException($e->getMessage(), $e->getCode(), 1, $e->getFile(), $e->getLine(), $e->getPrevious());
}

//set exceptions and errors handlers
set_exception_handler('handleExceptions');

//remove PHP maximum execution time
set_time_limit(0);

//load .env file
if (!Storage::path()->isFile('.env') && !empty((new Request())->uri())) {
throw new Exception('Run "php console app:setup" console command to setup application or copy ".env.example" file to ".env"');
}
Route::load();

if (Storage::path()->isFile('.env')) Config::loadEnv();

Config::loadEnv();
throw new Exception('Copy ".env.example" file to ".env" then edit or run "php console app:setup" console command to setup application');
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"phpunit/phpunit": "^9.5",
"symfony/var-dumper": "^5.2",
"filp/whoops": "^2.12",
"fakerphp/faker": "^1.15",
"brianium/paratest": "^6.3"
"fakerphp/faker": "^1.15"
}
}
100 changes: 3 additions & 97 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

return [
'env' => env('APP_ENV', 'test'),
'env' => env('APP_ENV', 'local'),
'name' => env('APP_NAME', 'TinyMVC'),
'url' => env('APP_URL', 'http://127.0.0.1:8080/'),
'lang' => env('APP_LANG', 'en'),
Expand Down
1 change: 1 addition & 0 deletions console
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $console->add(new \Core\Console\Make\Test());

$console->add(new \Core\Console\App\Setup());
$console->add(new \Core\Console\App\EncryptionKey());
$console->add(new \Core\Console\App\Environnement());

$console->add(new \Core\Console\Cache());
$console->add(new \Core\Console\Server());
Expand Down
23 changes: 5 additions & 18 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Core\Http\Request;
use Core\Routing\Router;
use Core\Support\Whoops;
use Core\Support\Storage;
use Core\Support\Exception;
use Core\Http\Response\Response;

Expand All @@ -20,34 +19,22 @@
*/
class Application
{
private $response;
private $request;

public function __construct()
{
$this->request = new Request();
$this->response = new Response();

Whoops::register();

$routes = Storage::path(config('storage.routes'))->getFiles();

foreach ($routes as $route) {
require_once config('storage.routes') . $route;
}
}

public function run()
public function execute()
{
try {
Router::dispatch($this->request, $this->response);
}
$response = new Response();

try { Router::dispatch(new Request(), $response); }

catch (Exception $e) {
if (config('errors.log')) save_log('Exception: ' . $e);
if (config('errors.display')) die($e);

$this->response->view(config('errors.views.500'), [], 500);
$response->view(config('errors.views.500'), [], 500);
}
}
}
Loading

0 comments on commit d9debb3

Please sign in to comment.