Skip to content

Commit e55b63b

Browse files
committed
Added test files
1 parent 0523308 commit e55b63b

File tree

7 files changed

+68
-2
lines changed

7 files changed

+68
-2
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.github/ export-ignore
2+
fixtures/ export-ignore
23
tests/ export-ignore

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PHP ISO file Library. A library for reading ISO files using PHP.

fixtures/invalid.iso

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invalid-file

fixtures/test.iso

1.19 MB
Binary file not shown.

src/Exception.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpIso;
6+
7+
class Exception extends \Exception
8+
{
9+
}

src/IsoFile.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,42 @@
44

55
namespace PhpIso;
66

7+
use PhpIso\Exception;
8+
79
class IsoFile
810
{
11+
/**
12+
* @var resource
13+
*/
14+
protected mixed $fileHandle;
15+
16+
public function __construct(protected string $isoFilePath)
17+
{
18+
$this->openFile();
19+
}
20+
21+
public function __destruct()
22+
{
23+
$this->closeFile();
24+
}
25+
26+
protected function openFile(): void
27+
{
28+
if (file_exists($this->isoFilePath) === false) {
29+
throw new Exception('File does not exist: ' . $this->isoFilePath);
30+
}
31+
32+
$fileHandle = fopen($this->isoFilePath, 'rb');
33+
34+
if ($fileHandle === false) {
35+
throw new Exception('Cannot open file for reading: ' . $this->isoFilePath);
36+
}
37+
38+
$this->fileHandle = $fileHandle;
39+
}
40+
41+
protected function closeFile(): void
42+
{
43+
fclose($this->fileHandle);
44+
}
945
}

tests/IsoFileTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,30 @@
66

77
use PHPUnit\Framework\TestCase;
88
use PhpIso\IsoFile;
9+
use PhpIso\Exception;
910

1011
class IsoFileTest extends TestCase
1112
{
12-
public function testConstructor(): void
13+
public function testConstructorFileDoesNotExist(): void
1314
{
14-
$isoFile = new IsoFile();
15+
$testFile = dirname(__FILE__, 2) . '/fixtures/does-not-exist.iso';
16+
17+
$this->expectException(Exception::class);
18+
new IsoFile($testFile);
19+
}
20+
21+
// public function testConstructorInvalidFile(): void
22+
// {
23+
// $testFile = dirname(__FILE__, 2) . '/fixtures/invalid.iso';
24+
//
25+
// $this->expectException(Exception::class);
26+
// new IsoFile($testFile);
27+
// }
28+
29+
public function testConstructorExistingFile(): void
30+
{
31+
$testFile = dirname(__FILE__, 2) . '/fixtures/test.iso';
32+
$isoFile = new IsoFile($testFile);
1533
$this->assertInstanceOf(IsoFile::class, $isoFile);
1634
}
1735
}

0 commit comments

Comments
 (0)