Skip to content

Commit 2353ee3

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents b451206 + a3b92fa commit 2353ee3

File tree

4 files changed

+49
-34
lines changed

4 files changed

+49
-34
lines changed

admin/starter/tests/README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use to test your application. Those details can be found in the documentation.
1414
## Requirements
1515

1616
It is recommended to use the latest version of PHPUnit. At the time of this
17-
writing we are running version 9.x. Support for this has been built into the
17+
writing, we are running version 9.x. Support for this has been built into the
1818
**composer.json** file that ships with CodeIgniter and can easily be installed
1919
via [Composer](https://getcomposer.org/) if you don't already have it installed globally.
2020

@@ -35,7 +35,7 @@ for code coverage to be calculated successfully. After installing `XDebug`, you
3535

3636
A number of the tests use a running database.
3737
In order to set up the database edit the details for the `tests` group in
38-
**app/Config/Database.php** or **phpunit.xml**.
38+
**app/Config/Database.php** or **.env**.
3939
Make sure that you provide a database engine that is currently running on your machine.
4040
More details on a test database setup are in the
4141
[Testing Your Database](https://codeigniter4.github.io/userguide/testing/database.html) section of the documentation.
@@ -92,12 +92,11 @@ HTML code coverage reports.
9292
## Test Cases
9393

9494
Every test needs a *test case*, or class that your tests extend. CodeIgniter 4
95-
provides a few that you may use directly:
96-
* `CodeIgniter\Test\CIUnitTestCase` - for basic tests with no other service needs
97-
* `CodeIgniter\Test\DatabaseTestTrait` - for tests that need database access
95+
provides one class that you may use directly:
96+
* `CodeIgniter\Test\CIUnitTestCase`
9897

99-
Most of the time you will want to write your own test cases to hold functions and services
100-
common to your test suites.
98+
Most of the time you will want to write your own test cases that extend `CIUnitTestCase`
99+
to hold functions and services common to your test suites.
101100

102101
## Creating Tests
103102

@@ -112,11 +111,8 @@ Review the links above and always pay attention to your code coverage.
112111

113112
### Database Tests
114113

115-
Tests can include migrating, seeding, and testing against a mock or live<sup>1</sup> database.
114+
Tests can include migrating, seeding, and testing against a mock or live database.
116115
Be sure to modify the test case (or create your own) to point to your seed and migrations
117116
and include any additional steps to be run before tests in the `setUp()` method.
118-
119-
<sup>1</sup> Note: If you are using database tests that require a live database connection
120-
you will need to rename **phpunit.xml.dist** to **phpunit.xml**, uncomment the database
121-
configuration lines and add your connection details. Prevent **phpunit.xml** from being
122-
tracked in your repo by adding it to **.gitignore**.
117+
See [Testing Your Database](https://codeigniter4.github.io/userguide/testing/database.html)
118+
for details.

tests/system/Database/Live/AbstractGetFieldDataTest.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ abstract class AbstractGetFieldDataTest extends CIUnitTestCase
2828
protected Forge $forge;
2929
protected string $table = 'test1';
3030

31+
public static function setUpBeforeClass(): void
32+
{
33+
parent::setUpBeforeClass();
34+
35+
helper('array');
36+
}
37+
3138
protected function setUp(): void
3239
{
3340
parent::setUp();
@@ -95,14 +102,12 @@ abstract public function testGetFieldDataDefault(): void;
95102

96103
protected function assertSameFieldData(array $expected, array $actual)
97104
{
98-
$expected = json_decode(json_encode($expected), true);
99-
$names = array_column($expected, 'name');
100-
array_multisort($names, SORT_ASC, $expected);
105+
$expectedArray = json_decode(json_encode($expected), true);
106+
array_sort_by_multiple_keys($expectedArray, ['name' => SORT_ASC]);
101107

102-
$fields = json_decode(json_encode($actual), true);
103-
$names = array_column($fields, 'name');
104-
array_multisort($names, SORT_ASC, $fields);
108+
$fieldsArray = json_decode(json_encode($actual), true);
109+
array_sort_by_multiple_keys($fieldsArray, ['name' => SORT_ASC]);
105110

106-
$this->assertSame($expected, $fields);
111+
$this->assertSame($expectedArray, $fieldsArray);
107112
}
108113
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$row = $query->getCustomRowObject(0, \App\Entities\User::class);
3+
$row = $query->getRow(0, \App\Entities\User::class);

user_guide_src/source/helpers/array_helper.rst

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Loading this Helper
1515
This helper is loaded using the following code:
1616

1717
.. literalinclude:: array_helper/001.php
18+
:lines: 2-
1819

1920
Available Functions
2021
===================
@@ -29,24 +30,28 @@ The following functions are available:
2930
:rtype: mixed
3031

3132
This method allows you to use dot-notation to search through an array for a specific-key,
32-
and allows the use of a the '*' wildcard. Given the following array:
33+
and allows the use of a the ``*`` wildcard. Given the following array:
3334

3435
.. literalinclude:: array_helper/002.php
36+
:lines: 2-
3537

36-
We can locate the value of 'fizz' by using the search string "foo.buzz.fizz". Likewise, the value
37-
of baz can be found with "foo.bar.baz":
38+
We can locate the value of ``fizz`` by using the search string ``foo.buzz.fizz``. Likewise, the value
39+
of ``baz`` can be found with ``foo.bar.baz``:
3840

3941
.. literalinclude:: array_helper/003.php
42+
:lines: 2-
4043

41-
You can use the asterisk as a wildcard to replace any of the segments. When found, it will search through all
44+
You can use the asterisk (``*``) as a wildcard to replace any of the segments. When found, it will search through all
4245
of the child nodes until it finds it. This is handy if you don't know the values, or if your values
4346
have a numeric index:
4447

4548
.. literalinclude:: array_helper/004.php
49+
:lines: 2-
4650

47-
If the array key contains a dot, then the key can be escaped with a backslash:
51+
If the array key contains a dot (``.``), then the key can be escaped with a backslash (``\``):
4852

4953
.. literalinclude:: array_helper/005.php
54+
:lines: 2-
5055

5156
.. note:: Prior to v4.2.0, ``dot_array_search('foo.bar.baz', ['foo' => ['bar' => 23]])`` returned ``23``
5257
due to a bug. v4.2.0 and later returns ``null``.
@@ -73,21 +78,24 @@ The following functions are available:
7378
from, e.g., the ``find()`` function of a model:
7479

7580
.. literalinclude:: array_helper/006.php
81+
:lines: 2-
7682

7783
Now sort this array by two keys. Note that the method supports the dot-notation
7884
to access values in deeper array levels, but does not support wildcards:
7985

8086
.. literalinclude:: array_helper/007.php
87+
:lines: 2-
8188

82-
The ``$players`` array is now sorted by the 'order' value in each players'
83-
'team' subarray. If this value is equal for several players, these players
84-
will be ordered by their 'position'. The resulting array is:
89+
The ``$players`` array is now sorted by the ``order`` value in each players'
90+
``team`` subarray. If this value is equal for several players, these players
91+
will be ordered by their ``position``. The resulting array is:
8592

8693
.. literalinclude:: array_helper/008.php
94+
:lines: 2-
8795

8896
In the same way, the method can also handle an array of objects. In the example
89-
above it is further possible that each 'player' is represented by an array,
90-
while the 'teams' are objects. The method will detect the type of elements in
97+
above it is further possible that each ``player`` is represented by an array,
98+
while the ``teams`` are objects. The method will detect the type of elements in
9199
each nesting level and handle it accordingly.
92100

93101
.. php:function:: array_flatten_with_dots(iterable $array[, string $id = '']): array
@@ -101,16 +109,19 @@ The following functions are available:
101109
as separators for the keys.
102110

103111
.. literalinclude:: array_helper/009.php
112+
:lines: 2-
104113

105114
On inspection, ``$flattened`` is equal to:
106115

107116
.. literalinclude:: array_helper/010.php
117+
:lines: 2-
108118

109119
Users may use the ``$id`` parameter on their own, but are not required to do so.
110120
The function uses this parameter internally to track the flattened keys. If users
111121
will be supplying an initial ``$id``, it will be prepended to all keys.
112122

113123
.. literalinclude:: array_helper/011.php
124+
:lines: 2-
114125

115126
.. php:function:: array_group_by(array $array, array $indexes[, bool $includeEmpty = false]): array
116127
@@ -126,12 +137,15 @@ The following functions are available:
126137
The example shows some data (i.e. loaded from an API) with nested arrays.
127138

128139
.. literalinclude:: array_helper/012.php
129-
130-
We want to group them first by "gender", then by "hr.department" (max depth = 2).
140+
:lines: 2-
141+
142+
We want to group them first by ``gender``, then by ``hr.department`` (max depth = 2).
131143
First the result when excluding empty values:
132144

133145
.. literalinclude:: array_helper/013.php
134-
146+
:lines: 2-
147+
135148
And here the same code, but this time we want to include empty values:
136149

137150
.. literalinclude:: array_helper/014.php
151+
:lines: 2-

0 commit comments

Comments
 (0)