|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tests\TestSuite\Formatter; |
| 6 | + |
| 7 | +use CssLint\Formatter\GithubActionsFormatter; |
| 8 | +use CssLint\Formatter\FormatterFactory; |
| 9 | +use CssLint\Formatter\FormatterManager; |
| 10 | +use CssLint\LintError; |
| 11 | +use CssLint\LintErrorKey; |
| 12 | +use Exception; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | +use CssLint\Position; |
| 15 | + |
| 16 | +class GithubActionsFormatterTest extends TestCase |
| 17 | +{ |
| 18 | + public function testGetNameReturnsGithubActions(): void |
| 19 | + { |
| 20 | + $formatter = new GithubActionsFormatter(); |
| 21 | + $this->assertSame('github-actions', $formatter->getName()); |
| 22 | + } |
| 23 | + |
| 24 | + public function testStartLintingOutputsGroup(): void |
| 25 | + { |
| 26 | + $formatter = new GithubActionsFormatter(); |
| 27 | + $this->expectOutputString("::group::Lint file.css" . PHP_EOL); |
| 28 | + $formatter->startLinting('file.css'); |
| 29 | + } |
| 30 | + |
| 31 | + public function testPrintFatalErrorWithThrowable(): void |
| 32 | + { |
| 33 | + $formatter = new GithubActionsFormatter(); |
| 34 | + $error = new Exception('fatal error'); |
| 35 | + $this->expectOutputString("::error file=file.css::fatal error" . PHP_EOL); |
| 36 | + $formatter->printFatalError('file.css', $error); |
| 37 | + } |
| 38 | + |
| 39 | + public function testPrintFatalErrorWithoutSource(): void |
| 40 | + { |
| 41 | + $formatter = new GithubActionsFormatter(); |
| 42 | + $this->expectOutputString("::error ::some error" . PHP_EOL); |
| 43 | + $formatter->printFatalError(null, 'some error'); |
| 44 | + } |
| 45 | + |
| 46 | + public function testPrintLintError(): void |
| 47 | + { |
| 48 | + $positionArr = ['line' => 10, 'column' => 5]; |
| 49 | + $lintError = new LintError( |
| 50 | + key: LintErrorKey::INVALID_AT_RULE_DECLARATION, |
| 51 | + message: 'issue found', |
| 52 | + start: new Position($positionArr['line'], $positionArr['column']), |
| 53 | + end: new Position($positionArr['line'], $positionArr['column']) |
| 54 | + ); |
| 55 | + |
| 56 | + $formatter = new GithubActionsFormatter(); |
| 57 | + $this->expectOutputString("::error file=file.css,line=10,col=5::issue found" . PHP_EOL); |
| 58 | + $formatter->printLintError('file.css', $lintError); |
| 59 | + } |
| 60 | + |
| 61 | + public function testEndLintingOutputsEndGroup(): void |
| 62 | + { |
| 63 | + $formatter = new GithubActionsFormatter(); |
| 64 | + $this->expectOutputString( |
| 65 | + "::notice ::Success: file.css is valid." . PHP_EOL . |
| 66 | + "::endgroup::" . PHP_EOL |
| 67 | + ); |
| 68 | + $formatter->endLinting('file.css', true); |
| 69 | + } |
| 70 | + |
| 71 | + public function testFactoryIntegration(): void |
| 72 | + { |
| 73 | + $factory = new FormatterFactory(); |
| 74 | + $available = $factory->getAvailableFormatters(); |
| 75 | + $this->assertContains('github-actions', $available); |
| 76 | + |
| 77 | + $manager = $factory->create('github-actions'); |
| 78 | + $this->assertInstanceOf(FormatterManager::class, $manager); |
| 79 | + } |
| 80 | +} |
0 commit comments