-
-
Notifications
You must be signed in to change notification settings - Fork 264
/
Copy pathGithubActionReporterTest.php
81 lines (68 loc) · 2.51 KB
/
GithubActionReporterTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\CI;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\CI\GithubActionReporter;
use Symfony\Component\Console\Output\BufferedOutput;
class GithubActionReporterTest extends TestCase
{
public function testIsGithubActionEnvironment()
{
$prev = getenv('GITHUB_ACTIONS');
putenv('GITHUB_ACTIONS');
try {
self::assertFalse(GithubActionReporter::isGithubActionEnvironment());
putenv('GITHUB_ACTIONS=1');
self::assertTrue(GithubActionReporter::isGithubActionEnvironment());
} finally {
putenv('GITHUB_ACTIONS'.($prev ? "=$prev" : ''));
}
}
/**
* @dataProvider annotationsFormatProvider
*/
public function testAnnotationsFormat(string $type, string $message, ?string $file, ?int $line, ?int $col, string $expected)
{
$reporter = new GithubActionReporter($buffer = new BufferedOutput());
$reporter->{$type}($message, $file, $line, $col);
self::assertSame($expected.\PHP_EOL, $buffer->fetch());
}
public static function annotationsFormatProvider(): iterable
{
yield 'warning' => ['warning', 'A warning', null, null, null, '::warning::A warning'];
yield 'error' => ['error', 'An error', null, null, null, '::error::An error'];
yield 'debug' => ['debug', 'A debug log', null, null, null, '::debug::A debug log'];
yield 'with message to escape' => [
'debug',
"There are 100% chances\nfor this to be escaped properly\rRight?",
null,
null,
null,
'::debug::There are 100%25 chances%0Afor this to be escaped properly%0DRight?',
];
yield 'with meta' => [
'warning',
'A warning',
'foo/bar.php',
2,
4,
'::warning file=foo/bar.php,line=2,col=4::A warning',
];
yield 'with file property to escape' => [
'warning',
'A warning',
'foo,bar:baz%quz.php',
2,
4,
'::warning file=foo%2Cbar%3Abaz%25quz.php,line=2,col=4::A warning',
];
yield 'without file ignores col & line' => ['warning', 'A warning', null, 2, 4, '::warning::A warning'];
}
}