Skip to content

Commit c1fc842

Browse files
authored
Merge pull request #5538 from paulbalandan/auto-review-composer
Auto-review required dependency matching in composer.json
2 parents b847682 + 08f3d30 commit c1fc842

File tree

5 files changed

+105
-1
lines changed

5 files changed

+105
-1
lines changed

.github/workflows/test-autoreview.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Automatic Code Review
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- composer.json
7+
- spark
8+
- '**.php'
9+
- .github/workflows/test-autoreview.yml
10+
push:
11+
paths:
12+
- composer.json
13+
- spark
14+
- '**.php'
15+
- .github/workflows/test-autoreview.yml
16+
17+
jobs:
18+
auto-review-tests:
19+
name: Automatic Code Review
20+
runs-on: ubuntu-20.04
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
26+
- name: Setup PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: '8.0'
30+
coverage: none
31+
32+
- name: Get composer cache directory
33+
id: composercache
34+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
35+
36+
- name: Cache dependencies
37+
uses: actions/cache@v2
38+
with:
39+
path: ${{ steps.composercache.outputs.dir }}
40+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
41+
restore-keys: ${{ runner.os }}-composer-
42+
43+
- name: Install dependencies
44+
run: composer update --ansi
45+
env:
46+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
47+
48+
- name: Run AutoReview Tests
49+
run: vendor/bin/phpunit --color=always --group=auto-review --no-coverage

.github/workflows/test-phpunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

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)