Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jun 1, 2024
2 parents 55cc8d2 + 482b8bb commit ef00c11
Show file tree
Hide file tree
Showing 46 changed files with 237 additions and 41 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test-file-permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Check File Permissions

on:
pull_request:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read

jobs:
permission-check:
name: Check File Permission
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Detect unnecessary execution permissions
run: php utils/check_permission_x.php
Empty file modified admin/starter/tests/.htaccess
100755 → 100644
Empty file.
Empty file modified admin/starter/tests/index.html
100755 → 100644
Empty file.
Empty file modified app/Config/DocTypes.php
100755 → 100644
Empty file.
13 changes: 0 additions & 13 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php70\Rector\FuncCall\RandomFunctionRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
use Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector;
use Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector;
Expand Down Expand Up @@ -107,7 +105,6 @@
__DIR__ . '/tests/_support/Commands/Foobar.php',
__DIR__ . '/tests/_support/View',

JsonThrowOnErrorRector::class,
YieldDataProviderRector::class,

RemoveUnusedPromotedPropertyRector::class => [
Expand Down Expand Up @@ -174,16 +171,6 @@
],
MixedTypeRector::class,

// PHP 8.1 features but cause breaking changes
FinalizePublicClassConstantRector::class => [
__DIR__ . '/system/Cache/Handlers/BaseHandler.php',
__DIR__ . '/system/Cache/Handlers/FileHandler.php',
__DIR__ . '/system/CodeIgniter.php',
__DIR__ . '/system/Events/Events.php',
__DIR__ . '/system/Log/Handlers/ChromeLoggerHandler.php',
__DIR__ . '/system/Log/Handlers/ErrorlogHandler.php',
__DIR__ . '/system/Security/Security.php',
],
ReturnNeverTypeRector::class => [
__DIR__ . '/system/Cache/Handlers/BaseHandler.php',
__DIR__ . '/system/Cache/Handlers/MemcachedHandler.php',
Expand Down
14 changes: 12 additions & 2 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ public function initialize()
// Connect to the database and set the connection ID
$this->connID = $this->connect($this->pConnect);
} catch (Throwable $e) {
$connectionErrors[] = sprintf('Main connection [%s]: %s', $this->DBDriver, $e->getMessage());
$this->connID = false;
$connectionErrors[] = sprintf(
'Main connection [%s]: %s',
$this->DBDriver,
$e->getMessage()
);
log_message('error', 'Error connecting to the database: ' . $e);
}

Expand All @@ -441,7 +446,12 @@ public function initialize()
// Try to connect
$this->connID = $this->connect($this->pConnect);
} catch (Throwable $e) {
$connectionErrors[] = sprintf('Failover #%d [%s]: %s', ++$index, $this->DBDriver, $e->getMessage());
$connectionErrors[] = sprintf(
'Failover #%d [%s]: %s',
++$index,
$this->DBDriver,
$e->getMessage()
);
log_message('error', 'Error connecting to the database: ' . $e);
}

Expand Down
13 changes: 10 additions & 3 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,24 @@ public function connect(bool $persistent = false)
$this->connID = $persistent === true ? pg_pconnect($this->DSN) : pg_connect($this->DSN);

if ($this->connID !== false) {
if ($persistent === true && pg_connection_status($this->connID) === PGSQL_CONNECTION_BAD && pg_ping($this->connID) === false
if (
$persistent === true
&& pg_connection_status($this->connID) === PGSQL_CONNECTION_BAD
&& pg_ping($this->connID) === false
) {
return false;
$error = pg_last_error($this->connID);

throw new DatabaseException($error);
}

if (! empty($this->schema)) {
$this->simpleQuery("SET search_path TO {$this->schema},public");
}

if ($this->setClientEncoding($this->charset) === false) {
return false;
$error = pg_last_error($this->connID);

throw new DatabaseException($error);
}
}

Expand Down
Empty file modified system/Database/SQLSRV/Builder.php
100755 → 100644
Empty file.
Empty file modified system/Database/SQLSRV/Connection.php
100755 → 100644
Empty file.
Empty file modified system/Database/SQLSRV/Forge.php
100755 → 100644
Empty file.
Empty file modified system/Database/SQLSRV/PreparedQuery.php
100755 → 100644
Empty file.
Empty file modified system/Database/SQLSRV/Result.php
100755 → 100644
Empty file.
Empty file modified system/Database/SQLSRV/Utils.php
100755 → 100644
Empty file.
Empty file modified system/HTTP/IncomingRequest.php
100755 → 100644
Empty file.
Empty file modified system/Helpers/cookie_helper.php
100755 → 100644
Empty file.
Empty file modified system/Helpers/html_helper.php
100755 → 100644
Empty file.
Empty file modified system/Helpers/inflector_helper.php
100755 → 100644
Empty file.
Empty file modified system/Helpers/text_helper.php
100755 → 100644
Empty file.
Empty file modified system/Test/Mock/MockResponse.php
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion system/Test/PhpStreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function restore()
stream_wrapper_restore('php');
}

public function stream_open(string $path): bool
public function stream_open(): bool
{
return true;
}
Expand Down
55 changes: 55 additions & 0 deletions tests/system/Database/Live/Postgre/ConnectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\Database\Live\Postgre;

use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Database;
use PHPUnit\Framework\Attributes\Group;

/**
* @internal
*/
#[Group('DatabaseLive')]
final class ConnectTest extends CIUnitTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->db = Database::connect($this->DBGroup);

if ($this->db->DBDriver !== 'Postgre') {
$this->markTestSkipped('This test is only for Postgre.');
}
}

public function testShowErrorMessageWhenSettingInvalidCharset(): void
{
$this->expectException(DatabaseException::class);
$this->expectExceptionMessage(
'Unable to connect to the database.
Main connection [Postgre]: ERROR: invalid value for parameter "client_encoding": "utf8mb4"'
);

$config = config('Database');
$group = $config->tests;
// Sets invalid charset.
$group['charset'] = 'utf8mb4';
$db = Database::connect($group);

// Actually connect to DB.
$db->initialize();
}
}
Empty file modified tests/system/Helpers/CookieHelperTest.php
100755 → 100644
Empty file.
Empty file modified tests/system/Helpers/HTMLHelperTest.php
100755 → 100644
Empty file.
Empty file modified tests/system/Helpers/InflectorHelperTest.php
100755 → 100644
Empty file.
Empty file modified tests/system/Helpers/NumberHelperTest.php
100755 → 100644
Empty file.
Empty file modified tests/system/Helpers/TextHelperTest.php
100755 → 100644
Empty file.
3 changes: 2 additions & 1 deletion user_guide_src/source/_static/css/citheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(
background-color: #fffff0;
}

span.std {
span.std,
span.pre {
text-wrap: nowrap;
}

Expand Down
Empty file modified user_guide_src/source/database/query_builder.rst
100755 → 100644
Empty file.
Empty file modified user_guide_src/source/general/common_functions.rst
100755 → 100644
Empty file.
Empty file modified user_guide_src/source/helpers/cookie_helper.rst
100755 → 100644
Empty file.
Empty file modified user_guide_src/source/helpers/html_helper.rst
100755 → 100644
Empty file.
Empty file modified user_guide_src/source/helpers/inflector_helper.rst
100755 → 100644
Empty file.
Empty file modified user_guide_src/source/helpers/text_helper.rst
100755 → 100644
Empty file.
21 changes: 8 additions & 13 deletions user_guide_src/source/libraries/caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ to projects and modules. This will replace the hard-coded value in a future rele
$file
=====

This is an array of settings specific to the ``File`` handler to determine how it should save the cache files.
This is an array of settings specific to the **File** handler to determine how it should save the cache files.

$memcached
==========

This is an array of servers that will be used when using the ``Memcache(d)`` handler.
This is an array of servers that will be used when using the **Memcached** handler.

$redis
======

The settings for the Redis server that you wish to use when using the ``Redis`` and ``Predis`` handler.
The settings for the Redis server that you wish to use when using the **Redis** and **Predis** handler.

******************
Command-Line Tools
Expand Down Expand Up @@ -139,12 +139,11 @@ Class Reference
Gets an item from the cache. If ``null`` was returned, this will invoke the callback
and save the result. Either way, this will return the value.

.. php:method:: save(string $key, $data[, int $ttl = 60[, $raw = false]])
.. php:method:: save(string $key, $data[, int $ttl = 60])
:param string $key: Cache item name
:param mixed $data: the data to save
:param int $ttl: Time To Live, in seconds (default 60)
:param bool $raw: Whether to store the raw value
:returns: ``true`` on success, ``false`` on failure
:rtype: bool

Expand All @@ -155,9 +154,6 @@ Class Reference

.. literalinclude:: caching/004.php

.. note:: The ``$raw`` parameter is only utilized by Memcache,
in order to allow usage of ``increment()`` and ``decrement()``.

.. php:method:: delete($key): bool
:param string $key: name of cached item
Expand Down Expand Up @@ -280,11 +276,10 @@ Drivers
File-based Caching
==================

Unlike caching from the Output Class, the driver file-based caching
allows for pieces of view files to be cached. Use this with care, and
make sure to benchmark your application, as a point can come where disk
I/O will negate positive gains by caching. This requires a cache
directory to be really writable by the application.
This requires a cache directory to be really writable by the application.

Use this with care, and make sure to benchmark your application, as a point can
come where disk I/O will negate positive gains by caching.

Memcached Caching
=================
Expand Down
13 changes: 9 additions & 4 deletions user_guide_src/source/models/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CodeIgniter does provide a model class that has a few nice features, including:

- automatic database connection
- basic CRUD methods
- in-model validation
- :ref:`in-model validation <in-model-validation>`
- :ref:`automatic pagination <paginating-with-models>`
- and more

Expand Down Expand Up @@ -659,9 +659,14 @@ prior to saving to the database with the ``insert()``, ``update()``, or ``save()
.. important:: When you update data, by default, the validation in the model class only
validates provided fields. This is to avoid validation errors when updating only some fields.

But this means ``required*`` rules do not work as expected when updating.
If you want to check required fields, you can change the behavior by configuration.
See :ref:`clean-validation-rules` for details.
However, this means that not all validation rules you set will be checked
during updates. Thus, incomplete data may pass the validation.

For example, ``required*`` rules or ``is_unique`` rule that require the
values of other fields may not work as expected.

To avoid such glitches, this behavior can be changed by configuration. See
:ref:`clean-validation-rules` for details.

Setting Validation Rules
------------------------
Expand Down
4 changes: 4 additions & 0 deletions user_guide_src/source/outgoing/view_cells.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ Implementing the AlertMessage from above as a Controlled Cell would look like th

.. literalinclude:: view_cells/010.php

.. note:: If you use typed properties, you must set the initial values:

.. literalinclude:: view_cells/023.php

.. _generating-cell-via-command:

Generating Cell via Command
Expand Down
13 changes: 13 additions & 0 deletions user_guide_src/source/outgoing/view_cells/023.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

// app/Cells/AlertMessageCell.php

namespace App\Cells;

use CodeIgniter\View\Cells\Cell;

class AlertMessageCell extends Cell
{
public string $type = '';
public string $message = '';
}
8 changes: 4 additions & 4 deletions user_guide_src/source/testing/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ There are no rules for how test files must be placed. However, we recommend that
you establish placement rules in advance so that you can quickly understand where
the test files are located.

In this document, we will place the test files corresponding to the classes in
the **app** directory in the **tests/app** directory. To test a new library,
In this document, the test files corresponding to the classes in the **app** directory
will be placed in the **tests/app** directory. To test a new library,
**app/Libraries/Foo.php**, you would create a new file at
**tests/app/Libraries/FooTest.php**:

.. literalinclude:: overview/001.php

To test one of your models, **app/Models/UserMode.php**, you might end up with
To test one of your models, **app/Models/UserModel.php**, you might end up with
something like this in **tests/app/Models/UserModelTest.php**:

.. literalinclude:: overview/002.php
Expand Down Expand Up @@ -121,7 +121,7 @@ parent as well so extended test cases do not interfere with staging:
Traits
------

A common way to enhance your tests is by using traits to consolidate staging across different
A common way to enhance your tests is using traits to consolidate staging across different
test cases. ``CIUnitTestCase`` will detect any class traits and look for staging methods
to run named for the trait itself (i.e. `setUp{NameOfTrait}()` and `tearDown{NameOfTrait}()`).

Expand Down
Loading

0 comments on commit ef00c11

Please sign in to comment.