rector/packages/caching/tests/Config/FileHashComputerTest.php

50 lines
1.5 KiB
PHP
Raw Normal View History

2020-04-01 03:55:44 +02:00
<?php
declare(strict_types=1);
namespace Rector\Caching\Tests\Config;
use Iterator;
use Rector\Caching\Config\FileHashComputer;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\HttpKernel\RectorKernel;
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase;
2020-07-21 13:42:17 +02:00
use Symplify\SmartFileSystem\SmartFileInfo;
2020-04-01 03:55:44 +02:00
final class FileHashComputerTest extends AbstractKernelTestCase
{
/**
* @var FileHashComputer
*/
private $fileHashComputer;
protected function setUp(): void
{
$this->bootKernel(RectorKernel::class);
$this->fileHashComputer = self::$container->get(FileHashComputer::class);
}
/**
* @dataProvider provideDataForIdenticalHash()
*/
public function testHashIsIdentical(string $firstConfig, string $secondConfig): void
{
2020-07-21 13:42:17 +02:00
$configAHash = $this->fileHashComputer->compute(new SmartFileInfo($firstConfig));
$configBHash = $this->fileHashComputer->compute(new SmartFileInfo($secondConfig));
2020-04-01 03:55:44 +02:00
$this->assertSame($configAHash, $configBHash);
}
public function provideDataForIdenticalHash(): Iterator
{
yield [__DIR__ . '/Source/config_content_a.yaml', __DIR__ . '/Source/config_content_b.yaml'];
yield [__DIR__ . '/Source/Import/import_a.yaml', __DIR__ . '/Source/Import/import_b.yaml'];
}
public function testInvalidType(): void
{
$this->expectException(ShouldNotHappenException::class);
2020-07-21 13:42:17 +02:00
$this->fileHashComputer->compute(new SmartFileInfo(__DIR__ . '/Source/file.xml'));
2020-04-01 03:55:44 +02:00
}
}