Skip to content

Commit 056db35

Browse files
Added new test to PHPunit testsuite
changed linefeed detection
1 parent 8e1280f commit 056db35

File tree

4 files changed

+71
-65
lines changed

4 files changed

+71
-65
lines changed

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<testsuite name="Github Actions printer for PHPUnit Test Suite">
1515
<directory suffix=".phpt">./test/</directory>
1616
</testsuite>
17+
<testsuite name="Github Actions printer for PHPUnit Test Suite">
18+
<directory suffix=".php">./test/Unit/</directory>
19+
</testsuite>
1720
</testsuites>
1821
<filter>
1922
<whitelist>

src/Functions/helpers.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ static function ($l) {
7676

7777
// Some messages might contain paths. Let's convert thost to relative paths too
7878
$message = relativePath($message);
79-
$message = preg_replace('/%0A$/', '', $message);
79+
$lineFeedPosition = strpos($message, '%0A');
80+
if (is_int($lineFeedPosition) === true) {
81+
$message = substr($message, 0, $lineFeedPosition);
82+
}
8083

8184
$path = relativePath($path);
8285
$file = "file={$path}";

test/Unit/HelperFunctionTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
use mheap\GithubActionsReporter\Printer6;
4+
use mheap\GithubActionsReporter\Printer7;
5+
use mheap\GithubActionsReporter\Printer8;
6+
use mheap\GithubActionsReporter\Printer9;
7+
use PHPUnit\Framework\TestCase;
8+
9+
use function mheap\GithubActionsReporter\Functions\determinePrinter;
10+
11+
class HelperFunctionTest extends TestCase
12+
{
13+
public function getInputsForVersionSelection()
14+
{
15+
yield 'invalid version' => [
16+
'version' => 'aaa',
17+
'expected' => null
18+
];
19+
20+
yield 'minor version 9.4' => [
21+
'version' => '9.4',
22+
'expected' => Printer9::class
23+
];
24+
25+
yield 'major version 9' => [
26+
'version' => '9.0',
27+
'expected' => Printer9::class
28+
];
29+
30+
yield 'minor version 9.1' => [
31+
'version' => '9.1',
32+
'expected' => Printer9::class
33+
];
34+
35+
yield 'minor version 8.2' => [
36+
'version' => '8.2',
37+
'expected' => Printer8::class
38+
];
39+
40+
yield 'patch version 7.0.1' => [
41+
'version' => '7.0.1',
42+
'expected' => Printer7::class
43+
];
44+
45+
yield 'minor version 6.5' => [
46+
'version' => '6.5',
47+
'expected' => Printer6::class
48+
];
49+
50+
yield 'minor version 5' => [
51+
'version' => '5.0',
52+
'expected' => null
53+
];
54+
}
55+
/**
56+
* @dataProvider getInputsForVersionSelection()
57+
*/
58+
public function testVersionSelector($version, $expected): void
59+
{
60+
$result = determinePrinter($version);
61+
62+
self::assertSame($expected, $result);
63+
}
64+
}

test/_files/HelperFunctionTest.php

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +0,0 @@
1-
<?php
2-
3-
use mheap\GithubActionsReporter\Printer6;
4-
use mheap\GithubActionsReporter\Printer7;
5-
use mheap\GithubActionsReporter\Printer8;
6-
use mheap\GithubActionsReporter\Printer9;
7-
use PHPUnit\Framework\TestCase;
8-
9-
use function mheap\GithubActionsReporter\Functions\determinePrinter;
10-
11-
class HelperFunctionTest extends TestCase
12-
{
13-
public function getInputsForVersionSelection()
14-
{
15-
yield 'invalid version' => [
16-
'version' => 'aaa',
17-
'expected' => null
18-
];
19-
20-
yield 'minor version 9.4' => [
21-
'version' => '9.4',
22-
'expected' => Printer9::class
23-
];
24-
25-
yield 'major version 9' => [
26-
'version' => '9.0',
27-
'expected' => Printer9::class
28-
];
29-
30-
yield 'minor version 9.1' => [
31-
'version' => '9.1',
32-
'expected' => Printer9::class
33-
];
34-
35-
yield 'minor version 8.2' => [
36-
'version' => '8.2',
37-
'expected' => Printer8::class
38-
];
39-
40-
yield 'patch version 7.0.1' => [
41-
'version' => '7.0.1',
42-
'expected' => Printer7::class
43-
];
44-
45-
yield 'minor version 6.5' => [
46-
'version' => '6.5',
47-
'expected' => Printer6::class
48-
];
49-
50-
yield 'minor version 5' => [
51-
'version' => '5.0',
52-
'expected' => null
53-
];
54-
}
55-
/**
56-
* @dataProvider getInputsForVersionSelection()
57-
*/
58-
public function testVersionSelector($version, $expected): void
59-
{
60-
$result = determinePrinter($version);
61-
62-
self::assertSame($expected, $result);
63-
}
64-
}

0 commit comments

Comments
 (0)