chore: update CodeIgniter to latest dev version after 4.1.6

This commit is contained in:
Yassine Doghri 2022-01-04 15:40:27 +00:00
parent de19317138
commit 1fc3da139e
29 changed files with 276 additions and 336 deletions

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Config;
use CodeIgniter\Config\BaseConfig;
class CURLRequest extends BaseConfig
{
/**
* --------------------------------------------------------------------------
* CURLRequest Share Options
* --------------------------------------------------------------------------
*
* Whether share options between requests or not.
*
* If true, all the options won't be reset between requests.
* It may cause an error request with unnecessary headers.
*/
public bool $shareOptions = true;
}

View File

@ -89,6 +89,18 @@ class Cache extends BaseConfig
*/ */
public int $ttl = 60; public int $ttl = 60;
/**
* --------------------------------------------------------------------------
* Reserved Characters
* --------------------------------------------------------------------------
*
* A string of reserved characters that will not be allowed in keys or tags.
* Strings that violate this restriction will cause handlers to throw.
* Default: {}()/\@:
* Note: The default set is required for PSR-6 compliance.
*/
public string $reservedCharacters = '{}()/\@:';
/** /**
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* File settings * File settings

View File

@ -6,6 +6,7 @@ namespace Config;
use App\Entities\Actor; use App\Entities\Actor;
use App\Entities\Post; use App\Entities\Post;
use App\Models\EpisodeModel;
use CodeIgniter\Events\Events; use CodeIgniter\Events\Events;
use CodeIgniter\Exceptions\FrameworkException; use CodeIgniter\Exceptions\FrameworkException;
use Modules\Auth\Entities\User; use Modules\Auth\Entities\User;
@ -131,11 +132,11 @@ Events::on('on_post_add', function ($post): void {
if ($post->episode_id !== null) { if ($post->episode_id !== null) {
if ($isReply) { if ($isReply) {
model('EpisodeModel', false) model(EpisodeModel::class, false)
->where('id', $post->episode_id) ->where('id', $post->episode_id)
->increment('comments_count'); ->increment('comments_count');
} else { } else {
model('EpisodeModel', false) model(EpisodeModel::class, false)
->where('id', $post->episode_id) ->where('id', $post->episode_id)
->increment('posts_count'); ->increment('posts_count');
} }
@ -160,7 +161,7 @@ Events::on('on_post_remove', function ($post): void {
} }
if ($episodeId = $post->episode_id) { if ($episodeId = $post->episode_id) {
model('EpisodeModel', false) model(EpisodeModel::class, false)
->where('id', $episodeId) ->where('id', $episodeId)
->decrement('posts_count'); ->decrement('posts_count');
} }

27
app/Config/Feature.php Normal file
View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Config;
use CodeIgniter\Config\BaseConfig;
/**
* Enable/disable backward compatibility breaking features.
*/
class Feature extends BaseConfig
{
/**
* Enable multiple filters for a route or not
*
* If you enable this:
* - CodeIgniter\CodeIgniter::handleRequest() uses:
* - CodeIgniter\Filters\Filters::enableFilters(), instead of enableFilter()
* - CodeIgniter\CodeIgniter::tryToRouteIt() uses:
* - CodeIgniter\Router\Router::getFilters(), instead of getFilter()
* - CodeIgniter\Router\Router::handle() uses:
* - property $filtersInfo, instead of $filterInfo
* - CodeIgniter\Router\RouteCollection::getFiltersForRoute(), instead of getFilterForRoute()
*/
public bool $multipleFilters = false;
}

View File

@ -8,6 +8,8 @@ use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Filters\CSRF; use CodeIgniter\Filters\CSRF;
use CodeIgniter\Filters\DebugToolbar; use CodeIgniter\Filters\DebugToolbar;
use CodeIgniter\Filters\Honeypot; use CodeIgniter\Filters\Honeypot;
use CodeIgniter\Filters\InvalidChars;
use CodeIgniter\Filters\SecureHeaders;
use Modules\Auth\Filters\PermissionFilter; use Modules\Auth\Filters\PermissionFilter;
use Modules\Fediverse\Filters\FediverseFilter; use Modules\Fediverse\Filters\FediverseFilter;
use Myth\Auth\Filters\LoginFilter; use Myth\Auth\Filters\LoginFilter;
@ -24,6 +26,8 @@ class Filters extends BaseConfig
'csrf' => CSRF::class, 'csrf' => CSRF::class,
'toolbar' => DebugToolbar::class, 'toolbar' => DebugToolbar::class,
'honeypot' => Honeypot::class, 'honeypot' => Honeypot::class,
'invalidchars' => InvalidChars::class,
'secureheaders' => SecureHeaders::class,
'login' => LoginFilter::class, 'login' => LoginFilter::class,
'role' => RoleFilter::class, 'role' => RoleFilter::class,
'permission' => PermissionFilter::class, 'permission' => PermissionFilter::class,
@ -39,10 +43,13 @@ class Filters extends BaseConfig
'before' => [ 'before' => [
// 'honeypot', // 'honeypot',
// 'csrf', // 'csrf',
// 'invalidchars',
], ],
'after' => [ 'after' => [
'toolbar', 'toolbar',
// 'honeypot', // 'honeypot',
// 'honeypot',
// 'secureheaders',
], ],
]; ];

View File

@ -30,6 +30,7 @@ class Generators extends BaseConfig
public array $views = [ public array $views = [
'make:command' => 'make:command' =>
'CodeIgniter\Commands\Generators\Views\command.tpl.php', 'CodeIgniter\Commands\Generators\Views\command.tpl.php',
'make:config' => 'CodeIgniter\Commands\Generators\Views\config.tpl.php',
'make:controller' => 'make:controller' =>
'CodeIgniter\Commands\Generators\Views\controller.tpl.php', 'CodeIgniter\Commands\Generators\Views\controller.tpl.php',
'make:entity' => 'CodeIgniter\Commands\Generators\Views\entity.tpl.php', 'make:entity' => 'CodeIgniter\Commands\Generators\Views\entity.tpl.php',

View File

@ -309,11 +309,11 @@ class Mimes
* @param string $proposedExtension - default extension (in case there is more than one with the same mime type) * @param string $proposedExtension - default extension (in case there is more than one with the same mime type)
* @return string|null The extension determined, or null if unable to match. * @return string|null The extension determined, or null if unable to match.
*/ */
public static function guessExtensionFromType(string $type, string $proposedExtension = ''): ?string public static function guessExtensionFromType(string $type, string $proposedExtension = null): ?string
{ {
$type = trim(strtolower($type), '. '); $type = trim(strtolower($type), '. ');
$proposedExtension = trim(strtolower($proposedExtension)); $proposedExtension = trim(strtolower($proposedExtension ?? ''));
if ($proposedExtension !== '') { if ($proposedExtension !== '') {
if (array_key_exists($proposedExtension, static::$mimes) && in_array( if (array_key_exists($proposedExtension, static::$mimes) && in_array(

17
app/Config/Publisher.php Normal file
View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Config;
use CodeIgniter\Config\Publisher as BasePublisher;
/**
* Publisher Configuration
*
* Defines basic security restrictions for the Publisher class to prevent abuse by injecting malicious files into a
* project.
*/
class Publisher extends BasePublisher
{
}

View File

@ -8,12 +8,32 @@ use CodeIgniter\Config\BaseConfig;
class Security extends BaseConfig class Security extends BaseConfig
{ {
/**
* --------------------------------------------------------------------------
* CSRF Protection Method
* --------------------------------------------------------------------------
*
* Protection Method for Cross Site Request Forgery protection.
*
* @var 'cookie'|'session'
*/
public string $csrfProtection = 'cookie';
/**
* --------------------------------------------------------------------------
* CSRF Token Randomization
* --------------------------------------------------------------------------
*
* Randomize the CSRF Token for added security.
*/
public bool $tokenRandomize = false;
/** /**
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* CSRF Token Name * CSRF Token Name
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* *
* Token name for Cross Site Request Forgery protection cookie. * Token name for Cross Site Request Forgery protection.
*/ */
public string $tokenName = 'csrf_test_name'; public string $tokenName = 'csrf_test_name';
@ -22,7 +42,7 @@ class Security extends BaseConfig
* CSRF Header Name * CSRF Header Name
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* *
* Token name for Cross Site Request Forgery protection cookie. * Header name for Cross Site Request Forgery protection.
*/ */
public string $headerName = 'X-CSRF-TOKEN'; public string $headerName = 'X-CSRF-TOKEN';
@ -31,7 +51,7 @@ class Security extends BaseConfig
* CSRF Cookie Name * CSRF Cookie Name
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* *
* Cookie name for Cross Site Request Forgery protection cookie. * Cookie name for Cross Site Request Forgery protection.
*/ */
public string $cookieName = 'csrf_cookie_name'; public string $cookieName = 'csrf_cookie_name';
@ -51,7 +71,7 @@ class Security extends BaseConfig
* CSRF Regenerate * CSRF Regenerate
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* *
* Regenerate CSRF Token on every request. * Regenerate CSRF Token on every submission.
*/ */
public bool $regenerate = true; public bool $regenerate = true;

View File

@ -37,7 +37,8 @@ class Toolbar extends BaseConfig
*/ */
public array $collectors = [ public array $collectors = [
Timers::class, Timers::class,
Database::class, // TODO: uncomment when fixed: https://github.com/codeigniter4/CodeIgniter4/issues/5539
// Database::class,
Logs::class, Logs::class,
Views::class, Views::class,
// Cache::class, // Cache::class,
@ -46,6 +47,16 @@ class Toolbar extends BaseConfig
Events::class, Events::class,
]; ];
/**
* --------------------------------------------------------------------------
* Collect Var Data
* --------------------------------------------------------------------------
*
* If set to false var data from the views will not be colleted. Useful to
* avoid high memory usage when there are lots of data passed to the view.
*/
public bool $collectVarData = true;
/** /**
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* Max History * Max History

View File

@ -16,6 +16,7 @@ use App\Entities\Podcast;
use App\Libraries\CommentObject; use App\Libraries\CommentObject;
use App\Models\EpisodeCommentModel; use App\Models\EpisodeCommentModel;
use App\Models\EpisodeModel; use App\Models\EpisodeModel;
use App\Models\LikeModel;
use App\Models\PodcastModel; use App\Models\PodcastModel;
use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
@ -135,7 +136,7 @@ class EpisodeCommentController extends BaseController
/** /**
* get comment replies * get comment replies
*/ */
$commentReplies = model('CommentModel', false) $commentReplies = model(EpisodeCommentModel::class, false)
->where('in_reply_to_id', service('uuid')->fromString($this->comment->id)->getBytes()) ->where('in_reply_to_id', service('uuid')->fromString($this->comment->id)->getBytes())
->orderBy('created_at', 'ASC'); ->orderBy('created_at', 'ASC');
@ -167,7 +168,7 @@ class EpisodeCommentController extends BaseController
public function attemptLike(): RedirectResponse public function attemptLike(): RedirectResponse
{ {
model('LikeModel') model(LikeModel::class)
->toggleLike(interact_as_actor(), $this->comment); ->toggleLike(interact_as_actor(), $this->comment);
return redirect()->back(); return redirect()->back();
@ -175,7 +176,7 @@ class EpisodeCommentController extends BaseController
public function attemptReply(): RedirectResponse public function attemptReply(): RedirectResponse
{ {
model('LikeModel') model(LikeModel::class)
->toggleLike(interact_as_actor(), $this->comment); ->toggleLike(interact_as_actor(), $this->comment);
return redirect()->back(); return redirect()->back();

View File

@ -16,6 +16,7 @@ use App\Libraries\NoteObject;
use App\Libraries\PodcastEpisode; use App\Libraries\PodcastEpisode;
use App\Models\EpisodeModel; use App\Models\EpisodeModel;
use App\Models\PodcastModel; use App\Models\PodcastModel;
use App\Models\PostModel;
use CodeIgniter\Database\BaseBuilder; use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\Response; use CodeIgniter\HTTP\Response;
@ -259,7 +260,7 @@ class EpisodeController extends BaseController
/** /**
* get comments: aggregated replies from posts referring to the episode * get comments: aggregated replies from posts referring to the episode
*/ */
$episodeComments = model('PostModel') $episodeComments = model(PostModel::class)
->whereIn('in_reply_to_id', function (BaseBuilder $builder): BaseBuilder { ->whereIn('in_reply_to_id', function (BaseBuilder $builder): BaseBuilder {
return $builder->select('id') return $builder->select('id')
->from(config('Fediverse')->tablesPrefix . 'posts') ->from(config('Fediverse')->tablesPrefix . 'posts')

View File

@ -275,11 +275,11 @@ class PodcastController extends BaseController
{ {
if ($this->podcast->type === 'serial') { if ($this->podcast->type === 'serial') {
// podcast is serial // podcast is serial
$episodes = model('EpisodeModel') $episodes = model(EpisodeModel::class)
->where('`published_at` <= NOW()', null, false) ->where('`published_at` <= NOW()', null, false)
->orderBy('season_number DESC, number ASC'); ->orderBy('season_number DESC, number ASC');
} else { } else {
$episodes = model('EpisodeModel') $episodes = model(EpisodeModel::class)
->where('`published_at` <= NOW()', null, false) ->where('`published_at` <= NOW()', null, false)
->orderBy('published_at', 'DESC'); ->orderBy('published_at', 'DESC');
} }

View File

@ -23,6 +23,7 @@ use CodeIgniter\I18n\Time;
use Modules\Analytics\AnalyticsTrait; use Modules\Analytics\AnalyticsTrait;
use Modules\Fediverse\Controllers\PostController as FediversePostController; use Modules\Fediverse\Controllers\PostController as FediversePostController;
use Modules\Fediverse\Entities\Post as FediversePost; use Modules\Fediverse\Entities\Post as FediversePost;
use Modules\Fediverse\Models\FavouriteModel;
class PostController extends FediversePostController class PostController extends FediversePostController
{ {
@ -184,7 +185,7 @@ class PostController extends FediversePostController
public function attemptFavourite(): RedirectResponse public function attemptFavourite(): RedirectResponse
{ {
model('FavouriteModel')->toggleFavourite(interact_as_actor(), $this->post); model(FavouriteModel::class)->toggleFavourite(interact_as_actor(), $this->post);
return redirect()->back(); return redirect()->back();
} }

View File

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace App\Entities; namespace App\Entities;
use App\Models\ActorModel;
use App\Models\EpisodeCommentModel; use App\Models\EpisodeCommentModel;
use App\Models\EpisodeModel; use App\Models\EpisodeModel;
use CodeIgniter\I18n\Time; use CodeIgniter\I18n\Time;
@ -94,7 +95,7 @@ class EpisodeComment extends UuidEntity
} }
if ($this->actor === null) { if ($this->actor === null) {
$this->actor = model('ActorModel', false) $this->actor = model(ActorModel::class, false)
->getActorById($this->actor_id); ->getActorById($this->actor_id);
} }
@ -129,7 +130,7 @@ class EpisodeComment extends UuidEntity
} }
if ($this->reply_to_comment === null) { if ($this->reply_to_comment === null) {
$this->reply_to_comment = model('EpisodeCommentModel', false) $this->reply_to_comment = model(EpisodeCommentModel::class, false)
->getCommentById($this->in_reply_to_id); ->getCommentById($this->in_reply_to_id);
} }

View File

@ -12,6 +12,7 @@ namespace App\Entities;
use App\Entities\Media\Image; use App\Entities\Media\Image;
use App\Libraries\SimpleRSSElement; use App\Libraries\SimpleRSSElement;
use App\Models\ActorModel;
use App\Models\CategoryModel; use App\Models\CategoryModel;
use App\Models\EpisodeModel; use App\Models\EpisodeModel;
use App\Models\MediaModel; use App\Models\MediaModel;
@ -188,7 +189,7 @@ class Podcast extends Entity
} }
if ($this->actor === null) { if ($this->actor === null) {
$this->actor = model('ActorModel') $this->actor = model(ActorModel::class)
->getActorById($this->actor_id); ->getActorById($this->actor_id);
} }

View File

@ -8,6 +8,7 @@ declare(strict_types=1);
* @link https://castopod.org/ * @link https://castopod.org/
*/ */
use App\Models\ActorModel;
use CodeIgniter\Database\Exceptions\DataException; use CodeIgniter\Database\Exceptions\DataException;
use Modules\Auth\Entities\User; use Modules\Auth\Entities\User;
use Modules\Fediverse\Entities\Actor; use Modules\Fediverse\Entities\Actor;
@ -74,7 +75,7 @@ if (! function_exists('interact_as_actor')) {
$session = session(); $session = session();
if ($session->has('interact_as_actor_id')) { if ($session->has('interact_as_actor_id')) {
return model('ActorModel')->getActorById($session->get('interact_as_actor_id')); return model(ActorModel::class)->getActorById($session->get('interact_as_actor_id'));
} }
return false; return false;

View File

@ -15,6 +15,7 @@ use App\Libraries\CommentObject;
use CodeIgniter\Database\BaseBuilder; use CodeIgniter\Database\BaseBuilder;
use Michalsn\Uuid\UuidModel; use Michalsn\Uuid\UuidModel;
use Modules\Fediverse\Activities\CreateActivity; use Modules\Fediverse\Activities\CreateActivity;
use Modules\Fediverse\Models\ActivityModel;
class EpisodeCommentModel extends UuidModel class EpisodeCommentModel extends UuidModel
{ {
@ -100,7 +101,7 @@ class EpisodeCommentModel extends UuidModel
->set('actor', $comment->actor->uri) ->set('actor', $comment->actor->uri)
->set('object', new CommentObject($comment)); ->set('object', new CommentObject($comment));
$activityId = model('ActivityModel', false) $activityId = model(ActivityModel::class, false)
->newActivity( ->newActivity(
'Create', 'Create',
$comment->actor_id, $comment->actor_id,
@ -113,7 +114,7 @@ class EpisodeCommentModel extends UuidModel
$createActivity->set('id', url_to('activity', $comment->actor->username, $activityId)); $createActivity->set('id', url_to('activity', $comment->actor->username, $activityId));
model('ActivityModel', false) model(ActivityModel::class, false)
->update($activityId, [ ->update($activityId, [
'payload' => $createActivity->toJSON(), 'payload' => $createActivity->toJSON(),
]); ]);
@ -188,9 +189,9 @@ class EpisodeCommentModel extends UuidModel
$data['data']['id'] = $uuid4->toString(); $data['data']['id'] = $uuid4->toString();
if (! isset($data['data']['uri'])) { if (! isset($data['data']['uri'])) {
$actor = model('ActorModel', false) $actor = model(ActorModel::class, false)
->getActorById((int) $data['data']['actor_id']); ->getActorById((int) $data['data']['actor_id']);
$episode = model('EpisodeModel', false) $episode = model(EpisodeModel::class, false)
->find((int) $data['data']['episode_id']); ->find((int) $data['data']['episode_id']);
$data['data']['uri'] = url_to('episode-comment', $actor->username, $episode->slug, $uuid4->toString()); $data['data']['uri'] = url_to('episode-comment', $actor->username, $episode->slug, $uuid4->toString());

View File

@ -16,6 +16,7 @@ use Michalsn\Uuid\UuidModel;
use Modules\Fediverse\Activities\LikeActivity; use Modules\Fediverse\Activities\LikeActivity;
use Modules\Fediverse\Activities\UndoActivity; use Modules\Fediverse\Activities\UndoActivity;
use Modules\Fediverse\Entities\Actor; use Modules\Fediverse\Entities\Actor;
use Modules\Fediverse\Models\ActivityModel;
class LikeModel extends UuidModel class LikeModel extends UuidModel
{ {
@ -64,7 +65,7 @@ class LikeModel extends UuidModel
$likeActivity->set('actor', $actor->uri) $likeActivity->set('actor', $actor->uri)
->set('object', $comment->uri); ->set('object', $comment->uri);
$activityId = model('ActivityModel') $activityId = model(ActivityModel::class)
->newActivity( ->newActivity(
'Like', 'Like',
$actor->id, $actor->id,
@ -77,7 +78,7 @@ class LikeModel extends UuidModel
$likeActivity->set('id', url_to('activity', $actor->username, $activityId)); $likeActivity->set('id', url_to('activity', $actor->username, $activityId));
model('ActivityModel') model(ActivityModel::class)
->update($activityId, [ ->update($activityId, [
'payload' => $likeActivity->toJSON(), 'payload' => $likeActivity->toJSON(),
]); ]);
@ -105,7 +106,7 @@ class LikeModel extends UuidModel
if ($registerActivity) { if ($registerActivity) {
$undoActivity = new UndoActivity(); $undoActivity = new UndoActivity();
// FIXME: get like activity associated with the deleted like // FIXME: get like activity associated with the deleted like
$activity = model('ActivityModel') $activity = model(ActivityModel::class)
->where([ ->where([
'type' => 'Like', 'type' => 'Like',
'actor_id' => $actor->id, 'actor_id' => $actor->id,
@ -122,7 +123,7 @@ class LikeModel extends UuidModel
->set('actor', $actor->uri) ->set('actor', $actor->uri)
->set('object', $likeActivity); ->set('object', $likeActivity);
$activityId = model('ActivityModel') $activityId = model(ActivityModel::class)
->newActivity( ->newActivity(
'Undo', 'Undo',
$actor->id, $actor->id,
@ -135,7 +136,7 @@ class LikeModel extends UuidModel
$undoActivity->set('id', url_to('activity', $actor->username, $activityId)); $undoActivity->set('id', url_to('activity', $actor->username, $activityId));
model('ActivityModel') model(ActivityModel::class)
->update($activityId, [ ->update($activityId, [
'payload' => $undoActivity->toJSON(), 'payload' => $undoActivity->toJSON(),
]); ]);

View File

@ -201,7 +201,7 @@ $errorId = uniqid('error', true); ?>
<tbody> <tbody>
<tr> <tr>
<td style="width: 10em">Path</td> <td style="width: 10em">Path</td>
<td><?= esc($request->uri) ?></td> <td><?= esc($request->getUri()) ?></td>
</tr> </tr>
<tr> <tr>
<td>HTTP Method</td> <td>HTTP Method</td>

96
builds
View File

@ -1,5 +1,6 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
define('LATEST_RELEASE', '^4.0'); define('LATEST_RELEASE', '^4.0');
define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4'); define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4');
@ -14,99 +15,81 @@ define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4');
*/ */
// Determine the requested stability // Determine the requested stability
if (empty($argv[1]) || !in_array($argv[1], ['release', 'development'])) { if (empty($argv[1]) || ! in_array($argv[1], ['release', 'development'], true)) {
echo 'Usage: php builds [release|development]' . PHP_EOL; echo 'Usage: php builds [release|development]' . PHP_EOL;
exit();
exit;
} }
$dev = $argv[1] == 'development'; $dev = $argv[1] === 'development';
$modified = []; $modified = [];
/* Locate each file and update it for the requested stability */ // Locate each file and update it for the requested stability
// Composer.json
$file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json'; $file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json';
if (is_file($file)) { if (is_file($file)) {
// Make sure we can read it $contents = file_get_contents($file);
if ($contents = file_get_contents($file)) {
if ($array = json_decode($contents, true)) { if ((string) $contents !== '') {
// Development $array = json_decode($contents, true);
if (is_array($array)) {
if ($dev) { if ($dev) {
// Set 'minimum-stability'
$array['minimum-stability'] = 'dev'; $array['minimum-stability'] = 'dev';
$array['prefer-stable'] = true; $array['prefer-stable'] = true;
$array['repositories'] = $array['repositories'] ?? [];
// Make sure the repo is configured
if (!isset($array['repositories'])) {
$array['repositories'] = [];
}
// Check for the CodeIgniter repo
$found = false; $found = false;
foreach ($array['repositories'] as $repository) { foreach ($array['repositories'] as $repository) {
if ($repository['url'] == GITHUB_URL) { if ($repository['url'] === GITHUB_URL) {
$found = true; $found = true;
break; break;
} }
} }
// Add the repo if it was not found if (! $found) {
if (!$found) {
$array['repositories'][] = [ $array['repositories'][] = [
'type' => 'vcs', 'type' => 'vcs',
'url' => GITHUB_URL, 'url' => GITHUB_URL,
]; ];
} }
// Define the "require"
$array['require']['codeigniter4/codeigniter4'] = 'dev-develop'; $array['require']['codeigniter4/codeigniter4'] = 'dev-develop';
unset($array['require']['codeigniter4/framework']); unset($array['require']['codeigniter4/framework']);
} } else {
// Release
else {
// Clear 'minimum-stability'
unset($array['minimum-stability']); unset($array['minimum-stability']);
// If the repo is configured then clear it
if (isset($array['repositories'])) { if (isset($array['repositories'])) {
// Check for the CodeIgniter repo
foreach ($array['repositories'] as $i => $repository) { foreach ($array['repositories'] as $i => $repository) {
if ($repository['url'] == GITHUB_URL) { if ($repository['url'] === GITHUB_URL) {
unset($array['repositories'][$i]); unset($array['repositories'][$i]);
break; break;
} }
} }
if (empty($array['repositories'])) { if (empty($array['repositories'])) {
unset($array['repositories']); unset($array['repositories']);
} }
} }
// Define the "require"
$array['require']['codeigniter4/framework'] = LATEST_RELEASE; $array['require']['codeigniter4/framework'] = LATEST_RELEASE;
unset($array['require']['codeigniter4/codeigniter4']); unset($array['require']['codeigniter4/codeigniter4']);
} }
// Write out a new composer.json file_put_contents($file, json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
file_put_contents(
$file,
json_encode(
$array,
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
) . PHP_EOL
);
$modified[] = $file; $modified[] = $file;
} else { } else {
echo 'Warning: Unable to decode composer.json! Skipping...' . echo 'Warning: Unable to decode composer.json! Skipping...' . PHP_EOL;
PHP_EOL;
} }
} else { } else {
echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL; echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL;
} }
} }
// Paths config and PHPUnit XMLs
$files = [ $files = [
__DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php', __DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php',
__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist', __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist',
@ -117,37 +100,26 @@ foreach ($files as $file) {
if (is_file($file)) { if (is_file($file)) {
$contents = file_get_contents($file); $contents = file_get_contents($file);
// Development
if ($dev) { if ($dev) {
$contents = str_replace( $contents = str_replace('vendor/codeigniter4/framework', 'vendor/codeigniter4/codeigniter4', $contents);
'vendor/codeigniter4/framework', } else {
'vendor/codeigniter4/codeigniter4', $contents = str_replace('vendor/codeigniter4/codeigniter4', 'vendor/codeigniter4/framework', $contents);
$contents
);
}
// Release
else {
$contents = str_replace(
'vendor/codeigniter4/codeigniter4',
'vendor/codeigniter4/framework',
$contents
);
} }
file_put_contents($file, $contents); file_put_contents($file, $contents);
$modified[] = $file; $modified[] = $file;
} }
} }
if (empty($modified)) { if ($modified === []) {
echo 'No files modified' . PHP_EOL; echo 'No files modified.' . PHP_EOL;
} else { } else {
echo 'The following files were modified:' . PHP_EOL; echo 'The following files were modified:' . PHP_EOL;
foreach ($modified as $file) { foreach ($modified as $file) {
echo " * {$file}" . PHP_EOL; echo " * {$file}" . PHP_EOL;
} }
echo 'Run `composer update` to sync changes with your vendor folder' .
PHP_EOL;
}
echo 'Run `composer update` to sync changes with your vendor folder.' . PHP_EOL;
}

158
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "afb6585b90ed08cc8a257f346ab1c416", "content-hash": "9efed48a02371916c3615af689e1cba2",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -106,12 +106,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/codeigniter4/CodeIgniter4.git", "url": "https://github.com/codeigniter4/CodeIgniter4.git",
"reference": "995c51f383844bc44a607026ea6ab85b06c7e87e" "reference": "0755553a4259fbacc799395ca8a5546c5e979c45"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/codeigniter4/CodeIgniter4/zipball/995c51f383844bc44a607026ea6ab85b06c7e87e", "url": "https://api.github.com/repos/codeigniter4/CodeIgniter4/zipball/0755553a4259fbacc799395ca8a5546c5e979c45",
"reference": "995c51f383844bc44a607026ea6ab85b06c7e87e", "reference": "0755553a4259fbacc799395ca8a5546c5e979c45",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -119,22 +119,22 @@
"ext-intl": "*", "ext-intl": "*",
"ext-json": "*", "ext-json": "*",
"ext-mbstring": "*", "ext-mbstring": "*",
"kint-php/kint": "^3.3", "kint-php/kint": "^4.0",
"laminas/laminas-escaper": "^2.6", "laminas/laminas-escaper": "^2.9",
"php": "^7.3 || ^8.0", "php": "^7.3 || ^8.0",
"psr/log": "^1.1" "psr/log": "^1.1"
}, },
"require-dev": { "require-dev": {
"codeigniter/coding-standard": "^1.1",
"fakerphp/faker": "^1.9", "fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "^3.0", "friendsofphp/php-cs-fixer": "^3.1",
"mikey179/vfsstream": "^1.6", "mikey179/vfsstream": "^1.6",
"nexusphp/cs-config": "^3.1", "nexusphp/cs-config": "^3.3",
"nexusphp/tachycardia": "^1.0", "nexusphp/tachycardia": "^1.0",
"phpstan/phpstan": "0.12.88", "phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^9.1", "phpunit/phpunit": "^9.1",
"predis/predis": "^1.1", "predis/predis": "^1.1",
"rector/rector": "0.11.16", "rector/rector": "0.12.10"
"symplify/package-builder": "^9.3"
}, },
"suggest": { "suggest": {
"ext-fileinfo": "Improves mime type detection for files" "ext-fileinfo": "Improves mime type detection for files"
@ -164,7 +164,15 @@
"bash -c \"if [ -f admin/setup.sh ]; then bash admin/setup.sh; fi\"" "bash -c \"if [ -f admin/setup.sh ]; then bash admin/setup.sh; fi\""
], ],
"analyze": ["phpstan analyse"], "analyze": ["phpstan analyse"],
"test": ["phpunit"] "test": ["phpunit"],
"cs": [
"php-cs-fixer fix --verbose --dry-run --diff --config=.no-header.php-cs-fixer.dist.php",
"php-cs-fixer fix --verbose --dry-run --diff"
],
"cs-fix": [
"php-cs-fixer fix --verbose --diff --config=.no-header.php-cs-fixer.dist.php",
"php-cs-fixer fix --verbose --diff"
]
}, },
"license": ["MIT"], "license": ["MIT"],
"description": "The CodeIgniter framework v4", "description": "The CodeIgniter framework v4",
@ -175,7 +183,7 @@
"slack": "https://codeigniterchat.slack.com", "slack": "https://codeigniterchat.slack.com",
"issues": "https://github.com/codeigniter4/CodeIgniter4/issues" "issues": "https://github.com/codeigniter4/CodeIgniter4/issues"
}, },
"time": "2021-06-10T06:40:05+00:00" "time": "2022-01-04T07:11:09+00:00"
}, },
{ {
"name": "codeigniter4/settings", "name": "codeigniter4/settings",
@ -587,24 +595,24 @@
}, },
{ {
"name": "james-heinrich/getid3", "name": "james-heinrich/getid3",
"version": "v2.0.0-beta4", "version": "2.0.x-dev",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/JamesHeinrich/getID3.git", "url": "https://github.com/JamesHeinrich/getID3.git",
"reference": "5ad79104e937e7d9c8a9141a97e1f063dd1123f8" "reference": "ee238d552571c6029898b087d5fc95df826418d6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/JamesHeinrich/getID3/zipball/5ad79104e937e7d9c8a9141a97e1f063dd1123f8", "url": "https://api.github.com/repos/JamesHeinrich/getID3/zipball/ee238d552571c6029898b087d5fc95df826418d6",
"reference": "5ad79104e937e7d9c8a9141a97e1f063dd1123f8", "reference": "ee238d552571c6029898b087d5fc95df826418d6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.4.0" "php": ">=5.4.0"
}, },
"require-dev": { "require-dev": {
"jakub-onderka/php-parallel-lint": "^0.9 || ^1.0", "php-parallel-lint/php-parallel-lint": "^1.0",
"phpunit/phpunit": "^4.8|^5.0" "phpunit/phpunit": "^4.8 || ^5.0 || ^6.1 || ^7.5 || ^8.5"
}, },
"suggest": { "suggest": {
"ext-SimpleXML": "SimpleXML extension is required to analyze RIFF/WAV/BWF audio files (also requires `ext-libxml`).", "ext-SimpleXML": "SimpleXML extension is required to analyze RIFF/WAV/BWF audio files (also requires `ext-libxml`).",
@ -655,43 +663,37 @@
"keywords": ["audio", "codecs", "id3", "metadata", "tags", "video"], "keywords": ["audio", "codecs", "id3", "metadata", "tags", "video"],
"support": { "support": {
"issues": "https://github.com/JamesHeinrich/getID3/issues", "issues": "https://github.com/JamesHeinrich/getID3/issues",
"source": "https://github.com/JamesHeinrich/getID3/tree/v2.0.0-beta4" "source": "https://github.com/JamesHeinrich/getID3/tree/2.0"
}, },
"time": "2021-10-06T16:23:45+00:00" "time": "2021-12-15T17:29:14+00:00"
}, },
{ {
"name": "kint-php/kint", "name": "kint-php/kint",
"version": "3.3", "version": "4.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/kint-php/kint.git", "url": "https://github.com/kint-php/kint.git",
"reference": "335ac1bcaf04d87df70d8aa51e8887ba2c6d203b" "reference": "e64b939f9ceb9620abd982e2a66a3289fcf4e837"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/kint-php/kint/zipball/335ac1bcaf04d87df70d8aa51e8887ba2c6d203b", "url": "https://api.github.com/repos/kint-php/kint/zipball/e64b939f9ceb9620abd982e2a66a3289fcf4e837",
"reference": "335ac1bcaf04d87df70d8aa51e8887ba2c6d203b", "reference": "e64b939f9ceb9620abd982e2a66a3289fcf4e837",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.6" "php": ">=5.6"
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^2.0", "friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "^4.0", "phpspec/prophecy-phpunit": "^2",
"phpunit/phpunit": "^9.0",
"seld/phar-utils": "^1.0", "seld/phar-utils": "^1.0",
"symfony/finder": "^2.0 || ^3.0 || ^4.0", "symfony/finder": "^3.0 || ^4.0 || ^5.0",
"vimeo/psalm": "^3.0" "vimeo/psalm": "^4.0"
}, },
"suggest": { "suggest": {
"ext-ctype": "Simple data type tests", "kint-php/kint-twig": "Provides d() and s() functions in twig templates"
"ext-iconv": "Provides fallback detection for ambiguous legacy string encodings such as the Windows and ISO 8859 code pages",
"ext-mbstring": "Provides string encoding detection",
"kint-php/kint-js": "Provides a simplified dump to console.log()",
"kint-php/kint-twig": "Provides d() and s() functions in twig templates",
"symfony/polyfill-ctype": "Replacement for ext-ctype if missing",
"symfony/polyfill-iconv": "Replacement for ext-iconv if missing",
"symfony/polyfill-mbstring": "Replacement for ext-mbstring if missing"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -707,10 +709,6 @@
"name": "Jonathan Vollebregt", "name": "Jonathan Vollebregt",
"homepage": "https://github.com/jnvsor" "homepage": "https://github.com/jnvsor"
}, },
{
"name": "Rokas Šleinius",
"homepage": "https://github.com/raveren"
},
{ {
"name": "Contributors", "name": "Contributors",
"homepage": "https://github.com/kint-php/kint/graphs/contributors" "homepage": "https://github.com/kint-php/kint/graphs/contributors"
@ -721,33 +719,32 @@
"keywords": ["debug", "kint", "php"], "keywords": ["debug", "kint", "php"],
"support": { "support": {
"issues": "https://github.com/kint-php/kint/issues", "issues": "https://github.com/kint-php/kint/issues",
"source": "https://github.com/kint-php/kint/tree/master" "source": "https://github.com/kint-php/kint/tree/4.1.1"
}, },
"time": "2019-10-17T18:05:24+00:00" "time": "2022-01-02T10:30:48+00:00"
}, },
{ {
"name": "laminas/laminas-escaper", "name": "laminas/laminas-escaper",
"version": "2.7.0", "version": "2.9.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laminas/laminas-escaper.git", "url": "https://github.com/laminas/laminas-escaper.git",
"reference": "5e04bc5ae5990b17159d79d331055e2c645e5cc5" "reference": "891ad70986729e20ed2e86355fcf93c9dc238a5f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laminas/laminas-escaper/zipball/5e04bc5ae5990b17159d79d331055e2c645e5cc5", "url": "https://api.github.com/repos/laminas/laminas-escaper/zipball/891ad70986729e20ed2e86355fcf93c9dc238a5f",
"reference": "5e04bc5ae5990b17159d79d331055e2c645e5cc5", "reference": "891ad70986729e20ed2e86355fcf93c9dc238a5f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"laminas/laminas-zendframework-bridge": "^1.0", "php": "^7.3 || ~8.0.0 || ~8.1.0"
"php": "^7.3 || ~8.0.0"
}, },
"replace": { "conflict": {
"zendframework/zend-escaper": "^2.6.1" "zendframework/zend-escaper": "*"
}, },
"require-dev": { "require-dev": {
"laminas/laminas-coding-standard": "~1.0.0", "laminas/laminas-coding-standard": "~2.3.0",
"phpunit/phpunit": "^9.3", "phpunit/phpunit": "^9.3",
"psalm/plugin-phpunit": "^0.12.2", "psalm/plugin-phpunit": "^0.12.2",
"vimeo/psalm": "^3.16" "vimeo/psalm": "^3.16"
@ -781,60 +778,7 @@
"type": "community_bridge" "type": "community_bridge"
} }
], ],
"time": "2020-11-17T21:26:43+00:00" "time": "2021-09-02T17:10:53+00:00"
},
{
"name": "laminas/laminas-zendframework-bridge",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/laminas/laminas-zendframework-bridge.git",
"reference": "6cccbddfcfc742eb02158d6137ca5687d92cee32"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laminas/laminas-zendframework-bridge/zipball/6cccbddfcfc742eb02158d6137ca5687d92cee32",
"reference": "6cccbddfcfc742eb02158d6137ca5687d92cee32",
"shasum": ""
},
"require": {
"php": "^7.3 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7 || ^6.5 || ^7.5 || ^8.1 || ^9.3",
"psalm/plugin-phpunit": "^0.15.1",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^4.6"
},
"type": "library",
"extra": {
"laminas": {
"module": "Laminas\\ZendFrameworkBridge"
}
},
"autoload": {
"files": ["src/autoload.php"],
"psr-4": {
"Laminas\\ZendFrameworkBridge\\": "src//"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": ["BSD-3-Clause"],
"description": "Alias legacy ZF class names to Laminas Project equivalents.",
"keywords": ["ZendFramework", "autoloading", "laminas", "zf"],
"support": {
"forum": "https://discourse.laminas.dev/",
"issues": "https://github.com/laminas/laminas-zendframework-bridge/issues",
"rss": "https://github.com/laminas/laminas-zendframework-bridge/releases.atom",
"source": "https://github.com/laminas/laminas-zendframework-bridge"
},
"funding": [
{
"url": "https://funding.communitybridge.org/projects/laminas-project",
"type": "community_bridge"
}
],
"time": "2021-02-25T21:54:58+00:00"
}, },
{ {
"name": "league/commonmark", "name": "league/commonmark",

8
env
View File

@ -110,6 +110,8 @@
# SECURITY # SECURITY
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# security.csrfProtection = 'cookie'
# security.tokenRandomize = false
# security.tokenName = 'csrf_token_name' # security.tokenName = 'csrf_token_name'
# security.headerName = 'X-CSRF-TOKEN' # security.headerName = 'X-CSRF-TOKEN'
# security.cookieName = 'csrf_cookie_name' # security.cookieName = 'csrf_cookie_name'
@ -123,3 +125,9 @@
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# logger.threshold = 4 # logger.threshold = 4
#--------------------------------------------------------------------
# CURLRequest
#--------------------------------------------------------------------
# curlrequest.shareOptions = true

View File

@ -30,6 +30,8 @@ parameters:
- '#Function "property_exists\(\)" cannot be used/left in the code#' - '#Function "property_exists\(\)" cannot be used/left in the code#'
- '#Instead of "instanceof/is_a\(\)" use ReflectionProvider service or "\(new ObjectType\(<desired_type\>\)\)\-\>isSuperTypeOf\(<element_type\>\)" for static reflection to work#' - '#Instead of "instanceof/is_a\(\)" use ReflectionProvider service or "\(new ObjectType\(<desired_type\>\)\)\-\>isSuperTypeOf\(<element_type\>\)" for static reflection to work#'
- '#^Access to an undefined property App\\Entities\\Media\\Image#' - '#^Access to an undefined property App\\Entities\\Media\\Image#'
- '#^Call to an undefined method CodeIgniter\\Model#'
- '#^Access to an undefined property CodeIgniter\\Database\\BaseBuilder#'
- -
message: '#Function "function_exists\(\)" cannot be used/left in the code#' message: '#Function "function_exists\(\)" cannot be used/left in the code#'
paths: paths:

View File

@ -1,61 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Support;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use Tests\Support\Database\Seeds\ExampleSeeder;
/**
* @phpstan-ignore-next-line
*/
class DatabaseTestCase extends CIUnitTestCase
{
use DatabaseTestTrait;
/**
* Should the database be refreshed before each test?
*
* @var boolean
*/
protected $refresh = true;
/**
* The seed file(s) used for all tests within this test case. Should be fully-namespaced or relative to $basePath
*
* @var string|string[]
*/
protected $seed = ExampleSeeder::class;
/**
* The path to the seeds directory. Allows overriding the default application directories.
*
* @var string
*/
protected $basePath = SUPPORTPATH . 'Database/';
/**
* The namespace(s) to help us find the migration classes. Empty is equivalent to running `spark migrate -all`. Note
* that running "all" runs migrations in date order, but specifying namespaces runs them in namespace order (then
* date)
*
* @var string|string[]|null
*/
protected $namespace = 'Tests\Support';
protected function setUp(): void
{
parent::setUp();
// Extra code to run before each test
}
protected function tearDown(): void
{
parent::tearDown();
// Extra code to run after each test
}
}

View File

@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Support;
use CodeIgniter\Session\Handlers\ArrayHandler;
use CodeIgniter\Session\SessionInterface;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Mock\MockSession;
use Config\Services;
/**
* @phpstan-ignore-next-line
*/
class SessionTestCase extends CIUnitTestCase
{
/**
* @var SessionInterface
*/
protected $session;
protected function setUp(): void
{
parent::setUp();
$this->mockSession();
}
/**
* Pre-loads the mock session driver into $this->session.
*
* @var string
*/
protected function mockSession(): void
{
$config = config('App');
$this->session = new MockSession(new ArrayHandler($config, '0.0.0.0'), $config,);
Services::injectMock('session', $this->session);
}
}

View File

@ -4,17 +4,19 @@ declare(strict_types=1);
namespace Tests\Database; namespace Tests\Database;
use Tests\Support\DatabaseTestCase; use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use Tests\Support\Database\Seeds\ExampleSeeder;
use Tests\Support\Models\ExampleModel; use Tests\Support\Models\ExampleModel;
class ExampleDatabaseTest extends DatabaseTestCase class ExampleDatabaseTest extends CIUnitTestCase
{ {
protected function setUp(): void use DatabaseTestTrait;
{
parent::setUp();
// Extra code to run before each test /**
} * @var string
*/
protected $seed = ExampleSeeder::class;
public function testModelFindAll(): void public function testModelFindAll(): void
{ {

View File

@ -4,21 +4,16 @@ declare(strict_types=1);
namespace Tests\Session; namespace Tests\Session;
use Tests\Support\SessionTestCase; use CodeIgniter\Test\CIUnitTestCase;
use Config\Services;
class ExampleSessionTest extends SessionTestCase class ExampleSessionTest extends CIUnitTestCase
{ {
protected function setUp(): void
{
parent::setUp();
}
public function testSessionSimple(): void public function testSessionSimple(): void
{ {
$this->session->set('logged_in', 123); $session = Services::session();
$value = $this->session->get('logged_in'); $session->set('logged_in', 123);
$this->assertSame(123, $session->get('logged_in'));
$this->assertSame(123, $value);
} }
} }

View File

@ -2,35 +2,30 @@
declare(strict_types=1); declare(strict_types=1);
namespace Tests\Unit;
use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\CIUnitTestCase;
use Config\App; use Config\App;
use Config\Services; use Config\Services;
use Tests\Support\Libraries\ConfigReader; use Tests\Support\Libraries\ConfigReader;
class HealthTest extends CIUnitTestCase /**
* @internal
*/
final class HealthTest extends CIUnitTestCase
{ {
protected function setUp(): void
{
parent::setUp();
}
public function testIsDefinedAppPath(): void public function testIsDefinedAppPath(): void
{ {
$test = defined('APPPATH'); $this->assertTrue(defined('APPPATH'));
$this->assertTrue($test);
} }
public function testBaseUrlHasBeenSet(): void public function testBaseUrlHasBeenSet(): void
{ {
$validation = Services::validation(); $validation = Services::validation();
$env = false; $env = false;
// Check the baseURL in .env // Check the baseURL in .env
if (is_file(HOMEPATH . '.env')) { if (is_file(HOMEPATH . '.env')) {
$env = (bool) preg_grep('~^app\.baseURL = .~', file(HOMEPATH . '.env'),); $env = preg_grep('~^app\.baseURL = .~', file(HOMEPATH . '.env')) !== false;
} }
if ($env) { if ($env) {
@ -40,7 +35,7 @@ class HealthTest extends CIUnitTestCase
$config = new App(); $config = new App();
$this->assertTrue( $this->assertTrue(
$validation->check($config->baseURL, 'valid_url'), $validation->check($config->baseURL, 'valid_url'),
'baseURL "' . $config->baseURL . '" in .env is not valid URL', 'baseURL "' . $config->baseURL . '" in .env is not valid URL'
); );
} }
@ -51,9 +46,7 @@ class HealthTest extends CIUnitTestCase
// BaseURL in app/Config/App.php is a valid URL? // BaseURL in app/Config/App.php is a valid URL?
$this->assertTrue( $this->assertTrue(
$validation->check($reader->baseURL, 'valid_url'), $validation->check($reader->baseURL, 'valid_url'),
'baseURL "' . 'baseURL "' . $reader->baseURL . '" in app/Config/App.php is not valid URL'
$reader->baseURL .
'" in app/Config/App.php is not valid URL',
); );
} }
} }