Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.gitignore export-ignore
/.github export-ignore
phpunit.xml.dist export-ignore
phpunit10.xml.dist export-ignore
phpcs.xml.dist export-ignore
22 changes: 20 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,18 @@ jobs:
- name: Lint
run: composer phplint -- --checkstyle | cs2pr

- name: Run unit tests
- name: Grab PHPUnit version
id: phpunit_version
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT

- name: "Run unit tests (PHPUnit < 10)"
if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
run: composer phpunit

- name: "Run unit tests (PHPUnit 10+)"
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
run: composer phpunit10

coverage:
needs: test
# Don't run on forks.
Expand Down Expand Up @@ -124,9 +133,18 @@ jobs:
- name: Lint
run: composer phplint -- --checkstyle | cs2pr

- name: Run the unit tests with code coverage
- name: Grab PHPUnit version
id: phpunit_version
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT

- name: "Run the unit tests with code coverage (PHPUnit < 10)"
if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
run: composer coverage

- name: "Run the unit tests with code coverage (PHPUnit 10+)"
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
run: composer coverage10

- name: Upload coverage results to Coveralls
if: ${{ success() }}
uses: coverallsapp/github-action@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/vendor/
/composer.lock
phpunit.xml
phpunit10.xml
.phpunit.result.cache
.phpcs.xml
phpcs.xml
14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"php-parallel-lint/php-console-color": "^1.0.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.1",
"php-parallel-lint/php-parallel-lint": "^1.0",
"php-parallel-lint/php-var-dump-check": "0.*",
"php-parallel-lint/php-code-style": "^2.0"
Expand Down Expand Up @@ -55,9 +55,15 @@
"phpunit": [
"@php ./vendor/phpunit/phpunit/phpunit --no-coverage"
],
"phpunit10": [
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage"
],
"coverage": [
"@php ./vendor/phpunit/phpunit/phpunit"
],
"coverage10": [
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist"
],
"build": [
"@phplint",
"@vardumpcheck",
Expand All @@ -70,8 +76,10 @@
"vardumpcheck": "Check PHP files for forgotten variable dumps",
"phpcs": "Check PHP code style",
"fixcs": "Auto-fix PHP code style",
"phpunit": "PHP unit",
"coverage": "PHP unit with code coverage",
"phpunit": "Run the unit tests on PHPUnit 4.x - 9.x without code coverage.",
"phpunit10": "Run the unit tests on PHPUnit 10.x without code coverage.",
"coverage": "Run the unit tests on PHPUnit 4.x - 9.x with code coverage.",
"coverage10": "Run the unit tests on PHPUnit 10.x with code coverage.",
"build": "Run all checks"
}
}
44 changes: 44 additions & 0 deletions phpunit10.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="true"
bootstrap="./vendor/autoload.php"
colors="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
failOnWarning="true"
failOnNotice="true"
failOnDeprecation="true"
requireCoverageMetadata="true"
>

<testsuites>
<testsuite name="PHP-Console-Highlighter">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</source>

<coverage includeUncoveredFiles="true" ignoreDeprecatedCodeUnits="true">
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage/"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>

<php>
<ini name="memory_limit" value="256M"/>
</php>
</phpunit>
10 changes: 5 additions & 5 deletions tests/ColorLinesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ColorLinesTest extends HighlighterTestCase
{
/** @var string */
private $input = array(
private static $input = array(
7 => array (
0 => array (
0 => 'token_keyword',
Expand Down Expand Up @@ -70,22 +70,22 @@ public function testColorLines($input, $expected, $withTheme = true)
*
* @return array
*/
public function dataColorLines()
public static function dataColorLines()
{
return array(
'No lines' => array(
'input' => array(),
'expected' => array(),
),
'With theme' => array(
'input' => $this->input,
'input' => self::$input,
'expected' => array(
7 => '<token_keyword>function </token_keyword><token_default>bar</token_default><token_keyword>(</token_keyword><token_default>$param</token_default><token_unknown>) </token_unknown><token_keyword>{}</token_keyword>',
),
'withTheme' => true,
),
'Without theme' => array(
'input' => $this->input,
'input' => self::$input,
'expected' => array(
7 => 'function bar($param) {}',
),
Expand All @@ -110,7 +110,7 @@ public function testColorLinesWithRealColors()
$method->setAccessible(true);

$highlighter = new Highlighter($color);
$output = $method->invoke($highlighter, $this->input);
$output = $method->invoke($highlighter, self::$input);
$method->setAccessible(false);

$this->assertSame($expected, $output);
Expand Down
2 changes: 1 addition & 1 deletion tests/GetCodeSnippetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testGetCodeSnippet($expected, $lineNo, $linesBeforeAfter = 2)
*
* @return array
*/
public function dataGetCodeSnippet()
public static function dataGetCodeSnippet()
{
return array(
'Snippet at start of code - line 1' => array(
Expand Down
8 changes: 4 additions & 4 deletions tests/GetWholeFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GetWholeFileTest extends HighlighterTestCase
private $highlighter;

/** @var string */
private $input = <<<'EOL'
private static $input = <<<'EOL'
<?php

namespace FooBar;
Expand Down Expand Up @@ -68,7 +68,7 @@ public function testGetWholeFile($input, $expected)
*
* @return array
*/
public function dataGetWholeFile()
public static function dataGetWholeFile()
{
return array(
'Empty source' => array(
Expand All @@ -85,7 +85,7 @@ public function dataGetWholeFile()
EOL
),
'Multi-line' => array(
'input' => $this->input,
'input' => self::$input,
'expected' => <<<'EOL'
<token_default><?php</token_default>

Expand Down Expand Up @@ -135,7 +135,7 @@ public function testGetWholeFileWithLineNumbers()
<line_number>15| </line_number><token_default>?></token_default>
EOL;

$output = $this->highlighter->getWholeFileWithLineNumbers($this->input);
$output = $this->highlighter->getWholeFileWithLineNumbers(self::$input);
// Allow unit tests to succeed on non-*nix systems.
$output = str_replace(array("\r\n", "\r"), "\n", $output);

Expand Down
18 changes: 9 additions & 9 deletions tests/TokenizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testEmptyFiles($original, $expected)
*
* @return array
*/
public function dataEmptyFiles()
public static function dataEmptyFiles()
{
return array(
'Empty file' => array(
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testPhpTags($original, $expected)
*
* @return array
*/
public function dataPhpTags()
public static function dataPhpTags()
{
return array(
'"Long" open tag with close tag' => array(
Expand Down Expand Up @@ -135,7 +135,7 @@ public function testMagicConstants($original, $expected)
*
* @return array
*/
public function dataMagicConstants()
public static function dataMagicConstants()
{
$magicConstants = array(
'__FILE__',
Expand Down Expand Up @@ -184,7 +184,7 @@ public function testMiscTokens($original, $expected)
*
* @return array
*/
public function dataMiscTokens()
public static function dataMiscTokens()
{
return array(
'Constant (T_STRING)' => array(
Expand Down Expand Up @@ -263,7 +263,7 @@ public function testComments($original, $expected)
*
* @return array
*/
public function dataComments()
public static function dataComments()
{
return array(
'Doc block: single line' => array(
Expand Down Expand Up @@ -378,7 +378,7 @@ public function testTextStrings($original, $expected)
*
* @return array
*/
public function dataTextStrings()
public static function dataTextStrings()
{
return array(
'Single quoted text string' => array(
Expand Down Expand Up @@ -499,7 +499,7 @@ public function testInlineHtml($original, $expected)
*
* @return array
*/
public function dataInlineHtml()
public static function dataInlineHtml()
{
return array(
'Inline HTML' => array(
Expand Down Expand Up @@ -532,7 +532,7 @@ public function testNameTokens($original, $expected)
*
* @return array
*/
public function dataNameTokens()
public static function dataNameTokens()
{
$data = array(
'Unqualified function call' => array(
Expand Down Expand Up @@ -623,7 +623,7 @@ public function testKeywordsAndOperators($original, $expected)
*
* @return array
*/
public function dataKeywordsAndOperators()
public static function dataKeywordsAndOperators()
{
return array(
'Keywords: instanceof' => array(
Expand Down