Skip to content

Commit

Permalink
Release v4.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Apr 14, 2024
1 parent 365a46c commit 9b2cd73
Show file tree
Hide file tree
Showing 25 changed files with 234 additions and 99 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,3 @@ nb-configuration.xml

/results/
/phpunit*.xml
/.phpunit.*.cache

107 changes: 61 additions & 46 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,48 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="system/Test/bootstrap.php" backupGlobals="false" colors="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage includeUncoveredFiles="true">
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/logs/html"/>
<php outputFile="build/logs/coverage.serialized"/>
<text outputFile="php://stdout" showUncoveredFiles="false"/>
</report>
</coverage>
<testsuites>
<testsuite name="App">
<directory>./tests</directory>
</testsuite>
</testsuites>
<logging>
<testdoxHtml outputFile="build/logs/testdox.html"/>
<testdoxText outputFile="build/logs/testdox.txt"/>
<junit outputFile="build/logs/logfile.xml"/>
</logging>
<php>
<server name="app.baseURL" value="http://example.com/"/>
<!-- Directory containing phpunit.xml -->
<const name="HOMEPATH" value="./"/>
<!-- Directory containing the Paths config file -->
<const name="CONFIGPATH" value="./app/Config/"/>
<!-- Directory containing the front controller (index.php) -->
<const name="PUBLICPATH" value="./public/"/>
<!-- Database configuration -->
<!-- Uncomment to provide your own database for testing
<env name="database.tests.hostname" value="localhost"/>
<env name="database.tests.database" value="tests"/>
<env name="database.tests.username" value="tests_user"/>
<env name="database.tests.password" value=""/>
<env name="database.tests.DBDriver" value="MySQLi"/>
<env name="database.tests.DBPrefix" value="tests_"/>
-->
</php>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
<exclude>
<directory suffix=".php">./app/Views</directory>
<file>./app/Config/Routes.php</file>
</exclude>
</source>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="system/Test/bootstrap.php"
backupGlobals="false"
beStrictAboutOutputDuringTests="true"
colors="true"
columns="max"
failOnRisky="true"
failOnWarning="true"
cacheDirectory="build/.phpunit.cache">
<coverage
includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/logs/html"/>
<php outputFile="build/logs/coverage.serialized"/>
<text outputFile="php://stdout" showUncoveredFiles="false"/>
</report>
</coverage>
<testsuites>
<testsuite name="App">
<directory>./tests</directory>
</testsuite>
</testsuites>
<logging>
<testdoxHtml outputFile="build/logs/testdox.html"/>
<testdoxText outputFile="build/logs/testdox.txt"/>
<junit outputFile="build/logs/logfile.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
<exclude>
<directory suffix=".php">./app/Views</directory>
<file>./app/Config/Routes.php</file>
</exclude>
</source>
<php>
<server name="app.baseURL" value="http://example.com/"/>
<server name="CODEIGNITER_SCREAM_DEPRECATIONS" value="0"/>
<!-- Directory containing phpunit.xml -->
<const name="HOMEPATH" value="./"/>
<!-- Directory containing the Paths config file -->
<const name="CONFIGPATH" value="./app/Config/"/>
<!-- Directory containing the front controller (index.php) -->
<const name="PUBLICPATH" value="./public/"/>
<!-- Database configuration -->
<!-- Uncomment to provide your own database for testing
<env name="database.tests.hostname" value="localhost"/>
<env name="database.tests.database" value="tests"/>
<env name="database.tests.username" value="tests_user"/>
<env name="database.tests.password" value=""/>
<env name="database.tests.DBDriver" value="MySQLi"/>
<env name="database.tests.DBPrefix" value="tests_"/>
-->
</php>
</phpunit>
15 changes: 14 additions & 1 deletion system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class FileLocator implements FileLocatorInterface
*/
protected $autoloader;

/**
* List of classnames that did not exist.
*
* @var list<class-string>
*/
private array $invalidClassnames = [];

public function __construct(Autoloader $autoloader)
{
$this->autoloader = $autoloader;
Expand Down Expand Up @@ -288,14 +295,20 @@ public function findQualifiedNameFromPath(string $path)
),
'\\'
);

// Remove the file extension (.php)
$className = mb_substr($className, 0, -4);

if (in_array($className, $this->invalidClassnames, true)) {
continue;
}

// Check if this exists
if (class_exists($className)) {
return $className;
}

// If the class does not exist, it is an invalid classname.
$this->invalidClassnames[] = $className;
}
}

Expand Down
8 changes: 5 additions & 3 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,9 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
$row = (array) $row;
}

// Convert any Time instances to appropriate $dateFormat
$row = $this->timeToString($row);

// Validate every row.
if (! $this->skipValidation && ! $this->validate($row)) {
// Restore $cleanValidationRules
Expand Down Expand Up @@ -1845,8 +1848,6 @@ protected function transformDataToArray($row, string $type): array
$row = $this->converter->toDataSource($row);
} elseif ($row instanceof Entity) {
$row = $this->converter->extract($row, $onlyChanged);
// Convert any Time instances to appropriate $dateFormat
$row = $this->timeToString($row);
} elseif (is_object($row)) {
$row = $this->converter->extract($row, $onlyChanged);
}
Expand All @@ -1870,7 +1871,8 @@ protected function transformDataToArray($row, string $type): array
throw DataException::forEmptyDataset($type);
}

return $row;
// Convert any Time instances to appropriate $dateFormat
return $this->timeToString($row);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ abstract public function run(array $params);
/**
* Can be used by a command to run other commands.
*
* @param array<int|string, string|null> $params
*
* @return int|void
*
* @throws ReflectionException
Expand Down Expand Up @@ -140,7 +142,7 @@ public function showHelp()
{
CLI::write(lang('CLI.helpUsage'), 'yellow');

if (! empty($this->usage)) {
if (isset($this->usage)) {
$usage = $this->usage;
} else {
$usage = $this->name;
Expand All @@ -152,7 +154,7 @@ public function showHelp()

CLI::write($this->setPad($usage, 0, 0, 2));

if (! empty($this->description)) {
if (isset($this->description)) {
CLI::newLine();
CLI::write(lang('CLI.helpDescription'), 'yellow');
CLI::write($this->setPad($this->description, 0, 0, 2));
Expand Down Expand Up @@ -194,6 +196,8 @@ public function setPad(string $item, int $max, int $extra = 2, int $indent = 0):
/**
* Get pad for $key => $value array output
*
* @param array<string, string> $array
*
* @deprecated Use setPad() instead.
*
* @codeCoverageIgnore
Expand All @@ -212,7 +216,7 @@ public function getPad(array $array, int $pad): int
/**
* Makes it simple to access our protected properties.
*
* @return array|Commands|LoggerInterface|string|null
* @return array<string, string>|Commands|LoggerInterface|string|null
*/
public function __get(string $key)
{
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CodeIgniter
/**
* The current version of CodeIgniter Framework
*/
public const CI_VERSION = '4.5.0';
public const CI_VERSION = '4.5.1';

/**
* App startup time.
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Housekeeping/ClearDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function run(array $params)
{
helper('filesystem');

if (! delete_files(WRITEPATH . 'debugbar')) {
if (! delete_files(WRITEPATH . 'debugbar', false, true)) {
// @codeCoverageIgnoreStart
CLI::error('Error deleting the debugbar JSON files.');
CLI::newLine();
Expand Down
7 changes: 7 additions & 0 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,15 @@ protected static function buildServicesCache(): void
$locator = static::locator();
$files = $locator->search('Config/Services');

$systemPath = static::autoloader()->getNamespace('CodeIgniter')[0];

// Get instances of all service classes and cache them locally.
foreach ($files as $file) {
// Does not search `CodeIgniter` namespace to prevent from loading twice.
if (str_starts_with($file, $systemPath)) {
continue;
}

$classname = $locator->findQualifiedNameFromPath($file);

if ($classname === false) {
Expand Down
4 changes: 3 additions & 1 deletion system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ public static function get(string $component, string $alias): ?object
if (isset(self::$aliases[$component][$alias])) {
$class = self::$aliases[$component][$alias];

return self::$instances[$component][$class];
if (isset(self::$instances[$component][$class])) {
return self::$instances[$component][$class];
}
}

return self::__callStatic($component, [$alias]);
Expand Down
22 changes: 17 additions & 5 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Events\Events;
use stdClass;
use Stringable;
use Throwable;

/**
Expand Down Expand Up @@ -1309,12 +1310,15 @@ public function escape($str)
return array_map($this->escape(...), $str);
}

/** @psalm-suppress NoValue I don't know why ERROR. */
if (is_string($str) || (is_object($str) && method_exists($str, '__toString'))) {
if ($str instanceof Stringable) {
if ($str instanceof RawSql) {
return $str->__toString();
}

$str = (string) $str;
}

if (is_string($str)) {
return "'" . $this->escapeString($str) . "'";
}

Expand All @@ -1328,8 +1332,8 @@ public function escape($str)
/**
* Escape String
*
* @param list<string>|string $str Input string
* @param bool $like Whether or not the string will be used in a LIKE condition
* @param list<string|Stringable>|string|Stringable $str Input string
* @param bool $like Whether the string will be used in a LIKE condition
*
* @return list<string>|string
*/
Expand All @@ -1343,6 +1347,14 @@ public function escapeString($str, bool $like = false)
return $str;
}

if ($str instanceof Stringable) {
if ($str instanceof RawSql) {
return $str->__toString();
}

$str = (string) $str;
}

$str = $this->_escapeString($str);

// escape LIKE condition wildcards
Expand Down Expand Up @@ -1371,7 +1383,7 @@ public function escapeString($str, bool $like = false)
* Calls the individual driver for platform
* specific escaping for LIKE conditions
*
* @param list<string>|string $str
* @param list<string|Stringable>|string|Stringable $str
*
* @return list<string>|string
*/
Expand Down
9 changes: 6 additions & 3 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PgSql\Connection as PgSqlConnection;
use PgSql\Result as PgSqlResult;
use stdClass;
use Stringable;

/**
* Connection for Postgre
Expand Down Expand Up @@ -233,20 +234,22 @@ public function escape($str)
$this->initialize();
}

/** @psalm-suppress NoValue I don't know why ERROR. */
if (is_string($str) || (is_object($str) && method_exists($str, '__toString'))) {
if ($str instanceof Stringable) {
if ($str instanceof RawSql) {
return $str->__toString();
}

$str = (string) $str;
}

if (is_string($str)) {
return pg_escape_literal($this->connID, $str);
}

if (is_bool($str)) {
return $str ? 'TRUE' : 'FALSE';
}

/** @psalm-suppress NoValue I don't know why ERROR. */
return parent::escape($str);
}

Expand Down
10 changes: 8 additions & 2 deletions system/Debug/BaseExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,14 @@ protected static function highlightFile(string $file, int $lineNumber, int $line
*/
protected function render(Throwable $exception, int $statusCode, $viewFile = null): void
{
if (empty($viewFile) || ! is_file($viewFile)) {
echo 'The error view files were not found. Cannot render exception trace.';
if ($viewFile === null) {
echo 'The error view file was not specified. Cannot display error view.';

exit(1);
}

if (! is_file($viewFile)) {
echo 'The error view file "' . $viewFile . '" was not found. Cannot display error view.';

exit(1);
}
Expand Down
Loading

0 comments on commit 9b2cd73

Please sign in to comment.