-
Notifications
You must be signed in to change notification settings - Fork 562
Expand file tree
/
Copy pathProcessedFilesCollectorTest.php
More file actions
62 lines (49 loc) · 1.8 KB
/
ProcessedFilesCollectorTest.php
File metadata and controls
62 lines (49 loc) · 1.8 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
<?php declare(strict_types = 1);
namespace PHPStan\Analyser;
use PHPUnit\Framework\TestCase;
use function array_keys;
class ProcessedFilesCollectorTest extends TestCase
{
public function testEmpty(): void
{
$collector = new ProcessedFilesCollector();
$this->assertSame([], $collector->getTopMostAnalysedFiles(5));
}
public function testSingleFileNotReported(): void
{
$collector = new ProcessedFilesCollector();
$collector->addProcessedFiles(['/path/to/file.php']);
$this->assertSame([], $collector->getTopMostAnalysedFiles(5));
}
public function testTopMostAnalysedFiles(): void
{
$collector = new ProcessedFilesCollector();
// Simulate: file A uses trait T1 and T2, file B uses trait T1
$collector->addProcessedFiles(['/path/to/A.php', '/path/to/T1.php', '/path/to/T2.php']);
$collector->addProcessedFiles(['/path/to/B.php', '/path/to/T1.php']);
$top = $collector->getTopMostAnalysedFiles(5);
$this->assertSame(['/path/to/T1.php' => 2], $top);
}
public function testLimit(): void
{
$collector = new ProcessedFilesCollector();
// Create 7 trait files with varying usage counts
for ($i = 0; $i < 7; $i++) {
$files = ['/path/to/main' . $i . '.php'];
for ($j = 0; $j <= $i; $j++) {
$files[] = '/path/to/trait' . $j . '.php';
}
$collector->addProcessedFiles($files);
}
$top = $collector->getTopMostAnalysedFiles(3);
$this->assertCount(3, $top);
// trait0.php used 7 times, trait1.php 6 times, trait2.php 5 times
$files = array_keys($top);
$this->assertSame('/path/to/trait0.php', $files[0]);
$this->assertSame(7, $top['/path/to/trait0.php']);
$this->assertSame('/path/to/trait1.php', $files[1]);
$this->assertSame(6, $top['/path/to/trait1.php']);
$this->assertSame('/path/to/trait2.php', $files[2]);
$this->assertSame(5, $top['/path/to/trait2.php']);
}
}