Skip to content

Commit d25a4aa

Browse files
committed
Added more tests
1 parent c82b0d2 commit d25a4aa

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

fixtures/1mb.iso

1.06 MB
Binary file not shown.

src/Descriptor/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function create(int $type, string $stdId = '', int $version = 0, ?
1919
Type::SUPPLEMENTARY_VOLUME_DESC => new SupplementaryVolume($stdId, $version, $bytes),
2020
Type::PARTITION_VOLUME_DESC => new Partition($stdId, $version, $bytes),
2121
Type::TERMINATOR_DESC => new Terminator($stdId, $version, $bytes),
22-
default => throw new Exception('Invalid descriptoin type received: ' . $type),
22+
default => throw new Exception('Invalid descriptor type received: ' . $type),
2323
};
2424
}
2525
}

src/Descriptor/SupplementaryVolume.php

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

55
namespace PhpIso\Descriptor;
66

7-
use PhpIso\IsoFile;
8-
97
class SupplementaryVolume extends Volume
108
{
119
protected int $type = Type::SUPPLEMENTARY_VOLUME_DESC;
1210
protected string $name = 'Supplementary volume descriptor';
13-
14-
public function init(IsoFile $isoFile, int &$offset): void
15-
{
16-
}
1711
}

src/Util/IsoDate.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,33 @@
88

99
class IsoDate
1010
{
11+
/*
12+
* UTC offset = Offset from Greenwich Mean Time in number of 15 min intervals from -48 (West) to +52 (East) recorded according to 7.1.2
13+
*/
14+
1115
/**
1216
* Create from a "7 bytes" date
1317
*
1418
* @param array<int, mixed> $buffer
1519
*/
1620
public static function init7(array &$buffer, int &$offset): ?Carbon
1721
{
18-
$year = 1900 + $buffer[$offset + 0];
19-
$month = $buffer[$offset + 1];
20-
$day = $buffer[$offset + 2];
21-
$hour = $buffer[$offset + 3];
22-
$min = $buffer[$offset + 4];
23-
$sec = $buffer[$offset + 5];
24-
// $tz = $buffer[$offset + 6];
22+
$year = 1900 + (int) $buffer[$offset + 0];
23+
$month = (int) $buffer[$offset + 1];
24+
$day = (int) $buffer[$offset + 2];
25+
$hour = (int) $buffer[$offset + 3];
26+
$min = (int) $buffer[$offset + 4];
27+
$sec = (int) $buffer[$offset + 5];
28+
$utcOffset = $buffer[$offset + 6];
29+
$utcOffsetHours = (int) round($utcOffset / 4);
2530

2631
$offset += 7;
2732

28-
return Carbon::create($year, $month, $day, $hour, $min, $sec);
33+
if ($year === 1900 || $month === 0 || $day === 0) {
34+
return null;
35+
}
36+
37+
return Carbon::create($year, $month, $day, $hour, $min, $sec, $utcOffsetHours);
2938
}
3039
/**
3140
* Create from a "17 bytes" date
@@ -42,11 +51,16 @@ public static function init17(array &$buffer, int &$offset): ?Carbon
4251
$hour = (int) substr($date, 8, 2);
4352
$min = (int) substr($date, 10, 2);
4453
$sec = (int) substr($date, 12, 2);
45-
// $ms = (int) substr($date, 14, 2);
46-
// $tz = $buffer[16];
54+
$ms = (int) substr($date, 14, 2);
55+
$utcOffset = $buffer[16];
56+
$utcOffsetHours = (int) round($utcOffset / 4);
4757

4858
$offset += 1;
4959

50-
return Carbon::create($year, $month, $day, $hour, $min, $sec);
60+
if ($year === 0 || $month === 0 || $day === 0) {
61+
return null;
62+
}
63+
64+
return Carbon::create($year, $month, $day, $hour, $min, $sec, $utcOffsetHours);
5165
}
5266
}

tests/IsoFileTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace PhpIso\Test;
66

7+
use Iterator;
78
use PHPUnit\Framework\TestCase;
9+
use PHPUnit\Framework\Attributes\DataProvider;
810
use PhpIso\IsoFile;
911
use PhpIso\Exception;
1012

@@ -26,10 +28,16 @@ public function testConstructorInvalidFile(): void
2628
new IsoFile($testFile);
2729
}
2830

29-
public function testConstructorExistingFile(): void
31+
#[DataProvider('isoFilesDataProvider')]
32+
public function testConstructorExistingFile(string $testFile): void
3033
{
31-
$testFile = dirname(__FILE__, 2) . '/fixtures/test.iso';
3234
$isoFile = new IsoFile($testFile);
3335
$this->assertInstanceOf(IsoFile::class, $isoFile);
3436
}
37+
38+
public static function isoFilesDataProvider(): Iterator
39+
{
40+
yield [dirname(__FILE__, 2) . '/fixtures/1mb.iso'];
41+
yield [dirname(__FILE__, 2) . '/fixtures/test.iso'];
42+
}
3543
}

0 commit comments

Comments
 (0)