|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace IntegrationTesting\Driver; |
| 4 | + |
| 5 | +use IntegrationTesting\Exception\TestingException; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | + |
| 8 | +/** |
| 9 | + * Class FileSystemTest |
| 10 | + * @package IntegrationTesting\Driver |
| 11 | + * @covers \IntegrationTesting\Driver\FileSystem |
| 12 | + */ |
| 13 | +class FileSystemTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var FileSystem |
| 17 | + */ |
| 18 | + private $sut; |
| 19 | + private $tmpDir; |
| 20 | + |
| 21 | + public function setUp(): void |
| 22 | + { |
| 23 | + $this->sut = new FileSystem(); |
| 24 | + $this->tmpDir = 'build/tmp'; |
| 25 | + mkdir($this->tmpDir, 0777, true); |
| 26 | + } |
| 27 | + |
| 28 | + public function tearDown(): void |
| 29 | + { |
| 30 | + rmdir($this->tmpDir); |
| 31 | + } |
| 32 | + |
| 33 | + public function testGetFileContentsOk(): void |
| 34 | + { |
| 35 | + $filePath = $this->tmpDir . DIRECTORY_SEPARATOR . uniqid() . '.test'; |
| 36 | + file_put_contents($filePath, 'contents'); |
| 37 | + $content = $this->sut->getFileContents($filePath); |
| 38 | + unlink($filePath); |
| 39 | + $this->assertSame('contents', $content); |
| 40 | + } |
| 41 | + |
| 42 | + public function testGetFileContentsException(): void |
| 43 | + { |
| 44 | + $this->expectException(TestingException::class); |
| 45 | + $this->sut->getFileContents('not-valid'); |
| 46 | + } |
| 47 | + |
| 48 | + public function testGetFileListIteratorFromPathByExtension(): void |
| 49 | + { |
| 50 | + $filePath = $this->tmpDir . DIRECTORY_SEPARATOR . uniqid() . '.test'; |
| 51 | + file_put_contents($filePath, ''); |
| 52 | + $iterator = $this->sut->getFileListIteratorFromPathByExtension($this->tmpDir, 'test'); |
| 53 | + unlink($filePath); |
| 54 | + $this->assertSame(1, count($iterator)); |
| 55 | + } |
| 56 | + |
| 57 | + public function testRunCallbackOnEachFileIteratorContents(): void |
| 58 | + { |
| 59 | + $this->markTestIncomplete(); |
| 60 | + } |
| 61 | +} |
0 commit comments