Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions tests/Integration/BlarggTestRomsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Tests\Integration;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -24,10 +26,9 @@ protected function setUp(): void
$this->runner = new TestRomRunner(self::TIMEOUT);
}

/**
* @dataProvider cpuInstrsTestRomsProvider
*/
public function testCpuInstrs(string $romName, string $romPath): void
#[Test]
#[DataProvider('cpuInstrsTestRomsProvider')]
public function it_runs_cpu_instrs_test_rom(string $romName, string $romPath): void
{
$result = $this->runner->run($romPath);

Expand Down Expand Up @@ -101,7 +102,8 @@ public static function cpuInstrsTestRomsProvider(): array
];
}

public function testInstrTiming(): void
#[Test]
public function it_runs_instr_timing_test_rom(): void
{
$romPath = self::ROM_BASE_PATH . '/instr_timing/instr_timing.gb';

Expand Down
18 changes: 10 additions & 8 deletions tests/Integration/CommercialRomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace Tests\Integration;

use Gb\Emulator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -27,10 +30,9 @@ final class CommercialRomTest extends TestCase
*/
private const TEST_TIMEOUT = 180; // 3 minutes timeout

/**
* @dataProvider commercialRomProvider
*/
public function testCommercialRom(string $romName, string $romPath, int $framesToRun): void
#[Test]
#[DataProvider('commercialRomProvider')]
public function it_runs_commercial_rom_without_crashing(string $romName, string $romPath, int $framesToRun): void
{
if (!file_exists($romPath)) {
$this->markTestSkipped("ROM not found: {$romPath}");
Expand Down Expand Up @@ -128,11 +130,11 @@ public static function commercialRomProvider(): array

/**
* Test loading ROMs without running them (quick sanity check)
*
* @dataProvider commercialRomProvider
* @doesNotPerformAssertions
*/
public function testRomLoads(string $romName, string $romPath, int $framesToRun): void
#[Test]
#[DataProvider('commercialRomProvider')]
#[DoesNotPerformAssertions]
public function it_loads_rom_successfully(string $romName, string $romPath, int $framesToRun): void
{
if (!file_exists($romPath)) {
$this->markTestSkipped("ROM not found: {$romPath}");
Expand Down
49 changes: 33 additions & 16 deletions tests/Unit/Apu/ApuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
use Gb\Apu\Apu;
use Gb\Apu\Sink\BufferSink;
use Gb\Apu\Sink\NullSink;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class ApuTest extends TestCase
{
public function testInitiallyDisabled(): void
#[Test]
public function it_is_initially_disabled(): void
{
$apu = new Apu(new NullSink());

// NR52 bit 7 should be 0 (disabled)
self::assertSame(0x70, $apu->readByte(0xFF26));
}

public function testEnableApu(): void
#[Test]
public function it_can_enable_apu(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -28,7 +31,8 @@ public function testEnableApu(): void
self::assertSame(0xF0, $apu->readByte(0xFF26) & 0xF0);
}

public function testDisableApuClearsChannels(): void
#[Test]
public function it_clears_channels_when_disabled(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -49,7 +53,8 @@ public function testDisableApuClearsChannels(): void
self::assertSame(0x00, $apu->readByte(0xFF26) & 0x0F);
}

public function testCannotWriteRegistersWhenDisabled(): void
#[Test]
public function it_cannot_write_registers_when_disabled(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -60,7 +65,8 @@ public function testCannotWriteRegistersWhenDisabled(): void
self::assertSame(0x00, $apu->readByte(0xFF12));
}

public function testWaveRamAccessWhenDisabled(): void
#[Test]
public function it_allows_wave_ram_access_when_disabled(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -70,7 +76,8 @@ public function testWaveRamAccessWhenDisabled(): void
self::assertSame(0xAB, $apu->readByte(0xFF30));
}

public function testChannel1Registers(): void
#[Test]
public function it_handles_channel_1_registers(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -90,7 +97,8 @@ public function testChannel1Registers(): void
self::assertSame(0x40, $apu->readByte(0xFF14) & 0x40);
}

public function testChannel2Registers(): void
#[Test]
public function it_handles_channel_2_registers(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -107,7 +115,8 @@ public function testChannel2Registers(): void
self::assertSame(0x40, $apu->readByte(0xFF19) & 0x40);
}

public function testChannel3Registers(): void
#[Test]
public function it_handles_channel_3_registers(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -126,7 +135,8 @@ public function testChannel3Registers(): void
self::assertSame(0x40, $apu->readByte(0xFF1E) & 0x40);
}

public function testChannel4Registers(): void
#[Test]
public function it_handles_channel_4_registers(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -143,7 +153,8 @@ public function testChannel4Registers(): void
self::assertSame(0x40, $apu->readByte(0xFF23) & 0x40);
}

public function testMasterVolumeRegister(): void
#[Test]
public function it_handles_master_volume_register(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -153,7 +164,8 @@ public function testMasterVolumeRegister(): void
self::assertSame(0xFF, $apu->readByte(0xFF24));
}

public function testPanningRegister(): void
#[Test]
public function it_handles_panning_register(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -163,7 +175,8 @@ public function testPanningRegister(): void
self::assertSame(0xAB, $apu->readByte(0xFF25));
}

public function testWaveRamReadWrite(): void
#[Test]
public function it_can_read_and_write_wave_ram(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -180,7 +193,8 @@ public function testWaveRamReadWrite(): void
}
}

public function testFrameSequencerStepsChannels(): void
#[Test]
public function it_steps_channels_through_frame_sequencer(): void
{
$apu = new Apu(new NullSink());

Expand All @@ -202,7 +216,8 @@ public function testFrameSequencerStepsChannels(): void
self::assertSame(0x00, $apu->readByte(0xFF26) & 0x01);
}

public function testAudioSampleGeneration(): void
#[Test]
public function it_generates_audio_samples(): void
{
$sink = new BufferSink();
$apu = new Apu($sink);
Expand All @@ -224,7 +239,8 @@ public function testAudioSampleGeneration(): void
self::assertGreaterThan(0, $sink->getSampleCount());
}

public function testStereoMixing(): void
#[Test]
public function it_mixes_stereo_audio(): void
{
$sink = new BufferSink();
$apu = new Apu($sink);
Expand All @@ -245,7 +261,8 @@ public function testStereoMixing(): void
self::assertGreaterThan(0, $sink->getSampleCount());
}

public function testNR52ChannelStatus(): void
#[Test]
public function it_reports_channel_status_in_nr52(): void
{
$apu = new Apu(new NullSink());

Expand Down
31 changes: 21 additions & 10 deletions tests/Unit/Apu/Channel1Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
namespace Tests\Unit\Apu;

use Gb\Apu\Channel\Channel1;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class Channel1Test extends TestCase
{
public function testInitiallyDisabled(): void
#[Test]
public function it_is_initially_disabled(): void
{
$channel = new Channel1();
self::assertFalse($channel->isEnabled());
self::assertSame(0.0, $channel->getSample());
}

public function testTriggerEnablesChannel(): void
#[Test]
public function it_enables_channel_when_triggered(): void
{
$channel = new Channel1();

Expand All @@ -28,7 +31,8 @@ public function testTriggerEnablesChannel(): void
self::assertTrue($channel->isEnabled());
}

public function testDutyPattern25Percent(): void
#[Test]
public function it_produces_25_percent_duty_pattern(): void
{
$channel = new Channel1();

Expand Down Expand Up @@ -60,7 +64,8 @@ public function testDutyPattern25Percent(): void
self::assertGreaterThan(0.5, $samples[7]); // 1
}

public function testVolumeEnvelope(): void
#[Test]
public function it_applies_volume_envelope(): void
{
$channel = new Channel1();

Expand All @@ -81,7 +86,8 @@ public function testVolumeEnvelope(): void
self::assertTrue($channel->isEnabled());
}

public function testLengthCounter(): void
#[Test]
public function it_disables_when_length_counter_expires(): void
{
$channel = new Channel1();

Expand All @@ -98,7 +104,8 @@ public function testLengthCounter(): void
self::assertFalse($channel->isEnabled());
}

public function testSweepIncreaseFrequency(): void
#[Test]
public function it_increases_frequency_with_sweep(): void
{
$channel = new Channel1();

Expand All @@ -118,7 +125,8 @@ public function testSweepIncreaseFrequency(): void
self::assertTrue($channel->isEnabled());
}

public function testSweepOverflowDisablesChannel(): void
#[Test]
public function it_disables_when_sweep_overflows(): void
{
$channel = new Channel1();

Expand All @@ -134,7 +142,8 @@ public function testSweepOverflowDisablesChannel(): void
self::assertFalse($channel->isEnabled());
}

public function testDacDisableStopsOutput(): void
#[Test]
public function it_stops_output_when_dac_disabled(): void
{
$channel = new Channel1();

Expand All @@ -151,7 +160,8 @@ public function testDacDisableStopsOutput(): void
self::assertSame(0.0, $channel->getSample());
}

public function testRegisterReadback(): void
#[Test]
public function it_reads_back_registers_correctly(): void
{
$channel = new Channel1();

Expand All @@ -171,7 +181,8 @@ public function testRegisterReadback(): void
self::assertSame(0x40, $channel->readNR14() & 0x40); // Only length enable readable
}

public function testFrequencyGeneration(): void
#[Test]
public function it_generates_frequency_based_output(): void
{
$channel = new Channel1();

Expand Down
Loading
Loading