File tree Expand file tree Collapse file tree 7 files changed +68
-2
lines changed Expand file tree Collapse file tree 7 files changed +68
-2
lines changed Original file line number Diff line number Diff line change 11.github / export-ignore
2+ fixtures / export-ignore
23tests / export-ignore
Original file line number Diff line number Diff line change 1+ PHP ISO file Library. A library for reading ISO files using PHP.
Original file line number Diff line number Diff line change 1+ invalid-file
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace PhpIso ;
6+
7+ class Exception extends \Exception
8+ {
9+ }
Original file line number Diff line number Diff line change 44
55namespace PhpIso ;
66
7+ use PhpIso \Exception ;
8+
79class 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}
Original file line number Diff line number Diff line change 66
77use PHPUnit \Framework \TestCase ;
88use PhpIso \IsoFile ;
9+ use PhpIso \Exception ;
910
1011class 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}
You can’t perform that action at this time.
0 commit comments