Skip to content

Commit

Permalink
MNT Resolve CI problems (#3)
Browse files Browse the repository at this point in the history
- Tell phpcs what to sniff
- Throw a hard error if we can't bootstrap tests correctly
- Force Tokens.php to be run for constant declarations
  • Loading branch information
GuySartorelli authored Nov 14, 2023
1 parent 47f0c4d commit 8bd191f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 7 additions & 4 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?xml version="1.0"?>
<ruleset name="PSR12">
<rule ref="PSR12"/>
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>tests/bootstrap\.php</exclude-pattern>
</rule>
<rule ref="PSR12"/>
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>tests/bootstrap\.php</exclude-pattern>
</rule>

<file>./src</file>
<file>./tests</file>
</ruleset>
12 changes: 12 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

// php_codesniffer autoloader

use PHP_CodeSniffer\Util\Tokens;

$autoloadCandidates = [
// running from package itself as root
__DIR__ . '/../vendor/squizlabs/php_codesniffer/autoload.php',
Expand All @@ -17,6 +20,15 @@
}
}

if (!$autoloaded) {
throw new RuntimeException("Couldn't find autoloader");
}

// Required to correctly run constant definitions in CI, though not needed locally for some reason.
// Referencing a static property on the Tokens class forces the file containing it to be autoloaded,
// which results in the constants (defined in the same file) being defined ahead of time.
Tokens::$operators;

if (!defined('PHP_CODESNIFFER_VERBOSITY')) {
define('PHP_CODESNIFFER_VERBOSITY', 0);
}
Expand Down

0 comments on commit 8bd191f

Please sign in to comment.