Repository navigation
Expand file tree
/
Copy pathFileHashComputerTest.php
More file actions
84 lines (60 loc) · 2.81 KB
/
Copy pathFileHashComputerTest.php
File metadata and controls
84 lines (60 loc) · 2.81 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
<?php
declare(strict_types=1);
namespace Symplify\EasyCodingStandard\Tests\ChangedFilesDetector\FileHashComputer;
use Override;
use Symfony\Component\Filesystem\Filesystem;
use Symplify\EasyCodingStandard\Caching\FileHashComputer;
use Symplify\EasyCodingStandard\Testing\PHPUnit\AbstractTestCase;
final class FileHashComputerTest extends AbstractTestCase
{
private const string INCLUDED_CONFIG_FILE = __DIR__ . '/Fixture/another-one.php';
private FileHashComputer $fileHashComputer;
private Filesystem $filesystem;
#[Override]
protected function setUp(): void
{
parent::setUp();
$this->fileHashComputer = $this->make(FileHashComputer::class);
$this->filesystem = $this->make(Filesystem::class);
}
public function testInvalidateCacheOnConfigurationChange(): void
{
// A. create on another one with fixer
$this->filesystem->copy(__DIR__ . '/Source/first_config.php', self::INCLUDED_CONFIG_FILE, true);
$fileOneHash = $this->fileHashComputer->computeConfig(
__DIR__ . '/Fixture/config-including-another-one.php'
);
// B. create on another one with no fixer
$this->filesystem->copy(__DIR__ . '/Source/empty_config.php', self::INCLUDED_CONFIG_FILE, true);
$fileTwoHash = $this->fileHashComputer->computeConfig(
__DIR__ . '/Fixture/config-including-another-one.php'
);
$this->assertNotSame($fileOneHash, $fileTwoHash);
$this->filesystem->remove(self::INCLUDED_CONFIG_FILE);
}
public function testInvalidateCacheOnLocalCheckerChange(): void
{
$localSniffFile = __DIR__ . '/Source/LocalSniff.php';
$originalContents = $this->filesystem->readFile($localSniffFile);
$originalHash = $this->fileHashComputer->computeConfig(__DIR__ . '/Source/local_sniff_config.php');
try {
$this->filesystem->dumpFile($localSniffFile, $originalContents . "\n// changed\n");
$changedHash = $this->fileHashComputer->computeConfig(__DIR__ . '/Source/local_sniff_config.php');
} finally {
$this->filesystem->dumpFile($localSniffFile, $originalContents);
}
$this->assertNotSame($originalHash, $changedHash);
}
public function testPhpFileHash(): void
{
$fileOne = __DIR__ . '/Source/SomeScannedClass.php';
$fileOneHash = $this->fileHashComputer->compute($fileOne);
$expectedFileOneHasn = md5_file($fileOne);
$this->assertSame($expectedFileOneHasn, $fileOneHash);
$fileTwo = __DIR__ . '/Source/ChangedScannedClass.php';
$fileTwoHash = $this->fileHashComputer->compute($fileTwo);
$expectedFileTwoHash = md5_file($fileTwo);
$this->assertSame($expectedFileTwoHash, $fileTwoHash);
$this->assertNotSame($fileOneHash, $fileTwoHash);
}
}