Convert class const's to enum's (#1050)
* convert `Migrate::(UP|DOWN)` class const to `MigrateDirection` enum * convert `Handler::(ENV_PRODUCTION|ENV_DEVELOPMENT)` class const to `Environment` enum * convert `ShiftSignupState::(FREE|...|NOT_ARRIVED)` class const to `ShiftSignupStatus::(FREE|...|NOT_ARRIVED)` enum
This commit is contained in:
parent
2db70c96ed
commit
e844c98871
10
bin/migrate
10
bin/migrate
|
@ -4,7 +4,9 @@
|
||||||
use Composer\Autoload\ClassLoader;
|
use Composer\Autoload\ClassLoader;
|
||||||
use Engelsystem\Application;
|
use Engelsystem\Application;
|
||||||
use Engelsystem\Database\Migration\Migrate;
|
use Engelsystem\Database\Migration\Migrate;
|
||||||
|
use Engelsystem\Database\Migration\Direction;
|
||||||
use Engelsystem\Database\Migration\MigrationServiceProvider;
|
use Engelsystem\Database\Migration\MigrationServiceProvider;
|
||||||
|
use Engelsystem\Environment;
|
||||||
use Engelsystem\Exceptions\Handler;
|
use Engelsystem\Exceptions\Handler;
|
||||||
use Engelsystem\Exceptions\Handlers\NullHandler;
|
use Engelsystem\Exceptions\Handlers\NullHandler;
|
||||||
|
|
||||||
|
@ -19,7 +21,7 @@ $app->register(MigrationServiceProvider::class);
|
||||||
|
|
||||||
/** @var Handler $errorHandler */
|
/** @var Handler $errorHandler */
|
||||||
$errorHandler = $app->get(Handler::class);
|
$errorHandler = $app->get(Handler::class);
|
||||||
$errorHandler->setHandler(Handler::ENV_PRODUCTION, new NullHandler());
|
$errorHandler->setHandler(Environment::PRODUCTION, new NullHandler());
|
||||||
|
|
||||||
/** @var Migrate $migration */
|
/** @var Migrate $migration */
|
||||||
$migration = $app->get('db.migration');
|
$migration = $app->get('db.migration');
|
||||||
|
@ -32,10 +34,10 @@ if (in_array('help', $argv) || in_array('--help', $argv) || in_array('-h', $argv
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$method = Migrate::UP;
|
$direction = Direction::UP;
|
||||||
if (in_array('down', $argv)) {
|
if (in_array('down', $argv)) {
|
||||||
$argv = array_values($argv);
|
$argv = array_values($argv);
|
||||||
$method = Migrate::DOWN;
|
$direction = Direction::DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
$oneStep = false;
|
$oneStep = false;
|
||||||
|
@ -48,4 +50,4 @@ if (in_array('force', $argv) || in_array('--force', $argv) || in_array('-f', $ar
|
||||||
$force = true;
|
$force = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$migration->run($baseDir, $method, $oneStep, $force);
|
$migration->run($baseDir, $direction, $oneStep, $force);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use Engelsystem\Models\AngelType;
|
use Engelsystem\Models\AngelType;
|
||||||
use Engelsystem\Models\Shifts\Shift;
|
use Engelsystem\Models\Shifts\Shift;
|
||||||
use Engelsystem\Models\Shifts\ShiftEntry;
|
use Engelsystem\Models\Shifts\ShiftEntry;
|
||||||
|
use Engelsystem\Models\Shifts\ShiftSignupStatus;
|
||||||
use Engelsystem\Models\User\User;
|
use Engelsystem\Models\User\User;
|
||||||
use Engelsystem\Models\UserAngelType;
|
use Engelsystem\Models\UserAngelType;
|
||||||
use Engelsystem\ShiftSignupState;
|
use Engelsystem\ShiftSignupState;
|
||||||
|
@ -180,21 +181,16 @@ function shift_entry_create_controller_supporter(Shift $shift, AngelType $angelt
|
||||||
*/
|
*/
|
||||||
function shift_entry_error_message(ShiftSignupState $shift_signup_state)
|
function shift_entry_error_message(ShiftSignupState $shift_signup_state)
|
||||||
{
|
{
|
||||||
if ($shift_signup_state->getState() == ShiftSignupState::ANGELTYPE) {
|
match ($shift_signup_state->getState()) {
|
||||||
error(__('You need be accepted member of the angeltype.'));
|
ShiftSignupStatus::ANGELTYPE => error(__('You need be accepted member of the angeltype.')),
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) {
|
ShiftSignupStatus::COLLIDES => error(__('This shift collides with one of your shifts.')),
|
||||||
error(__('This shift collides with one of your shifts.'));
|
ShiftSignupStatus::OCCUPIED => error(__('This shift is already occupied.')),
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::OCCUPIED) {
|
ShiftSignupStatus::SHIFT_ENDED => error(__('This shift ended already.')),
|
||||||
error(__('This shift is already occupied.'));
|
ShiftSignupStatus::NOT_ARRIVED => error(__('You are not marked as arrived.')),
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::SHIFT_ENDED) {
|
ShiftSignupStatus::NOT_YET => error(__('You are not allowed to sign up yet.')),
|
||||||
error(__('This shift ended already.'));
|
ShiftSignupStatus::SIGNED_UP => error(__('You are signed up for this shift.')),
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::NOT_ARRIVED) {
|
default => null, // ShiftSignupStatus::FREE|ShiftSignupStatus::ADMIN
|
||||||
error(__('You are not marked as arrived.'));
|
};
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::NOT_YET) {
|
|
||||||
error(__('You are not allowed to sign up yet.'));
|
|
||||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::SIGNED_UP) {
|
|
||||||
error(__('You are signed up for this shift.'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Engelsystem\Models\Shifts\NeededAngelType;
|
||||||
use Engelsystem\Models\Shifts\ScheduleShift;
|
use Engelsystem\Models\Shifts\ScheduleShift;
|
||||||
use Engelsystem\Models\Shifts\Shift;
|
use Engelsystem\Models\Shifts\Shift;
|
||||||
use Engelsystem\Models\Shifts\ShiftType;
|
use Engelsystem\Models\Shifts\ShiftType;
|
||||||
|
use Engelsystem\Models\Shifts\ShiftSignupStatus;
|
||||||
use Engelsystem\ShiftSignupState;
|
use Engelsystem\ShiftSignupState;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
@ -313,7 +314,7 @@ function shift_controller()
|
||||||
$angeltypes = AngelType::all();
|
$angeltypes = AngelType::all();
|
||||||
$user_shifts = Shifts_by_user($user->id);
|
$user_shifts = Shifts_by_user($user->id);
|
||||||
|
|
||||||
$shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
|
$shift_signup_state = new ShiftSignupState(ShiftSignupStatus::OCCUPIED, 0);
|
||||||
foreach ($angeltypes as $angeltype) {
|
foreach ($angeltypes as $angeltype) {
|
||||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
||||||
if (empty($needed_angeltype)) {
|
if (empty($needed_angeltype)) {
|
||||||
|
|
|
@ -2,67 +2,24 @@
|
||||||
|
|
||||||
namespace Engelsystem;
|
namespace Engelsystem;
|
||||||
|
|
||||||
|
use Engelsystem\Models\Shifts\ShiftSignupStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BO to represent if there are free slots on a shift for a given angeltype
|
* BO to represent if there are free slots on a shift for a given angeltype
|
||||||
* and if signup for a given user is possible (or not, because of collisions, etc.)
|
* and if signup for a given user is possible (or not, because of collisions, etc.)
|
||||||
*/
|
*/
|
||||||
class ShiftSignupState
|
class ShiftSignupState
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Shift has free places
|
|
||||||
*/
|
|
||||||
public const FREE = 'FREE';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shift collides with users shifts
|
|
||||||
*/
|
|
||||||
public const COLLIDES = 'COLLIDES';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User cannot join because of a restricted angeltype or user is not in the angeltype
|
|
||||||
*/
|
|
||||||
public const ANGELTYPE = 'ANGELTYPE';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shift is full
|
|
||||||
*/
|
|
||||||
public const OCCUPIED = 'OCCUPIED';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User is admin and can do what he wants.
|
|
||||||
*/
|
|
||||||
public const ADMIN = 'ADMIN';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shift has already ended, no signup
|
|
||||||
*/
|
|
||||||
public const SHIFT_ENDED = 'SHIFT_ENDED';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shift is not available yet
|
|
||||||
*/
|
|
||||||
public const NOT_YET = 'NOT_YET';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User is already signed up
|
|
||||||
*/
|
|
||||||
public const SIGNED_UP = 'SIGNED_UP';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User has to be arrived
|
|
||||||
*/
|
|
||||||
public const NOT_ARRIVED = 'NOT_ARRIVED';
|
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $freeEntries;
|
private $freeEntries;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ShiftSignupState constructor.
|
* ShiftSignupState constructor.
|
||||||
*
|
*
|
||||||
* @param string $state
|
* @param ShiftSignupStatus $state
|
||||||
* @param int $free_entries
|
* @param int $free_entries
|
||||||
*/
|
*/
|
||||||
public function __construct(private $state, $free_entries)
|
public function __construct(private ShiftSignupStatus $state, $free_entries)
|
||||||
{
|
{
|
||||||
$this->freeEntries = $free_entries;
|
$this->freeEntries = $free_entries;
|
||||||
}
|
}
|
||||||
|
@ -82,17 +39,17 @@ class ShiftSignupState
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $state
|
* @param ShiftSignupStatus $state
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private function valueForState($state)
|
private function valueForState(ShiftSignupStatus $state)
|
||||||
{
|
{
|
||||||
return match ($state) {
|
return match ($state) {
|
||||||
ShiftSignupState::NOT_ARRIVED, ShiftSignupState::NOT_YET, ShiftSignupState::SHIFT_ENDED => 100,
|
ShiftSignupStatus::NOT_ARRIVED, ShiftSignupStatus::NOT_YET, ShiftSignupStatus::SHIFT_ENDED => 100,
|
||||||
ShiftSignupState::SIGNED_UP => 90,
|
ShiftSignupStatus::SIGNED_UP => 90,
|
||||||
ShiftSignupState::FREE => 80,
|
ShiftSignupStatus::FREE => 80,
|
||||||
ShiftSignupState::ANGELTYPE, ShiftSignupState::COLLIDES => 70,
|
ShiftSignupStatus::ANGELTYPE, ShiftSignupStatus::COLLIDES => 70,
|
||||||
ShiftSignupState::OCCUPIED, ShiftSignupState::ADMIN => 60,
|
ShiftSignupStatus::OCCUPIED, ShiftSignupStatus::ADMIN => 60,
|
||||||
default => 0,
|
default => 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -105,7 +62,7 @@ class ShiftSignupState
|
||||||
public function isSignupAllowed()
|
public function isSignupAllowed()
|
||||||
{
|
{
|
||||||
return match ($this->state) {
|
return match ($this->state) {
|
||||||
ShiftSignupState::FREE, ShiftSignupState::ADMIN => true,
|
ShiftSignupStatus::FREE, ShiftSignupStatus::ADMIN => true,
|
||||||
default => false,
|
default => false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -113,9 +70,9 @@ class ShiftSignupState
|
||||||
/**
|
/**
|
||||||
* Return the shift signup state
|
* Return the shift signup state
|
||||||
*
|
*
|
||||||
* @return string
|
* @return ShiftSignupStatus
|
||||||
*/
|
*/
|
||||||
public function getState()
|
public function getState(): ShiftSignupStatus
|
||||||
{
|
{
|
||||||
return $this->state;
|
return $this->state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ use Engelsystem\Helpers\Carbon;
|
||||||
use Engelsystem\Models\AngelType;
|
use Engelsystem\Models\AngelType;
|
||||||
use Engelsystem\Models\Shifts\Shift;
|
use Engelsystem\Models\Shifts\Shift;
|
||||||
use Engelsystem\Models\Shifts\ShiftEntry;
|
use Engelsystem\Models\Shifts\ShiftEntry;
|
||||||
|
use Engelsystem\Models\Shifts\ShiftSignupStatus;
|
||||||
use Engelsystem\Models\User\User;
|
use Engelsystem\Models\User\User;
|
||||||
use Engelsystem\Models\UserAngelType;
|
use Engelsystem\Models\UserAngelType;
|
||||||
use Engelsystem\ShiftsFilter;
|
use Engelsystem\ShiftsFilter;
|
||||||
|
@ -323,11 +324,11 @@ function Shift_signup_allowed_angel(
|
||||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||||
|
|
||||||
if (config('signup_requires_arrival') && !$user->state->arrived) {
|
if (config('signup_requires_arrival') && !$user->state->arrived) {
|
||||||
return new ShiftSignupState(ShiftSignupState::NOT_ARRIVED, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::NOT_ARRIVED, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config('signup_advance_hours') && $shift->start->timestamp > time() + config('signup_advance_hours') * 3600) {
|
if (config('signup_advance_hours') && $shift->start->timestamp > time() + config('signup_advance_hours') * 3600) {
|
||||||
return new ShiftSignupState(ShiftSignupState::NOT_YET, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::NOT_YET, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($user_shifts)) {
|
if (empty($user_shifts)) {
|
||||||
|
@ -344,7 +345,7 @@ function Shift_signup_allowed_angel(
|
||||||
|
|
||||||
if ($signed_up) {
|
if ($signed_up) {
|
||||||
// you cannot join if you already signed up for this shift
|
// you cannot join if you already signed up for this shift
|
||||||
return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::SIGNED_UP, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
$shift_post_signup_total_allowed_seconds =
|
$shift_post_signup_total_allowed_seconds =
|
||||||
|
@ -353,11 +354,11 @@ function Shift_signup_allowed_angel(
|
||||||
|
|
||||||
if (time() > $shift->start->timestamp + $shift_post_signup_total_allowed_seconds) {
|
if (time() > $shift->start->timestamp + $shift_post_signup_total_allowed_seconds) {
|
||||||
// you can only join if the shift is in future
|
// you can only join if the shift is in future
|
||||||
return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::SHIFT_ENDED, $free_entries);
|
||||||
}
|
}
|
||||||
if ($free_entries == 0) {
|
if ($free_entries == 0) {
|
||||||
// you cannot join if shift is full
|
// you cannot join if shift is full
|
||||||
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::OCCUPIED, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($user_angeltype)) {
|
if (empty($user_angeltype)) {
|
||||||
|
@ -373,16 +374,16 @@ function Shift_signup_allowed_angel(
|
||||||
// you cannot join if you are not confirmed
|
// you cannot join if you are not confirmed
|
||||||
// you cannot join if angeltype has no self signup
|
// you cannot join if angeltype has no self signup
|
||||||
|
|
||||||
return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::ANGELTYPE, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shift_collides($shift, $user_shifts)) {
|
if (Shift_collides($shift, $user_shifts)) {
|
||||||
// you cannot join if user already joined a parallel of this shift
|
// you cannot join if user already joined a parallel of this shift
|
||||||
return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::COLLIDES, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hooray, shift is free for you!
|
// Hooray, shift is free for you!
|
||||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::FREE, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -396,10 +397,10 @@ function Shift_signup_allowed_angeltype_supporter(AngelType $needed_angeltype, $
|
||||||
{
|
{
|
||||||
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
$free_entries = Shift_free_entries($needed_angeltype, $shift_entries);
|
||||||
if ($free_entries == 0) {
|
if ($free_entries == 0) {
|
||||||
return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::OCCUPIED, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::FREE, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -415,10 +416,10 @@ function Shift_signup_allowed_admin(AngelType $needed_angeltype, $shift_entries)
|
||||||
|
|
||||||
if ($free_entries == 0) {
|
if ($free_entries == 0) {
|
||||||
// User shift admins may join anybody in every shift
|
// User shift admins may join anybody in every shift
|
||||||
return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::ADMIN, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ShiftSignupState(ShiftSignupState::FREE, $free_entries);
|
return new ShiftSignupState(ShiftSignupStatus::FREE, $free_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Engelsystem;
|
||||||
use Engelsystem\Models\AngelType;
|
use Engelsystem\Models\AngelType;
|
||||||
use Engelsystem\Models\Shifts\Shift;
|
use Engelsystem\Models\Shifts\Shift;
|
||||||
use Engelsystem\Models\Shifts\ShiftEntry;
|
use Engelsystem\Models\Shifts\ShiftEntry;
|
||||||
|
use Engelsystem\Models\Shifts\ShiftSignupStatus;
|
||||||
use Engelsystem\Models\User\User;
|
use Engelsystem\Models\User\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
@ -72,11 +73,11 @@ class ShiftCalendarShiftRenderer
|
||||||
private function classForSignupState(ShiftSignupState $shiftSignupState)
|
private function classForSignupState(ShiftSignupState $shiftSignupState)
|
||||||
{
|
{
|
||||||
return match ($shiftSignupState->getState()) {
|
return match ($shiftSignupState->getState()) {
|
||||||
ShiftSignupState::ADMIN, ShiftSignupState::OCCUPIED => 'success',
|
ShiftSignupStatus::ADMIN, ShiftSignupStatus::OCCUPIED => 'success',
|
||||||
ShiftSignupState::SIGNED_UP => 'primary',
|
ShiftSignupStatus::SIGNED_UP => 'primary',
|
||||||
ShiftSignupState::NOT_ARRIVED, ShiftSignupState::NOT_YET, ShiftSignupState::SHIFT_ENDED => 'secondary',
|
ShiftSignupStatus::NOT_ARRIVED, ShiftSignupStatus::NOT_YET, ShiftSignupStatus::SHIFT_ENDED => 'secondary',
|
||||||
ShiftSignupState::ANGELTYPE, ShiftSignupState::COLLIDES => 'warning',
|
ShiftSignupStatus::ANGELTYPE, ShiftSignupStatus::COLLIDES => 'warning',
|
||||||
ShiftSignupState::FREE => 'danger',
|
ShiftSignupStatus::FREE => 'danger',
|
||||||
default => 'light',
|
default => 'light',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -118,7 +119,7 @@ class ShiftCalendarShiftRenderer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_null($shift_signup_state)) {
|
if (is_null($shift_signup_state)) {
|
||||||
$shift_signup_state = new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, 0);
|
$shift_signup_state = new ShiftSignupState(ShiftSignupStatus::SHIFT_ENDED, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth()->can('user_shifts_admin')) {
|
if (auth()->can('user_shifts_admin')) {
|
||||||
|
@ -173,11 +174,10 @@ class ShiftCalendarShiftRenderer
|
||||||
$freeEntriesCount = $shift_signup_state->getFreeEntries();
|
$freeEntriesCount = $shift_signup_state->getFreeEntries();
|
||||||
$inner_text = _e('%d helper needed', '%d helpers needed', $freeEntriesCount, [$freeEntriesCount]);
|
$inner_text = _e('%d helper needed', '%d helpers needed', $freeEntriesCount, [$freeEntriesCount]);
|
||||||
|
|
||||||
switch ($shift_signup_state->getState()) {
|
$entry = match ($shift_signup_state->getState()) {
|
||||||
case ShiftSignupState::ADMIN:
|
|
||||||
case ShiftSignupState::FREE:
|
|
||||||
// When admin or free display a link + button for sign up
|
// When admin or free display a link + button for sign up
|
||||||
$entry_list[] = '<a class="me-1 text-nowrap" href="'
|
ShiftSignupStatus::ADMIN, ShiftSignupStatus::FREE =>
|
||||||
|
'<a class="me-1 text-nowrap" href="'
|
||||||
. shift_entry_create_link($shift, $angeltype)
|
. shift_entry_create_link($shift, $angeltype)
|
||||||
. '">'
|
. '">'
|
||||||
. $inner_text
|
. $inner_text
|
||||||
|
@ -186,50 +186,30 @@ class ShiftCalendarShiftRenderer
|
||||||
shift_entry_create_link($shift, $angeltype),
|
shift_entry_create_link($shift, $angeltype),
|
||||||
__('Sign up'),
|
__('Sign up'),
|
||||||
'btn-sm btn-primary text-nowrap d-print-none'
|
'btn-sm btn-primary text-nowrap d-print-none'
|
||||||
);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ShiftSignupState::SHIFT_ENDED:
|
|
||||||
// No link and add a text hint, when the shift ended
|
|
||||||
$entry_list[] = $inner_text . ' (' . __('ended') . ')';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ShiftSignupState::NOT_ARRIVED:
|
|
||||||
// No link and add a text hint, when the shift ended
|
|
||||||
$entry_list[] = $inner_text . ' (' . __('please arrive for signup') . ')';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ShiftSignupState::NOT_YET:
|
|
||||||
$entry_list[] = $inner_text . ' (' . __('not yet') . ')';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ShiftSignupState::ANGELTYPE:
|
|
||||||
if ($angeltype->restricted) {
|
|
||||||
// User has to be confirmed on the angeltype first
|
|
||||||
$entry_list[] = $inner_text . icon('mortarboard-fill');
|
|
||||||
} else {
|
|
||||||
// Add link to join the angeltype first
|
|
||||||
$entry_list[] = $inner_text . '<br />'
|
|
||||||
. button(
|
|
||||||
page_link_to(
|
|
||||||
'user_angeltypes',
|
|
||||||
['action' => 'add', 'angeltype_id' => $angeltype->id]
|
|
||||||
),
|
),
|
||||||
|
// No link and add a text hint, when the shift ended
|
||||||
|
ShiftSignupStatus::SHIFT_ENDED => $inner_text . ' (' . __('ended') . ')',
|
||||||
|
// No link and add a text hint, when the shift ended
|
||||||
|
ShiftSignupStatus::NOT_ARRIVED => $inner_text . ' (' . __('please arrive for signup') . ')',
|
||||||
|
ShiftSignupStatus::NOT_YET => $inner_text . ' (' . __('not yet') . ')',
|
||||||
|
ShiftSignupStatus::ANGELTYPE => $angeltype->restricted
|
||||||
|
// User has to be confirmed on the angeltype first
|
||||||
|
? $inner_text . icon('mortarboard-fill')
|
||||||
|
// Add link to join the angeltype first
|
||||||
|
: $inner_text . '<br />'
|
||||||
|
. button(
|
||||||
|
page_link_to('user_angeltypes', ['action' => 'add', 'angeltype_id' => $angeltype->id]),
|
||||||
sprintf(__('Become %s'), $angeltype->name),
|
sprintf(__('Become %s'), $angeltype->name),
|
||||||
'btn-sm'
|
'btn-sm'
|
||||||
);
|
),
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ShiftSignupState::COLLIDES:
|
|
||||||
case ShiftSignupState::SIGNED_UP:
|
|
||||||
// Shift collides or user is already signed up: No signup allowed
|
// Shift collides or user is already signed up: No signup allowed
|
||||||
$entry_list[] = $inner_text;
|
ShiftSignupStatus::COLLIDES, ShiftSignupStatus::SIGNED_UP => $inner_text,
|
||||||
break;
|
|
||||||
|
|
||||||
case ShiftSignupState::OCCUPIED:
|
|
||||||
// Shift is full
|
// Shift is full
|
||||||
break;
|
ShiftSignupStatus::OCCUPIED => null,
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
if (!is_null($entry)) {
|
||||||
|
$entry_list[] = $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
$shifts_row = '<li class="list-group-item d-flex flex-wrap align-items-center ' . $this->classBg() . '">';
|
$shifts_row = '<li class="list-group-item d-flex flex-wrap align-items-center ' . $this->classBg() . '">';
|
||||||
|
|
|
@ -5,6 +5,7 @@ use Engelsystem\Models\Room;
|
||||||
use Engelsystem\Models\Shifts\Shift;
|
use Engelsystem\Models\Shifts\Shift;
|
||||||
use Engelsystem\Models\Shifts\ShiftEntry;
|
use Engelsystem\Models\Shifts\ShiftEntry;
|
||||||
use Engelsystem\Models\Shifts\ShiftType;
|
use Engelsystem\Models\Shifts\ShiftType;
|
||||||
|
use Engelsystem\Models\Shifts\ShiftSignupStatus;
|
||||||
use Engelsystem\Models\UserAngelType;
|
use Engelsystem\Models\UserAngelType;
|
||||||
use Engelsystem\ShiftSignupState;
|
use Engelsystem\ShiftSignupState;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
@ -152,11 +153,11 @@ function Shift_view(Shift $shift, ShiftType $shifttype, Room $room, $angeltypes_
|
||||||
|
|
||||||
$content = [msg()];
|
$content = [msg()];
|
||||||
|
|
||||||
if ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) {
|
if ($shift_signup_state->getState() === ShiftSignupStatus::COLLIDES) {
|
||||||
$content[] = info(__('This shift collides with one of your shifts.'), true);
|
$content[] = info(__('This shift collides with one of your shifts.'), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($shift_signup_state->getState() == ShiftSignupState::SIGNED_UP) {
|
if ($shift_signup_state->getState() === ShiftSignupStatus::SIGNED_UP) {
|
||||||
$content[] = info(__('You are signed up for this shift.'), true);
|
$content[] = info(__('You are signed up for this shift.'), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Engelsystem\Database\Migration;
|
||||||
|
|
||||||
|
enum Direction: string
|
||||||
|
{
|
||||||
|
case UP = 'up';
|
||||||
|
case DOWN = 'down';
|
||||||
|
}
|
|
@ -13,12 +13,6 @@ use Throwable;
|
||||||
|
|
||||||
class Migrate
|
class Migrate
|
||||||
{
|
{
|
||||||
/** @var string */
|
|
||||||
public const UP = 'up';
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
public const DOWN = 'down';
|
|
||||||
|
|
||||||
/** @var callable */
|
/** @var callable */
|
||||||
protected $output;
|
protected $output;
|
||||||
|
|
||||||
|
@ -35,12 +29,10 @@ class Migrate
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a migration
|
* Run a migration
|
||||||
*
|
|
||||||
* @param string $type (up|down)
|
|
||||||
*/
|
*/
|
||||||
public function run(
|
public function run(
|
||||||
string $path,
|
string $path,
|
||||||
string $type = self::UP,
|
Direction $direction = Direction::UP,
|
||||||
bool $oneStep = false,
|
bool $oneStep = false,
|
||||||
bool $forceMigration = false
|
bool $forceMigration = false
|
||||||
): void {
|
): void {
|
||||||
|
@ -52,7 +44,7 @@ class Migrate
|
||||||
$this->getMigrated()
|
$this->getMigrated()
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($type == self::DOWN) {
|
if ($direction === Direction::DOWN) {
|
||||||
$migrations = $migrations->reverse();
|
$migrations = $migrations->reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,19 +54,19 @@ class Migrate
|
||||||
$name = $migration['migration'];
|
$name = $migration['migration'];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
($type == self::UP && isset($migration['id']))
|
($direction === Direction::UP && isset($migration['id']))
|
||||||
|| ($type == self::DOWN && !isset($migration['id']))
|
|| ($direction === Direction::DOWN && !isset($migration['id']))
|
||||||
) {
|
) {
|
||||||
($this->output)('Skipping ' . $name);
|
($this->output)('Skipping ' . $name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
($this->output)('Migrating ' . $name . ' (' . $type . ')');
|
($this->output)('Migrating ' . $name . ' (' . $direction->value . ')');
|
||||||
|
|
||||||
if (isset($migration['path'])) {
|
if (isset($migration['path'])) {
|
||||||
$this->migrate($migration['path'], $name, $type);
|
$this->migrate($migration['path'], $name, $direction);
|
||||||
}
|
}
|
||||||
$this->setMigrated($name, $type);
|
$this->setMigrated($name, $direction);
|
||||||
|
|
||||||
if ($oneStep) {
|
if ($oneStep) {
|
||||||
break;
|
break;
|
||||||
|
@ -145,10 +137,8 @@ class Migrate
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migrate a migration
|
* Migrate a migration
|
||||||
*
|
|
||||||
* @param string $type (up|down)
|
|
||||||
*/
|
*/
|
||||||
protected function migrate(string $file, string $migration, string $type = self::UP): void
|
protected function migrate(string $file, string $migration, Direction $direction = Direction::UP): void
|
||||||
{
|
{
|
||||||
require_once $file;
|
require_once $file;
|
||||||
|
|
||||||
|
@ -156,21 +146,19 @@ class Migrate
|
||||||
/** @var Migration $class */
|
/** @var Migration $class */
|
||||||
$class = $this->app->make('Engelsystem\\Migrations\\' . $className);
|
$class = $this->app->make('Engelsystem\\Migrations\\' . $className);
|
||||||
|
|
||||||
if (method_exists($class, $type)) {
|
if (method_exists($class, $direction->value)) {
|
||||||
$class->{$type}();
|
$class->{$direction->value}();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a migration to migrated
|
* Set a migration to migrated
|
||||||
*
|
|
||||||
* @param string $type (up|down)
|
|
||||||
*/
|
*/
|
||||||
protected function setMigrated(string $migration, string $type = self::UP): void
|
protected function setMigrated(string $migration, Direction $direction = Direction::UP): void
|
||||||
{
|
{
|
||||||
$table = $this->getTableQuery();
|
$table = $this->getTableQuery();
|
||||||
|
|
||||||
if ($type == self::DOWN) {
|
if ($direction === Direction::DOWN) {
|
||||||
$table->where(['migration' => $migration])->delete();
|
$table->where(['migration' => $migration])->delete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Engelsystem;
|
||||||
|
|
||||||
|
enum Environment: string
|
||||||
|
{
|
||||||
|
case PRODUCTION = 'prod';
|
||||||
|
case DEVELOPMENT = 'dev';
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Engelsystem\Exceptions;
|
namespace Engelsystem\Exceptions;
|
||||||
|
|
||||||
use Engelsystem\Container\ServiceProvider;
|
use Engelsystem\Container\ServiceProvider;
|
||||||
|
use Engelsystem\Environment;
|
||||||
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
||||||
use Engelsystem\Exceptions\Handlers\Legacy;
|
use Engelsystem\Exceptions\Handlers\Legacy;
|
||||||
use Engelsystem\Exceptions\Handlers\LegacyDevelopment;
|
use Engelsystem\Exceptions\Handlers\LegacyDevelopment;
|
||||||
|
@ -36,7 +37,7 @@ class ExceptionsServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
$handler = $this->app->make(Legacy::class);
|
$handler = $this->app->make(Legacy::class);
|
||||||
$this->app->instance('error.handler.production', $handler);
|
$this->app->instance('error.handler.production', $handler);
|
||||||
$errorHandler->setHandler(Handler::ENV_PRODUCTION, $handler);
|
$errorHandler->setHandler(Environment::PRODUCTION, $handler);
|
||||||
$this->app->bind(HandlerInterface::class, 'error.handler.production');
|
$this->app->bind(HandlerInterface::class, 'error.handler.production');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ class ExceptionsServiceProvider extends ServiceProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->app->instance('error.handler.development', $handler);
|
$this->app->instance('error.handler.development', $handler);
|
||||||
$errorHandler->setHandler(Handler::ENV_DEVELOPMENT, $handler);
|
$errorHandler->setHandler(Environment::DEVELOPMENT, $handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addLogger(Handler $handler): void
|
protected function addLogger(Handler $handler): void
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Engelsystem\Exceptions;
|
namespace Engelsystem\Exceptions;
|
||||||
|
|
||||||
|
use Engelsystem\Environment;
|
||||||
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
||||||
use Engelsystem\Exceptions\Handlers\Legacy;
|
use Engelsystem\Exceptions\Handlers\Legacy;
|
||||||
use Engelsystem\Http\Request;
|
use Engelsystem\Http\Request;
|
||||||
|
@ -15,18 +16,12 @@ class Handler
|
||||||
|
|
||||||
protected ?Request $request = null;
|
protected ?Request $request = null;
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
public const ENV_PRODUCTION = 'prod';
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
public const ENV_DEVELOPMENT = 'dev';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler constructor.
|
* Handler constructor.
|
||||||
*
|
*
|
||||||
* @param string $environment prod|dev
|
* @param Environment $environment prod|dev
|
||||||
*/
|
*/
|
||||||
public function __construct(protected string $environment = self::ENV_PRODUCTION)
|
public function __construct(protected Environment $environment = Environment::PRODUCTION)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +46,8 @@ class Handler
|
||||||
$this->request = new Request();
|
$this->request = new Request();
|
||||||
}
|
}
|
||||||
|
|
||||||
$handler = isset($this->handler[$this->environment]) ? $this->handler[$this->environment] : new Legacy();
|
$handler = isset($this->handler[$this->environment->value])
|
||||||
|
? $this->handler[$this->environment->value] : new Legacy();
|
||||||
$handler->report($e);
|
$handler->report($e);
|
||||||
ob_start();
|
ob_start();
|
||||||
$handler->render($this->request, $e);
|
$handler->render($this->request, $e);
|
||||||
|
@ -81,12 +77,12 @@ class Handler
|
||||||
die(1);
|
die(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEnvironment(): string
|
public function getEnvironment(): Environment
|
||||||
{
|
{
|
||||||
return $this->environment;
|
return $this->environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEnvironment(string $environment): void
|
public function setEnvironment(Environment $environment): void
|
||||||
{
|
{
|
||||||
$this->environment = $environment;
|
$this->environment = $environment;
|
||||||
}
|
}
|
||||||
|
@ -94,18 +90,18 @@ class Handler
|
||||||
/**
|
/**
|
||||||
* @return HandlerInterface|HandlerInterface[]
|
* @return HandlerInterface|HandlerInterface[]
|
||||||
*/
|
*/
|
||||||
public function getHandler(string $environment = null): HandlerInterface|array
|
public function getHandler(Environment $environment = null): HandlerInterface|array
|
||||||
{
|
{
|
||||||
if (!is_null($environment)) {
|
if (!is_null($environment)) {
|
||||||
return $this->handler[$environment];
|
return $this->handler[$environment->value];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->handler;
|
return $this->handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setHandler(string $environment, HandlerInterface $handler): void
|
public function setHandler(Environment $environment, HandlerInterface $handler): void
|
||||||
{
|
{
|
||||||
$this->handler[$environment] = $handler;
|
$this->handler[$environment->value] = $handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequest(): Request
|
public function getRequest(): Request
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Engelsystem\Helpers;
|
||||||
use Carbon\CarbonTimeZone;
|
use Carbon\CarbonTimeZone;
|
||||||
use Engelsystem\Config\Config;
|
use Engelsystem\Config\Config;
|
||||||
use Engelsystem\Container\ServiceProvider;
|
use Engelsystem\Container\ServiceProvider;
|
||||||
|
use Engelsystem\Environment;
|
||||||
use Engelsystem\Exceptions\Handler;
|
use Engelsystem\Exceptions\Handler;
|
||||||
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ class ConfigureEnvironmentServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/** @var Handler $errorHandler */
|
/** @var Handler $errorHandler */
|
||||||
$errorHandler = $this->app->get('error.handler');
|
$errorHandler = $this->app->get('error.handler');
|
||||||
$errorHandler->setEnvironment(Handler::ENV_DEVELOPMENT);
|
$errorHandler->setEnvironment(Environment::DEVELOPMENT);
|
||||||
$this->app->bind(HandlerInterface::class, 'error.handler.development');
|
$this->app->bind(HandlerInterface::class, 'error.handler.development');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Engelsystem\Models\Shifts;
|
||||||
|
|
||||||
|
enum ShiftSignupStatus: string
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Shift has free places
|
||||||
|
*/
|
||||||
|
case FREE = 'FREE';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift collides with users shifts
|
||||||
|
*/
|
||||||
|
case COLLIDES = 'COLLIDES';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User cannot join because of a restricted angeltype or user is not in the angeltype
|
||||||
|
*/
|
||||||
|
case ANGELTYPE = 'ANGELTYPE';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift is full
|
||||||
|
*/
|
||||||
|
case OCCUPIED = 'OCCUPIED';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User is admin and can do what he wants.
|
||||||
|
*/
|
||||||
|
case ADMIN = 'ADMIN';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift has already ended, no signup
|
||||||
|
*/
|
||||||
|
case SHIFT_ENDED = 'SHIFT_ENDED';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift is not available yet
|
||||||
|
*/
|
||||||
|
case NOT_YET = 'NOT_YET';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User is already signed up
|
||||||
|
*/
|
||||||
|
case SIGNED_UP = 'SIGNED_UP';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User has to be arrived
|
||||||
|
*/
|
||||||
|
case NOT_ARRIVED = 'NOT_ARRIVED';
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ namespace Engelsystem\Test\Unit\Database\Migration;
|
||||||
|
|
||||||
use Engelsystem\Application;
|
use Engelsystem\Application;
|
||||||
use Engelsystem\Database\Migration\Migrate;
|
use Engelsystem\Database\Migration\Migrate;
|
||||||
|
use Engelsystem\Database\Migration\Direction;
|
||||||
use Engelsystem\Test\Unit\TestCase;
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Database\Capsule\Manager as CapsuleManager;
|
use Illuminate\Database\Capsule\Manager as CapsuleManager;
|
||||||
|
@ -61,34 +62,34 @@ class MigrateTest extends TestCase
|
||||||
$migration->expects($this->atLeastOnce())
|
$migration->expects($this->atLeastOnce())
|
||||||
->method('migrate')
|
->method('migrate')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
['foo/9876_03_22_210000_random_hack.php', '9876_03_22_210000_random_hack', Migrate::UP],
|
['foo/9876_03_22_210000_random_hack.php', '9876_03_22_210000_random_hack', Direction::UP],
|
||||||
['foo/9999_99_99_999999_another_foo.php', '9999_99_99_999999_another_foo', Migrate::UP],
|
['foo/9999_99_99_999999_another_foo.php', '9999_99_99_999999_another_foo', Direction::UP],
|
||||||
['foo/9876_03_22_210000_random_hack.php', '9876_03_22_210000_random_hack', Migrate::UP],
|
['foo/9876_03_22_210000_random_hack.php', '9876_03_22_210000_random_hack', Direction::UP],
|
||||||
['foo/9999_99_99_999999_another_foo.php', '9999_99_99_999999_another_foo', Migrate::UP],
|
['foo/9999_99_99_999999_another_foo.php', '9999_99_99_999999_another_foo', Direction::UP],
|
||||||
['foo/9876_03_22_210000_random_hack.php', '9876_03_22_210000_random_hack', Migrate::UP],
|
['foo/9876_03_22_210000_random_hack.php', '9876_03_22_210000_random_hack', Direction::UP],
|
||||||
['foo/4567_11_01_000000_do_stuff.php', '4567_11_01_000000_do_stuff', Migrate::DOWN]
|
['foo/4567_11_01_000000_do_stuff.php', '4567_11_01_000000_do_stuff', Direction::DOWN]
|
||||||
);
|
);
|
||||||
$migration->expects($this->atLeastOnce())
|
$migration->expects($this->atLeastOnce())
|
||||||
->method('setMigrated')
|
->method('setMigrated')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
['9876_03_22_210000_random_hack', Migrate::UP],
|
['9876_03_22_210000_random_hack', Direction::UP],
|
||||||
['9999_99_99_999999_another_foo', Migrate::UP],
|
['9999_99_99_999999_another_foo', Direction::UP],
|
||||||
['9876_03_22_210000_random_hack', Migrate::UP],
|
['9876_03_22_210000_random_hack', Direction::UP],
|
||||||
['9999_99_99_999999_another_foo', Migrate::UP],
|
['9999_99_99_999999_another_foo', Direction::UP],
|
||||||
['9876_03_22_210000_random_hack', Migrate::UP],
|
['9876_03_22_210000_random_hack', Direction::UP],
|
||||||
['4567_11_01_000000_do_stuff', Migrate::DOWN]
|
['4567_11_01_000000_do_stuff', Direction::DOWN]
|
||||||
);
|
);
|
||||||
$this->setExpects($migration, 'lockTable', null, null, $this->atLeastOnce());
|
$this->setExpects($migration, 'lockTable', null, null, $this->atLeastOnce());
|
||||||
$this->setExpects($migration, 'unlockTable', null, null, $this->atLeastOnce());
|
$this->setExpects($migration, 'unlockTable', null, null, $this->atLeastOnce());
|
||||||
|
|
||||||
$migration->run('foo', Migrate::UP);
|
$migration->run('foo', Direction::UP);
|
||||||
|
|
||||||
$messages = [];
|
$messages = [];
|
||||||
$migration->setOutput(function ($text) use (&$messages): void {
|
$migration->setOutput(function ($text) use (&$messages): void {
|
||||||
$messages[] = $text;
|
$messages[] = $text;
|
||||||
});
|
});
|
||||||
|
|
||||||
$migration->run('foo', Migrate::UP);
|
$migration->run('foo', Direction::UP);
|
||||||
|
|
||||||
$this->assertCount(4, $messages);
|
$this->assertCount(4, $messages);
|
||||||
foreach (
|
foreach (
|
||||||
|
@ -113,10 +114,10 @@ class MigrateTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
$messages = [];
|
$messages = [];
|
||||||
$migration->run('foo', Migrate::UP, true);
|
$migration->run('foo', Direction::UP, true);
|
||||||
$this->assertCount(3, $messages);
|
$this->assertCount(3, $messages);
|
||||||
|
|
||||||
$migration->run('foo', Migrate::DOWN, true);
|
$migration->run('foo', Direction::DOWN, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -192,7 +193,7 @@ class MigrateTest extends TestCase
|
||||||
$messages[] = $msg;
|
$messages[] = $msg;
|
||||||
});
|
});
|
||||||
|
|
||||||
$migration->run(__DIR__ . '/Stub', Migrate::UP);
|
$migration->run(__DIR__ . '/Stub', Direction::UP);
|
||||||
|
|
||||||
$this->assertTrue($schema->hasTable('migrations'));
|
$this->assertTrue($schema->hasTable('migrations'));
|
||||||
|
|
||||||
|
@ -206,12 +207,12 @@ class MigrateTest extends TestCase
|
||||||
|
|
||||||
$this->assertTrue($schema->hasTable('lorem_ipsum'));
|
$this->assertTrue($schema->hasTable('lorem_ipsum'));
|
||||||
|
|
||||||
$migration->run(__DIR__ . '/Stub', Migrate::DOWN, true);
|
$migration->run(__DIR__ . '/Stub', Direction::DOWN, true);
|
||||||
|
|
||||||
$migrations = $db->table('migrations')->get();
|
$migrations = $db->table('migrations')->get();
|
||||||
$this->assertCount(2, $migrations);
|
$this->assertCount(2, $migrations);
|
||||||
|
|
||||||
$migration->run(__DIR__ . '/Stub', Migrate::DOWN);
|
$migration->run(__DIR__ . '/Stub', Direction::DOWN);
|
||||||
|
|
||||||
$migrations = $db->table('migrations')->get();
|
$migrations = $db->table('migrations')->get();
|
||||||
$this->assertCount(0, $migrations);
|
$this->assertCount(0, $migrations);
|
||||||
|
@ -220,6 +221,6 @@ class MigrateTest extends TestCase
|
||||||
|
|
||||||
$db->table('migrations')->insert(['migration' => 'lock']);
|
$db->table('migrations')->insert(['migration' => 'lock']);
|
||||||
$this->expectException(Exception::class);
|
$this->expectException(Exception::class);
|
||||||
$migration->run(__DIR__ . '/Stub', Migrate::UP);
|
$migration->run(__DIR__ . '/Stub', Direction::UP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Engelsystem\Test\Unit\Exceptions;
|
namespace Engelsystem\Test\Unit\Exceptions;
|
||||||
|
|
||||||
|
use Engelsystem\Environment;
|
||||||
use Engelsystem\Exceptions\ExceptionsServiceProvider;
|
use Engelsystem\Exceptions\ExceptionsServiceProvider;
|
||||||
use Engelsystem\Exceptions\Handler;
|
use Engelsystem\Exceptions\Handler;
|
||||||
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
||||||
|
@ -69,8 +70,8 @@ class ExceptionsServiceProviderTest extends ServiceProviderTest
|
||||||
$handler->expects($this->exactly(2))
|
$handler->expects($this->exactly(2))
|
||||||
->method('setHandler')
|
->method('setHandler')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
[Handler::ENV_PRODUCTION, $legacyHandler],
|
[Environment::PRODUCTION, $legacyHandler],
|
||||||
[Handler::ENV_DEVELOPMENT, $whoopsHandler]
|
[Environment::DEVELOPMENT, $whoopsHandler]
|
||||||
);
|
);
|
||||||
|
|
||||||
$serviceProvider = new ExceptionsServiceProvider($app);
|
$serviceProvider = new ExceptionsServiceProvider($app);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Engelsystem\Test\Unit\Exceptions;
|
namespace Engelsystem\Test\Unit\Exceptions;
|
||||||
|
|
||||||
|
use Engelsystem\Environment;
|
||||||
use Engelsystem\Exceptions\Handler;
|
use Engelsystem\Exceptions\Handler;
|
||||||
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
||||||
use Engelsystem\Http\Request;
|
use Engelsystem\Http\Request;
|
||||||
|
@ -20,10 +21,10 @@ class HandlerTest extends TestCase
|
||||||
/** @var Handler|MockObject $handler */
|
/** @var Handler|MockObject $handler */
|
||||||
$handler = new Handler();
|
$handler = new Handler();
|
||||||
$this->assertInstanceOf(Handler::class, $handler);
|
$this->assertInstanceOf(Handler::class, $handler);
|
||||||
$this->assertEquals(Handler::ENV_PRODUCTION, $handler->getEnvironment());
|
$this->assertEquals(Environment::PRODUCTION, $handler->getEnvironment());
|
||||||
|
|
||||||
$anotherHandler = new Handler(Handler::ENV_DEVELOPMENT);
|
$anotherHandler = new Handler(Environment::DEVELOPMENT);
|
||||||
$this->assertEquals(Handler::ENV_DEVELOPMENT, $anotherHandler->getEnvironment());
|
$this->assertEquals(Environment::DEVELOPMENT, $anotherHandler->getEnvironment());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +71,7 @@ class HandlerTest extends TestCase
|
||||||
$handler->expects($this->once())
|
$handler->expects($this->once())
|
||||||
->method('terminateApplicationImmediately');
|
->method('terminateApplicationImmediately');
|
||||||
|
|
||||||
$handler->setHandler(Handler::ENV_PRODUCTION, $handlerMock);
|
$handler->setHandler(Environment::PRODUCTION, $handlerMock);
|
||||||
|
|
||||||
$this->expectOutputString($errorMessage);
|
$this->expectOutputString($errorMessage);
|
||||||
$handler->exceptionHandler($exception);
|
$handler->exceptionHandler($exception);
|
||||||
|
@ -106,11 +107,11 @@ class HandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
$handler = new Handler();
|
$handler = new Handler();
|
||||||
|
|
||||||
$handler->setEnvironment(Handler::ENV_DEVELOPMENT);
|
$handler->setEnvironment(Environment::DEVELOPMENT);
|
||||||
$this->assertEquals(Handler::ENV_DEVELOPMENT, $handler->getEnvironment());
|
$this->assertEquals(Environment::DEVELOPMENT, $handler->getEnvironment());
|
||||||
|
|
||||||
$handler->setEnvironment(Handler::ENV_PRODUCTION);
|
$handler->setEnvironment(Environment::PRODUCTION);
|
||||||
$this->assertEquals(Handler::ENV_PRODUCTION, $handler->getEnvironment());
|
$this->assertEquals(Environment::PRODUCTION, $handler->getEnvironment());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,10 +126,10 @@ class HandlerTest extends TestCase
|
||||||
/** @var HandlerInterface|MockObject $prodHandler */
|
/** @var HandlerInterface|MockObject $prodHandler */
|
||||||
$prodHandler = $this->getMockForAbstractClass(HandlerInterface::class);
|
$prodHandler = $this->getMockForAbstractClass(HandlerInterface::class);
|
||||||
|
|
||||||
$handler->setHandler(Handler::ENV_DEVELOPMENT, $devHandler);
|
$handler->setHandler(Environment::DEVELOPMENT, $devHandler);
|
||||||
$handler->setHandler(Handler::ENV_PRODUCTION, $prodHandler);
|
$handler->setHandler(Environment::PRODUCTION, $prodHandler);
|
||||||
$this->assertEquals($devHandler, $handler->getHandler(Handler::ENV_DEVELOPMENT));
|
$this->assertEquals($devHandler, $handler->getHandler(Environment::DEVELOPMENT));
|
||||||
$this->assertEquals($prodHandler, $handler->getHandler(Handler::ENV_PRODUCTION));
|
$this->assertEquals($prodHandler, $handler->getHandler(Environment::PRODUCTION));
|
||||||
$this->assertCount(2, $handler->getHandler());
|
$this->assertCount(2, $handler->getHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Engelsystem\Test\Unit\Helpers;
|
||||||
|
|
||||||
use Carbon\CarbonTimeZone;
|
use Carbon\CarbonTimeZone;
|
||||||
use Engelsystem\Config\Config;
|
use Engelsystem\Config\Config;
|
||||||
|
use Engelsystem\Environment;
|
||||||
use Engelsystem\Exceptions\Handler;
|
use Engelsystem\Exceptions\Handler;
|
||||||
use Engelsystem\Helpers\ConfigureEnvironmentServiceProvider;
|
use Engelsystem\Helpers\ConfigureEnvironmentServiceProvider;
|
||||||
use Engelsystem\Test\Unit\ServiceProviderTest;
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
||||||
|
@ -42,10 +43,10 @@ class ConfigureEnvironmentServiceProviderTest extends ServiceProviderTest
|
||||||
->with(E_ALL);
|
->with(E_ALL);
|
||||||
|
|
||||||
$serviceProvider->register();
|
$serviceProvider->register();
|
||||||
$this->assertNotEquals(Handler::ENV_DEVELOPMENT, $handler->getEnvironment());
|
$this->assertNotEquals(Environment::DEVELOPMENT, $handler->getEnvironment());
|
||||||
|
|
||||||
$config->set('environment', 'development');
|
$config->set('environment', 'development');
|
||||||
$serviceProvider->register();
|
$serviceProvider->register();
|
||||||
$this->assertEquals(Handler::ENV_DEVELOPMENT, $handler->getEnvironment());
|
$this->assertEquals(Environment::DEVELOPMENT, $handler->getEnvironment());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue