Skip to content

Commit

Permalink
Merge pull request #24 from symplify/tv-less-file-info
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 3, 2023
2 parents 6e8434c + 7dcfa16 commit 2616d5a
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 323 deletions.
14 changes: 7 additions & 7 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ final class YourFixerTest extends AbstractCheckerTestCase
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
public function test(string $filePath): void
{
$this->doTestFileInfo($fileInfo);
$this->doTestFile($filePath);
}

public function provideData(): Iterator
{
return StaticFixtureFinder::yieldDirectory(__DIR__ . '/Fixture');
yield self::yieldFiles(__DIR__ . '/Fixture');
}

/**
* @dataProvider provideDataWithFileErrors()
*/
public function testFileErrors(SmartFileInfo $fileInfo, int $expectedErrorCount): void
public function testFileErrors(string $filePath, int $expectedErrorCount): void
{
$this->doTestFileInfoWithErrorCountOf($fileInfo, $expectedErrorCount);
$this->doTestFileInfoWithErrorCountOf($filePath, $expectedErrorCount);
}

public function provideDataWithFileErrors(): Iterator
{
yield [new SmartFileInfo(__DIR__ . '/Fixture/wrong.php.inc'), 1];
yield [new SmartFileInfo(__DIR__ . '/Fixture/correct.php.inc'), 0];
yield [__DIR__ . '/Fixture/wrong.php.inc', 1];
yield [__DIR__ . '/Fixture/correct.php.inc', 0];
}

protected function getCheckerClass(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,57 @@

namespace Symplify\EasyCodingStandard\Tests\ChangedFilesDetector\ChangedFilesDetector;

use SplFileInfo;
use Symplify\EasyCodingStandard\Caching\ChangedFilesDetector;
use Symplify\EasyCodingStandard\Kernel\EasyCodingStandardKernel;
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class ChangedFilesDetectorTest extends AbstractKernelTestCase
{
private SmartFileInfo $smartFileInfo;
private SplFileInfo $fileInfo;

private ChangedFilesDetector $changedFilesDetector;

protected function setUp(): void
{
$this->bootKernel(EasyCodingStandardKernel::class);

$this->smartFileInfo = new SmartFileInfo(__DIR__ . '/Source/OneClass.php');
$this->fileInfo = new SplFileInfo(__DIR__ . '/Source/OneClass.php');

$this->changedFilesDetector = $this->getService(ChangedFilesDetector::class);
$this->changedFilesDetector->changeConfigurationFile(__DIR__ . '/Source/easy-coding-standard.php');
}

public function testAddFile(): void
{
$this->assertFileHasChanged($this->smartFileInfo);
$this->assertFileHasChanged($this->smartFileInfo);
$this->assertFileHasChanged($this->fileInfo);
$this->assertFileHasChanged($this->fileInfo);
}

public function testHasFileChanged(): void
{
$this->changedFilesDetector->addFileInfo($this->smartFileInfo);
$this->changedFilesDetector->addFileInfo($this->fileInfo);

$this->assertFileHasNotChanged($this->smartFileInfo);
$this->assertFileHasNotChanged($this->fileInfo);
}

public function testInvalidateCacheOnConfigurationChange(): void
{
$this->changedFilesDetector->addFileInfo($this->smartFileInfo);
$this->assertFileHasNotChanged($this->smartFileInfo);
$this->changedFilesDetector->addFileInfo($this->fileInfo);
$this->assertFileHasNotChanged($this->fileInfo);

$this->changedFilesDetector->changeConfigurationFile(__DIR__ . '/Source/another-configuration.php');

$this->assertFileHasChanged($this->smartFileInfo);
$this->assertFileHasChanged($this->fileInfo);
}

private function assertFileHasChanged(SmartFileInfo $smartFileInfo): void
private function assertFileHasChanged(SplFileInfo $fileInfo): void
{
$failedAssertMessage = sprintf(
'Failed asserting that file "%s" has changed.',
$smartFileInfo->getRelativeFilePath()
);
$this->assertTrue($this->changedFilesDetector->hasFileInfoChanged($smartFileInfo), $failedAssertMessage);
$this->assertTrue($this->changedFilesDetector->hasFileInfoChanged($fileInfo));
}

private function assertFileHasNotChanged(SmartFileInfo $smartFileInfo): void
private function assertFileHasNotChanged(SplFileInfo $fileInfo): void
{
$failedAssertMessage = sprintf(
'Failed asserting that file "%s" has not changed.',
$smartFileInfo->getRelativeFilePath()
);
$this->assertFalse($this->changedFilesDetector->hasFileInfoChanged($smartFileInfo), $failedAssertMessage);
$this->assertFalse($this->changedFilesDetector->hasFileInfoChanged($fileInfo));
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

38 changes: 0 additions & 38 deletions packages-tests/SnippetFormatter/HeredocNowdoc/Fixture/trim.php.inc

This file was deleted.

Loading

0 comments on commit 2616d5a

Please sign in to comment.