Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
php ./vendor/simplemachines/build-tools/check-smf-index.php
php ./vendor/simplemachines/build-tools/check-version.php

- name: Running the auto review test suite
run: vendor/bin/phpunit --testsuite auto-review

lint:
runs-on: ubuntu-latest
strategy:
Expand Down
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@
"test": "phpunit --no-coverage",
"test-integration": "phpunit --no-coverage --testsuite integration",
"test-unit": "phpunit --no-coverage --testsuite unit"
},
"scripts-descriptions": {
"lint": "Check changed PHP files with PHP-CS-Fixer. Does not work on Windows!",
"lint-fix": "Fix coding standards in changed PHP files with PHP-CS-Fixer. Does not work on Windows!",
"test": "Run the PHPUnit test suite.",
"test-integration": "Run the PHPUnit integration test suite.",
"test-unit": "Run the PHPUnit unit test suite."
}
}
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="auto-review">
<directory>tests/AutoReview</directory>
</testsuite>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
Expand Down
94 changes: 94 additions & 0 deletions tests/AutoReview/ComposerFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

namespace SMF\Tests\AutoReview;

use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;

#[CoversNothing]
final class ComposerFileTest extends TestCase
{
public function testScriptsHaveDescriptions(): void
{
$composer_json = $this->readComposerJson();

$this->assertArrayHasKey('scripts', $composer_json);
$this->assertArrayHasKey('scripts-descriptions', $composer_json);

$descriptions = array_keys($composer_json['scripts-descriptions']);
$event_scripts = [
'pre-install-cmd',
'post-install-cmd',
'pre-update-cmd',
'post-update-cmd',
'pre-status-cmd',
'post-status-cmd',
'pre-archive-cmd',
'post-archive-cmd',
'pre-autoload-dump',
'post-autoload-dump',
'post-root-package-install',
'post-create-project-cmd',
'pre-operations-exec',
'pre-package-install',
'post-package-install',
'pre-package-update',
'post-package-update',
'pre-package-uninstall',
'post-package-uninstall',
'init',
'command',
'pre-file-download',
'post-file-download',
'pre-command-run',
'pre-pool-create',
];
$scripts = array_diff(
array_keys($composer_json['scripts']),
$event_scripts,
);

$this->assertSame(
[],
array_diff($scripts, $descriptions),
'There should be no scripts with missing descriptions.',
);

$this->assertSame(
[],
array_diff($descriptions, $scripts),
'There should be no superfluous descriptions for undefined scripts.',
);
}

public function testPlatformPhpVersionSatisfiesPhpRequirement(): void
{
$composer_json = $this->readComposerJson();

$this->assertArrayHasKey('require', $composer_json);
$this->assertArrayHasKey('php', $composer_json['require']);
$this->assertArrayHasKey('config', $composer_json);
$this->assertArrayHasKey('platform', $composer_json['config']);
$this->assertArrayHasKey('php', $composer_json['config']['platform']);

$php_requirement = $composer_json['require']['php'];
$platform_php = $composer_json['config']['platform']['php'];

$this->assertTrue(
\Composer\Semver\Semver::satisfies($platform_php, $php_requirement),
"Platform PHP version '{$platform_php}' does not satisfy PHP requirement '{$php_requirement}'.",
);
}

/**
* @return array<string, mixed>
*/
private function readComposerJson(): array
{
$composer_json_content = (string) file_get_contents(__DIR__ . '/../../composer.json');

return json_decode($composer_json_content, true, 512, JSON_THROW_ON_ERROR);
}
}
8 changes: 8 additions & 0 deletions tests/AutoReview/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

// Try to handle it with the upper level index.php. (it should know what to do.)
if (file_exists(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'index.php')) {
include dirname(__DIR__) . DIRECTORY_SEPARATOR . 'index.php';
} else {
exit;
}
Loading