Skip to content

Commit 63f0a87

Browse files
authored
Merge pull request #11 from tattersoftware/tools
Bugfix strict database
2 parents fef2498 + d23d501 commit 63f0a87

File tree

10 files changed

+90
-8
lines changed

10 files changed

+90
-8
lines changed

.github/workflows/analyze.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
php-version: ${{ matrix.php-versions }}
4141
tools: composer, pecl, phpunit
4242
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3
43+
env:
44+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4345

4446
- name: Get composer cache directory
4547
id: composer-cache
@@ -65,7 +67,12 @@ jobs:
6567
key: ${{ runner.os }}-phpstan-${{ github.sha }}
6668
restore-keys: ${{ runner.os }}-phpstan-
6769

68-
- name: Install dependencies
70+
- name: Install dependencies (limited)
71+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
72+
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
73+
74+
- name: Install dependencies (authenticated)
75+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
6976
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
7077
env:
7178
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

.github/workflows/compare.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# When a PR is opened or a push is made, compare
2+
# code for backwards compatibility.
3+
name: RoaveBC
4+
5+
on:
6+
pull_request:
7+
branches:
8+
- develop
9+
paths:
10+
- 'src/**'
11+
12+
jobs:
13+
compare:
14+
name: Compare for Backwards Compatibility
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Run comparison (limited)
22+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
23+
uses: docker://nyholm/roave-bc-check-ga
24+
25+
- name: Run comparison (authenticated)
26+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
27+
uses: docker://nyholm/roave-bc-check-ga
28+
env:
29+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

.github/workflows/test.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
tools: composer, pecl, phpunit
3232
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3
3333
coverage: xdebug
34+
env:
35+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3436

3537
- name: Get composer cache directory
3638
id: composer-cache
@@ -43,7 +45,12 @@ jobs:
4345
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
4446
restore-keys: ${{ runner.os }}-composer-
4547

46-
- name: Install dependencies
48+
- name: Install dependencies (limited)
49+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
50+
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
51+
52+
- name: Install dependencies (authenticated)
53+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
4754
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
4855
env:
4956
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require-dev": {
2626
"codeigniter4/codeigniter4": "dev-develop",
27-
"tatter/tools": "^1.7"
27+
"tatter/tools": "^1.8"
2828
},
2929
"autoload": {
3030
"psr-4": {

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ parameters:
1212
ignoreErrors:
1313
universalObjectCratesClasses:
1414
- CodeIgniter\Entity
15+
- CodeIgniter\Entity\Entity
1516
- Faker\Generator
1617
scanDirectories:
1718
- vendor/codeigniter4/codeigniter4/system/Helpers

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
<element key="precision">
5656
<integer>2</integer>
5757
</element>
58+
<element key="collectBare">
59+
<boolean>true</boolean>
60+
</element>
5861
<element key="tabulate">
5962
<boolean>true</boolean>
6063
</element>
@@ -86,6 +89,7 @@
8689
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
8790

8891
<!-- Database configuration -->
92+
<env name="database.tests.strictOn" value="true"/>
8993
<!-- Uncomment to use alternate testing database configuration
9094
<env name="database.tests.hostname" value="localhost"/>
9195
<env name="database.tests.database" value="tests"/>

roave-bc-check.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
ignoreErrors:
3+
- '#\[BC\] SKIPPED: .+ could not be found in the located source#'

src/Audits.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ public function __construct(AuditsConfig $config)
3434
* Checks the session for a logged in user based on config
3535
*
3636
* @return int The current user ID, 0 for "not logged in", -1 for CLI
37+
*
38+
* @deprecated This will be removed in the next major release; use codeigniter4/authentication-implementation
3739
*/
3840
public function sessionUserId(): int
3941
{
4042
if (is_cli())
4143
{
42-
return -1;
44+
return 0;
4345
}
4446

4547
return session($this->config->sessionUserId) ?? 0;

tests/_support/DatabaseTestCase.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,22 @@ public function seeAudit(array $values)
7070
// Check each audit in the queue for a match
7171
foreach ($queue as $audit)
7272
{
73+
$found = true;
74+
7375
// Check each value against the audit
7476
foreach ($values as $key => $value)
7577
{
7678
if ($audit[$key] != $value)
7779
{
78-
break 2;
80+
$found = false;
81+
break;
7982
}
8083
}
8184

82-
$found = true;
83-
break;
85+
if ($found)
86+
{
87+
break;
88+
}
8489
}
8590

8691
$this->assertTrue($found, 'Audit not found in queue: ' . print_r($values, true));

tests/unit/TraitTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Tests\Support\DatabaseTestCase;
4+
use Tests\Support\Models\WidgetModel;
45

56
class TraitTest extends DatabaseTestCase
67
{
@@ -16,12 +17,35 @@ public function testInsertAddsAudit()
1617
'source_id' => $result,
1718
'event' => 'insert',
1819
'summary' => '5 fields',
19-
'user_id' => -1,
20+
'user_id' => 0,
2021
];
2122

2223
$queue = service('audits')->getQueue();
2324

2425
$this->assertCount(1, $queue);
2526
$this->seeAudit($expected);
2627
}
28+
29+
public function testUpdateAddsAudit()
30+
{
31+
$widget = fake(WidgetModel::class);
32+
$widgetId = $widget->id; // @phpstan-ignore-line
33+
34+
$this->model->update($widgetId, [
35+
'name' => 'Banana Widget',
36+
]);
37+
38+
$expected = [
39+
'source' => 'widgets',
40+
'source_id' => [$widgetId],
41+
'event' => 'update',
42+
'summary' => '2 fields',
43+
'user_id' => 0,
44+
];
45+
46+
$queue = service('audits')->getQueue();
47+
48+
$this->assertCount(2, $queue);
49+
$this->seeAudit($expected);
50+
}
2751
}

0 commit comments

Comments
 (0)