Skip to content

Commit e820aa3

Browse files
committed
Auto-review required dependency matching
1 parent 2444763 commit e820aa3

File tree

4 files changed

+94
-3
lines changed

4 files changed

+94
-3
lines changed

.github/workflows/test-phpunit.yml

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
- .github/workflows/test-phpunit.yml
2222

2323
jobs:
24-
tests:
24+
unit-tests:
2525
name: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
2626
runs-on: ubuntu-20.04
2727
if: "!contains(github.event.head_commit.message, '[ci skip]')"
@@ -126,7 +126,7 @@ jobs:
126126
run: echo "TACHYCARDIA_MONITOR_GA=enabled" >> $GITHUB_ENV
127127

128128
- name: Test with PHPUnit
129-
run: script -e -c "vendor/bin/phpunit --color=always"
129+
run: script -e -c "vendor/bin/phpunit --color=always --exclude-group=auto-review"
130130
env:
131131
DB: ${{ matrix.db-platforms }}
132132
TERM: xterm-256color
@@ -141,9 +141,45 @@ jobs:
141141
COVERALLS_PARALLEL: true
142142
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
143143

144+
auto-review-tests:
145+
name: Automatic Code Review
146+
needs: [unit-tests]
147+
runs-on: ubuntu-20.04
148+
149+
steps:
150+
- name: Checkout
151+
uses: actions/checkout@v2
152+
153+
- name: Setup PHP
154+
uses: shivammathur/setup-php@v2
155+
with:
156+
php-version: '8.0'
157+
coverage: none
158+
159+
- name: Get composer cache directory
160+
id: composercache
161+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
162+
163+
- name: Cache dependencies
164+
uses: actions/cache@v2
165+
with:
166+
path: ${{ steps.composercache.outputs.dir }}
167+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
168+
restore-keys: ${{ runner.os }}-composer-
169+
170+
- name: Install dependencies
171+
run: |
172+
composer update --ansi --no-interaction
173+
composer remove --ansi --dev --unused -W -- rector/rector phpstan/phpstan friendsofphp/php-cs-fixer nexusphp/cs-config codeigniter/coding-standard
174+
env:
175+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
176+
177+
- name: Run AutoReview Tests
178+
run: vendor/bin/phpunit --color=always --group=auto-review
179+
144180
coveralls-finish:
145181
if: github.repository_owner == 'codeigniter4'
146-
needs: [tests]
182+
needs: [unit-tests]
147183
runs-on: ubuntu-20.04
148184

149185
steps:

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"autoload-dev": {
5151
"psr-4": {
5252
"CodeIgniter\\": "tests/system/",
53+
"CodeIgniter\\AutoReview\\": "tests/AutoReview/",
5354
"Utils\\": "utils/"
5455
}
5556
},

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
</coverage>
3737

3838
<testsuites>
39+
<testsuite name="AutoReview">
40+
<directory>./tests/AutoReview</directory>
41+
</testsuite>
3942
<testsuite name="System">
4043
<directory>./tests/system</directory>
4144
<exclude>./tests/system/Database</exclude>

tests/AutoReview/ComposerJsonTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace CodeIgniter\AutoReview;
15+
16+
use JsonException;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* @internal
21+
*
22+
* @coversNothing
23+
* @group auto-review
24+
*/
25+
final class ComposerJsonTest extends TestCase
26+
{
27+
public function testFrameworkRequireIsTheSameWithDevRequire(): void
28+
{
29+
$devComposer = $this->getComposerJson(dirname(__DIR__, 2) . '/composer.json');
30+
$frameworkComposer = $this->getComposerJson(dirname(__DIR__, 2) . '/admin/framework/composer.json');
31+
32+
$this->assertSame(
33+
$devComposer['require'],
34+
$frameworkComposer['require'],
35+
'The framework\'s "require" section is not updated with the main composer.json.'
36+
);
37+
}
38+
39+
private function getComposerJson(string $path): array
40+
{
41+
try {
42+
return json_decode((string) file_get_contents($path), true, 512, JSON_THROW_ON_ERROR);
43+
} catch (JsonException $e) {
44+
$this->fail(sprintf(
45+
'The composer.json at "%s" is not readable or does not exist. Error was "%s".',
46+
clean_path($path),
47+
$e->getMessage()
48+
));
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)