Skip to content

Commit

Permalink
update: readme
Browse files Browse the repository at this point in the history
check environnement for database actions
  • Loading branch information
eliseekn committed Oct 29, 2021
1 parent 454cfa5 commit 87c1ce8
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 116 deletions.
44 changes: 9 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,16 @@ yarn

## Installation

1\. On your terminal run:
```
composer create-project eliseekn/tinymvc project-name
```

2\. Setup your web server configuration

For ***Apache*** server, edit your ```.htaccess``` with the following lines:
1\. Create new composer project

On your console :
```
<IfModule mod_rewrite.c>
RewriteEngine on
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect request to main controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php
</IfModule>
composer create-project eliseekn/tinymvc project-name
```

For ***Nginx*** server, add the following to your server declaration

```
server {
location / {
try_files $uri $uri/ /index.php;
}
}
```
3\. Install packages dependencies
2\. Install packages dependencies

On your terminal:
On your console :
```
cd ./project-name
yarn && yarn build
Expand All @@ -60,25 +34,25 @@ yarn && yarn build

1\. Setup application

On your terminal:
On your console :
```
cp .env.example .env
php console app:setup
```
2\. Setup database

On your terminal:
On your console :
```
php console db:create
php console migrations:run --seed
```
3\. Start a local server development

On your terminal:
On your console :
```
php console server:start
```
For more console commands:
For more console commands :
```
php console list
```
Expand Down
8 changes: 6 additions & 2 deletions config/testing.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
*/

return [
'database' => [
'driver' => 'sqlite',
'suffix' => '_test'
],

'host' => '127.0.0.1',
'port' => 8889,
'process' => 4 //phpunit process number
];
];
5 changes: 4 additions & 1 deletion core/Console/Database/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$databases = $input->getArgument('database');

if (is_null($databases) || empty($databases)) {
$databases = [config('database.name')];
$db = config('app.env') !== 'test' ? config('database.name') :
config('database.name') . config('testing.database.suffix') ;

$databases = [$db];
}

foreach ($databases as $database) {
Expand Down
5 changes: 4 additions & 1 deletion core/Console/Database/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$databases = $input->getArgument('database');

if (is_null($databases) || empty($databases)) {
$databases = [config('database.name')];
$db = config('app.env') !== 'test' ? config('database.name') :
config('database.name') . config('testing.database.suffix') ;

$databases = [$db];
}

foreach ($databases as $database) {
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$models = $input->getArgument('model');

foreach ($models as $model) {
list($name, $class) = Make::generateClass($model, 'actions', true, true);
list(, $class) = Make::generateClass($model, 'actions', true, true);

if (!Make::createActions($model, $input->getOption('namespace'))) {
$output->writeln('<fg=yellow>Failed to create actions "' . $class . '"</fg>');
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
list($name, $class) = Make::generateClass($input->getArgument('console'), '', true);
list(, $class) = Make::generateClass($input->getArgument('console'), '', true);

if (!Make::createConsole($input->getArgument('console'), $input->getOption('command'), $input->getOption('description'), $input->getOption('namespace'))) {
$output->writeln('<fg=yellow>Failed to create command "' . $class . '"</fg>');
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$controllers = $input->getArgument('controller');

foreach ($controllers as $controller) {
list($name, $class) = Make::generateClass($controller, 'controller', true, true);
list(, $class) = Make::generateClass($controller, 'controller', true, true);

if (!Make::createController($controller, $input->getOption('namespace'))) {
$output->writeln('<fg=yellow>Failed to create controller "' . $class . '"</fg>');
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$factorys = $input->getArgument('factory');

foreach ($factorys as $factory) {
list($name, $class) = Make::generateClass($factory, 'factory', true, true);
list(, $class) = Make::generateClass($factory, 'factory', true, true);

if (!Make::createFactory($factory, $input->getOption('namespace'))) {
$output->writeln('<fg=yellow>Failed to create factory "' . Make::fixPluralTypo($class, true) . '"</fg>');
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$helpers = $input->getArgument('helper');

foreach ($helpers as $helper) {
list($name, $class) = Make::generateClass($helper, '');
list(, $class) = Make::generateClass($helper, '');

if (!Make::createHelper($helper)) {
$output->writeln('<fg=yellow>Failed to create helper "' . $class . '"</fg>');
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$mails = $input->getArgument('mail');

foreach ($mails as $mail) {
list($name, $class) = Make::generateClass($mail, 'mail');
list(, $class) = Make::generateClass($mail, 'mail');

if (!Make::createMail($mail)) {
$output->writeln('<fg=yellow>Failed to create mail template "' . $class . '"</fg>');
Expand Down
12 changes: 6 additions & 6 deletions core/Console/Make/Make.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function generateClass(string $base_name, string $suffix = '', boo

public static function createController(string $controller, ?string $namespace = null)
{
list($name, $class) = self::generateClass($controller, 'controller', true, true);
list(, $class) = self::generateClass($controller, 'controller', true, true);

$data = self::stubs()->readFile('Controller.stub');
$data = self::addNamespace($data, 'App\Http\Controllers', $namespace);
Expand Down Expand Up @@ -186,7 +186,7 @@ public static function createFactory(string $factory, ?string $namespace = null)

public static function createHelper(string $helper)
{
list($name, $class) = self::generateClass($helper, 'helper', true);
list(, $class) = self::generateClass($helper, 'helper', true);

$data = self::stubs()->readFile('Helper.stub');
$data = str_replace('CLASSNAME', $class, $data);
Expand All @@ -200,7 +200,7 @@ public static function createHelper(string $helper)

public static function createTest(string $test, bool $unit_test, ?string $namespace = null)
{
list($name, $class) = self::generateClass($test, 'test', true);
list(, $class) = self::generateClass($test, 'test', true);

$storage = Storage::path(config('storage.tests'));

Expand All @@ -223,7 +223,7 @@ public static function createTest(string $test, bool $unit_test, ?string $namesp

public static function createValidator(string $validator, ?string $namespace = null)
{
list($name, $class) = self::generateClass($validator, 'validator', true);
list(, $class) = self::generateClass($validator, 'validator', true);

$data = self::stubs()->readFile('Validator.stub');
$data = self::addNamespace($data, 'App\Http\Validators', $namespace);
Expand All @@ -244,7 +244,7 @@ public static function createValidator(string $validator, ?string $namespace = n

public static function createMiddleware(string $middleware)
{
list($name, $class) = self::generateClass($middleware, '', true);
list(, $class) = self::generateClass($middleware, '', true);

$data = self::stubs()->readFile('Middleware.stub');
$data = str_replace('CLASSNAME', $class, $data);
Expand Down Expand Up @@ -303,7 +303,7 @@ public static function createView(?string $view, ?string $layout)

public static function createConsole(string $console, string $command, string $description, ?string $namespace = null)
{
list($_name, $class) = self::generateClass($console, '', true);
list(, $class) = self::generateClass($console, '', true);

$data = self::stubs()->readFile('Console.stub');
$data = self::addNamespace($data, 'App\Console', $namespace);
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$middlewares = $input->getArgument('middleware');

foreach ($middlewares as $middleware) {
list($name, $class) = Make::generateClass($middleware, '', true);
list(, $class) = Make::generateClass($middleware, '', true);

if (!Make::createMiddleware($middleware)) {
$output->writeln('<fg=yellow>Failed to create middleware "' . $class . '"</fg>');
Expand Down
4 changes: 2 additions & 2 deletions core/Console/Make/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$migrations = $input->getArgument('migration');

foreach ($migrations as $migration) {
list($name, $class) = Make::generateClass($migration, 'migration');
list(, $class) = Make::generateClass($migration, 'migration');

if (!Make::createMigration($migration)) {
$output->writeln('<fg=yellow>Failed to create migration "' . $class . '"</fg>');
Expand All @@ -44,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($input->getOption('seed')) {
foreach ($migrations as $migration) {
list($name, $class) = Make::generateClass($migration, 'seed');
list(, $class) = Make::generateClass($migration, 'seed');

if (!Make::createSeed($migration)) {
$output->writeln('<fg=yellow>Failed to create seed "' . $class . '"</fg>');
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$seeds = $input->getArgument('seed');

foreach ($seeds as $seed) {
list($name, $class) = Make::generateClass($seed, 'seed', true, true);
list(, $class) = Make::generateClass($seed, 'seed', true, true);

if (!Make::createSeed($seed)) {
$output->writeln('<fg=yellow>Failed to create seed "' . Make::fixPluralTypo($class, true) . '"</fg>');
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$tests = $input->getArgument('test');

foreach ($tests as $test) {
list($name, $class) = Make::generateClass($test, 'test', true);
list(, $class) = Make::generateClass($test, 'test', true);

if (!Make::createTest($test, $input->getOption('unit'), $input->getOption('subdir'))) {
$output->writeln('<fg=yellow>Failed to create test "' . $class . '"</fg>');
Expand Down
2 changes: 1 addition & 1 deletion core/Console/Make/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$validators = $input->getArgument('validator');

foreach ($validators as $validator) {
list($name, $class) = Make::generateClass($validator, 'validator', true);
list(, $class) = Make::generateClass($validator, 'validator', true);

if (!Make::createValidator($validator, $input->getOption('namespace'))) {
$output->writeln('<fg=yellow>Failed to create request validator "' . $class . '"</fg>');
Expand Down
26 changes: 9 additions & 17 deletions core/Console/Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<fg=yellow>You must set APP_ENV to test in application configuration</>');
return Command::FAILURE;
}

$server = new Process(['php', '-S', config('testing.host') . ':' . config('testing.port')]);
$server->setTimeout(null);
$server->start();

if (config('database.driver') === 'sqlite' && config('database.sqlite.memory')) {
$output->writeln('<fg=yellow>You must set SQLite memory to false in database configuration</>');
return Command::FAILURE;
}

$server_process = new Process(['php', '-S', config('testing.host') . ':' . config('testing.port')]);
$server_process->setTimeout(null);
$server_process->start();

$process = new Process(['php', 'vendor/bin/phpunit']);
$process->setTimeout(null);
$process->start();

$process->wait(function ($type, $buffer) use ($output) {
$output->write($buffer);
});
$phpunit = new Process(['php', 'vendor/bin/phpunit']);
$phpunit->setTimeout(null);
$phpunit->start();
$phpunit->wait(function ($type, $buffer) { echo $buffer; });

$server_process->stop();
$server->stop();

return Command::SUCCESS;
}
Expand Down
4 changes: 3 additions & 1 deletion core/Database/Connection/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class Connection

private function __construct()
{
$this->db = config('database.driver') === 'mysql' ? new MySQLConnection() : new SQLiteConnection();
$driver = config('app.env') === 'test' ? $driver = config('testing.database.driver') : config('database.driver');

$this->db = $driver === 'mysql' ? new MySQLConnection() : new SQLiteConnection();
}

public static function getInstance(): self
Expand Down
4 changes: 4 additions & 0 deletions core/Database/Connection/SQLiteConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function __construct()

private function getDB()
{
if (config('app.env') === 'test') {
return config('storage.sqlite') . config('database.name') . config('testing.database.suffix') . '.db';
}

return config('database.sqlite.memory') ? ':memory:'
: config('storage.sqlite') . config('database.name') . '.db';
}
Expand Down
4 changes: 1 addition & 3 deletions core/Database/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class Factory
protected static $model;
protected $class;

/**
* \Faker\Factory
*/
/** @var \Faker\Generator $faker */
public $faker;

public function __construct(int $count = 1)
Expand Down
4 changes: 3 additions & 1 deletion core/Database/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ public function primaryKey(): self

public function addPrimaryKey(string $column, bool $auto_increment = true): self
{
$pk = config('database.driver') === 'mysql' ? $this->addBigInt($column) : $this->addInteger($column);
$driver = config('app.env') === 'test' ? $driver = config('testing.database.driver') : config('database.driver');

$pk = $driver === 'mysql' ? $this->addBigInt($column) : $this->addInteger($column);
$pk->primaryKey();

if ($auto_increment) $pk->autoIncrement();
Expand Down
Loading

0 comments on commit 87c1ce8

Please sign in to comment.