Skip to content

Commit

Permalink
Updating and fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Nov 11, 2024
1 parent bf9f774 commit ab6267e
Show file tree
Hide file tree
Showing 39 changed files with 1,083 additions and 8,362 deletions.
10 changes: 5 additions & 5 deletions .dev/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ LEAN_APP_DIR = '' # Base of application without trai
LEAN_DEBUG = 1 # Debug flag

# Database
LEAN_DB_HOST = 'db' # Database host
LEAN_DB_USER = 'leantime' # Database username
LEAN_DB_PASSWORD = 'leantime' # Database password
LEAN_DB_DATABASE = 'leantime_test' # Database name
LEAN_DB_PORT = '3306' # Database port
LEAN_DB_HOST='localhost' # Database host
LEAN_DB_USER='root' # Database username
LEAN_DB_PASSWORD='test' # Database password
LEAN_DB_DATABASE='leantime' # Database name
LEAN_DB_PORT='3306' # Database port

## Optional Configuraiton, you may ommit these from your .env file

Expand Down
12 changes: 12 additions & 0 deletions .idea/codebuddy.xml

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

4 changes: 1 addition & 3 deletions .idea/leantime-oss.iml

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

12 changes: 1 addition & 11 deletions .idea/php-test-framework.xml

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

14 changes: 7 additions & 7 deletions .idea/php.xml

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

10 changes: 0 additions & 10 deletions .lando.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .phpstan/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use Leantime\Core\Http\HttpKernel;

define('RESTRICTED', true);
define('ROOT', __DIR__);
define('APP_ROOT', dirname(__DIR__, 1));
define('LEAN_CLI', false);

require __DIR__.'/../vendor/autoload.php';

$app = require_once APP_ROOT . '/bootstrap/app.php';

$app->make(\Leantime\Core\Console\ConsoleKernel::class)->bootstrap();
37 changes: 37 additions & 0 deletions .phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
parameters:
bootstrapFiles:
- bootstrap.php
level: 0
inferPrivatePropertyTypeFromConstructor: true
paths:
- ../public
- ../app
excludePaths:
- ../app/Plugins/*/vendor/*
scanDirectories:
- ../vendor
- ../config
ignoreErrors:
#- '#Call to an undefined static method Illuminate\\Http\\Request::[a-zA-Z0-9\\_]()#'
#- '#Access to undefined constant Illuminate\\Http\\Request::[a-zA-Z0-9\\_]()#'
#- '#Call to an undefined static method Carbon\\CarbonImmutable::[a-zA-Z0-9\\_]()#'
# Rules for level 1. Templates use variables through include which are not detected by phpstan
#-
# messages:
# - '#Attribute class Leantime\\Domain\\Connector\\Models\\DbColumn does not exist\.#'
# - '#Variable \$__data might not be defined\.#'
# - '#Constant BASE_URL not found\.#'
# - '#Constant CURRENT_URL not found\.#'
# - '#Variable \$login might not be defined\.#'
# - '#Variable \$roles might not be defined\.#'
# paths:
# - app/Domain/*/Templates/*.tpl.php
# - app/Domain/*/Templates/*.inc.php
# - app/Domain/*/Templates/submodules/*.sub.php
universalObjectCratesClasses:
- Leantime\Core\Configuration\Environment
earlyTerminatingMethodCalls:
Leantime\Core\UI\Templates:
- redirect
- display
- displayPartial
1 change: 0 additions & 1 deletion .phpunit.result.cache

This file was deleted.

4 changes: 2 additions & 2 deletions app/Command/CheckEventListeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
use Symfony\Component\Finder\Finder;

#[AsCommand(
name: 'events:check-listeners',
name: 'event:check-listeners',
description: 'Validate event listener paths against available events',
)]
class CheckEventListeners extends Command
{
protected $signature = 'events:check-listeners {--debug : Show detailed debug information} {--clear-cache : Clear the event cache}';
protected $signature = 'event:check-listeners {--debug : Show detailed debug information} {--clear-cache : Clear the event cache}';

protected $description = 'Check if all registered event listeners match existing events';

Expand Down
19 changes: 19 additions & 0 deletions app/Core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class Application extends \Illuminate\Foundation\Application
{
use DispatchesEvents;

/**
* Application bootstrap status
*
* @var bool
*/
private static bool $bootstrapped = false;

/**
* Constructor for the class.
*
Expand Down Expand Up @@ -155,4 +162,16 @@ public function boot()
self::dispatchEvent('afterBootingServiceProviders');

}

/**
* Set the application as having been bootstrapped
*
* @return Application
*/
public static function setHasBeenBootstrapped(): self
{
self::$bootstrapped = true;

return self::getInstance();
}
}
45 changes: 45 additions & 0 deletions app/Core/Configuration/laravelConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,5 +409,50 @@
'database' => '0',
'prefix' => 'leantime_cache',
],
],
'database' => [
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Below are all of the database connections defined for your application.
| An example configuration is provided for each database system which
| is supported by Laravel. You're free to add / remove connections.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DB_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
'busy_timeout' => null,
'journal_mode' => null,
'synchronous' => null,
],
'mysql' => [
'driver' => 'mysql',
'url' => env('DB_URL'),
'host' => env('LEAN_DB_HOST', '127.0.0.1'),
'port' => env('LEAN_DB_PORT', '3306'),
'database' => env('LEAN_DB_DATABASE', 'laravel'),
'username' => env('LEAN_DB_USER', 'root'),
'password' => env('LEAN_DB_PASSWORD', ''),
'unix_socket' => env('LEAN_DB_SOCKET', ''),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],

],
]
]
];
3 changes: 2 additions & 1 deletion app/Core/Db/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Leantime\Core\Db;

use Illuminate\Database\DatabaseManager;
use Illuminate\Support\Facades\Log;
use Leantime\Core\Events\DispatchesEvents;
use PDO;

/**
* Database Class - Very simple abstraction layer for pdo connection
*/
class Db
class Db extends DatabaseManager
{
use DispatchesEvents;

Expand Down
9 changes: 5 additions & 4 deletions app/Core/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class Language
* @param Environment $config The configuration environment.
* @param ApiRequest $request The API request object.
*/
public function __construct() {
public function __construct()
{

$this->config = app('config');
$this->request = app('request');
Expand Down Expand Up @@ -167,9 +168,9 @@ public function getCurrentLanguage(): string
return $this->language;
}

$language = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '');
$language = str_replace("_", "-", $language);
if($language && $this->isValidLanguage($language)) {
$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? 'en-US', 0, 2);
$language = str_replace('_', '-', $language);
if ($language && $this->isValidLanguage($language)) {
return $this->language;
}

Expand Down
25 changes: 18 additions & 7 deletions app/Core/Middleware/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Auth
'auth.resetPw',
'auth.userInvite',
'install',
'install.index',
'install.update',
'errors.error404',
'errors.error500',
Expand Down Expand Up @@ -56,7 +57,7 @@ public function redirectWithOrigin(string $route, string $origin, IncomingReques

$uri = ltrim(str_replace('.', '/', $route), '/');
$destination = BASE_URL.'/'.$uri;
$originClean = Str::replaceStart("/", "", $origin);
$originClean = Str::replaceStart('/', '', $origin);
$queryParams = ! empty($origin) && $origin !== '/' ? '?'.http_build_query(['redirect' => $originClean]) : '';

if ($request->getCurrentRoute() == $route) {
Expand All @@ -77,7 +78,8 @@ public function handle(IncomingRequest $request, Closure $next): Response
}

if (! $this->authService->loggedIn()) {
$loginRedirect = self::dispatch_filter("loginRoute", 'auth.login', ["request" => $request]);
$loginRedirect = self::dispatch_filter('loginRoute', 'auth.login', ['request' => $request]);

return $this->redirectWithOrigin($loginRedirect, $request->getRequestUri(), $request) ?: $next($request);
}

Expand Down Expand Up @@ -112,19 +114,28 @@ public function handle(IncomingRequest $request, Closure $next): Response
return $response;
}

public function isPublicController($currentPath ) {
public function isPublicController($currentPath)
{

//path comes in with dots as separator.
//We only need to compare the first 2 segments
$currentPath = explode(".", $currentPath);
$currentPath = explode('.', $currentPath);

//Todo: We may want to take out hx if we have public htmx paths
if(! is_array($currentPath) || count($currentPath) < 2){
if (! is_array($currentPath)) {
return false;
}

if (count($currentPath) == 1) {
if (in_array($currentPath[0], $this->publicActions)) {
return true;
}

return false;
}

$controllerPath = $currentPath[0].".".$currentPath[1];
if(in_array($controllerPath, $this->publicActions)){
$controllerPath = $currentPath[0].'.'.$currentPath[1];
if (in_array($controllerPath, $this->publicActions)) {
return true;
}

Expand Down
Loading

0 comments on commit ab6267e

Please sign in to comment.