forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentDetectedErrorFormatterTest.php
More file actions
87 lines (72 loc) · 2.32 KB
/
AgentDetectedErrorFormatterTest.php
File metadata and controls
87 lines (72 loc) · 2.32 KB
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
82
83
84
85
86
87
<?php declare(strict_types = 1);
namespace PHPStan\Command\ErrorFormatter;
use Override;
use PHPStan\Testing\ErrorFormatterTestCase;
use function putenv;
class AgentDetectedErrorFormatterTest extends ErrorFormatterTestCase
{
#[Override]
protected function setUp(): void
{
putenv('AI_AGENT');
putenv('CURSOR_TRACE_ID');
putenv('CURSOR_AGENT');
putenv('GEMINI_CLI');
putenv('CODEX_SANDBOX');
putenv('AUGMENT_AGENT');
putenv('OPENCODE_CLIENT');
putenv('OPENCODE');
putenv('CLAUDECODE');
putenv('CLAUDE_CODE');
putenv('REPL_ID');
}
#[Override]
protected function tearDown(): void
{
putenv('AI_AGENT');
putenv('CLAUDE_CODE');
}
public function testIsAgentDetectedReturnsFalse(): void
{
$formatter = new AgentDetectedErrorFormatter(new JsonErrorFormatter(false));
$this->assertFalse($formatter->isAgentDetected());
}
public function testIsAgentDetectedReturnsTrueWithAiAgent(): void
{
putenv('AI_AGENT=test');
$formatter = new AgentDetectedErrorFormatter(new JsonErrorFormatter(false));
$this->assertTrue($formatter->isAgentDetected());
}
public function testIsAgentDetectedReturnsTrueWithClaudeCode(): void
{
putenv('CLAUDE_CODE=1');
$formatter = new AgentDetectedErrorFormatter(new JsonErrorFormatter(false));
$this->assertTrue($formatter->isAgentDetected());
}
public function testFormatErrorsProducesValidJson(): void
{
$formatter = new AgentDetectedErrorFormatter(new JsonErrorFormatter(false));
$exitCode = $formatter->formatErrors(
$this->getAnalysisResult(1, 0),
$this->getOutput(),
);
$this->assertSame(1, $exitCode);
$this->assertJsonStringEqualsJsonString(
'{"totals":{"errors":0,"file_errors":1},"files":{"/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with \\"spaces\\" and unicode 😃.php":{"errors":1,"messages":[{"message":"Foo","line":4,"ignorable":true}]}},"errors":[]}',
$this->getOutputContent(),
);
}
public function testFormatErrorsNoErrors(): void
{
$formatter = new AgentDetectedErrorFormatter(new JsonErrorFormatter(false));
$exitCode = $formatter->formatErrors(
$this->getAnalysisResult(0, 0),
$this->getOutput(),
);
$this->assertSame(0, $exitCode);
$this->assertJsonStringEqualsJsonString(
'{"totals":{"errors":0,"file_errors":0},"files":{},"errors":[]}',
$this->getOutputContent(),
);
}
}