-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrationReportTest.php
More file actions
88 lines (73 loc) · 2.67 KB
/
MigrationReportTest.php
File metadata and controls
88 lines (73 loc) · 2.67 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
88
<?php
declare(strict_types=1);
namespace KaririCode\Devkit\Tests\Unit\ValueObject;
use KaririCode\Devkit\ValueObject\MigrationReport;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
#[CoversClass(MigrationReport::class)]
final class MigrationReportTest extends TestCase
{
#[Test]
public function hasRedundanciesIsFalseWhenAllEmpty(): void
{
$report = new MigrationReport(
projectRoot: '/app',
redundantPackages: [],
redundantConfigFiles: [],
redundantCachePaths: [],
);
$this->assertFalse($report->hasRedundancies);
$this->assertSame(0, $report->totalItems);
$this->assertFalse($report->hasPackages());
$this->assertFalse($report->hasConfigFiles());
$this->assertFalse($report->hasCachePaths());
}
#[Test]
public function hasRedundanciesIsTrueWhenThereAreRedundantPackages(): void
{
$report = new MigrationReport(
projectRoot: '/app',
redundantPackages: ['phpunit/phpunit' => '^11.0'],
redundantConfigFiles: [],
redundantCachePaths: [],
);
$this->assertTrue($report->hasRedundancies);
$this->assertSame(1, $report->totalItems);
$this->assertTrue($report->hasPackages());
$this->assertFalse($report->hasConfigFiles());
}
#[Test]
public function totalItemsCountsAllCategories(): void
{
$report = new MigrationReport(
projectRoot: '/app',
redundantPackages: ['phpstan/phpstan' => '^2.0', 'vimeo/psalm' => '^6.0'],
redundantConfigFiles: ['phpstan.neon', 'phpcs.xml'],
redundantCachePaths: ['.phpunit.cache'],
);
$this->assertSame(5, $report->totalItems);
$this->assertTrue($report->hasRedundancies);
$this->assertTrue($report->hasPackages());
$this->assertTrue($report->hasConfigFiles());
$this->assertTrue($report->hasCachePaths());
}
#[Test]
public function removeFilesDeletesExistingFiles(): void
{
$tmpDir = sys_get_temp_dir() . '/devkit_test_' . uniqid();
mkdir($tmpDir, 0o777, true);
$fileToRemove = $tmpDir . '/phpstan.neon';
file_put_contents($fileToRemove, 'parameters:');
$report = new MigrationReport(
projectRoot: $tmpDir,
redundantPackages: [],
redundantConfigFiles: ['phpstan.neon'],
redundantCachePaths: [],
);
$removed = $report->removeFiles();
$this->assertSame(1, $removed);
$this->assertFileDoesNotExist($fileToRemove);
rmdir($tmpDir);
}
}