<?phpnamespace Tests;use App\Cryo\PhpCryoReader;use App\Cryo\Studio;/** The window, its snapshots and the files a user opens. */final class MainFormTest extends CryoTestCase{ public function testTheDemoOpensWithTheLeakingLineOnTop(): void { $form = $this->form(); self::assertSame('leaks', $form->view()); self::assertCount(5, $this->items($form, 'snapshots')); $rows = $this->items($form, 'rows'); self::assertStringStartsWith('[LEAK] shop_worker.php:17 SqlLogger::log', $rows[0]); self::assertStringContainsString('kept 320 (100%)', $rows[0]); self::assertStringNotContainsString('[LEAK]', $rows[3], 'the bounded cache is not a leak'); $this->game->shot('leaks'); } public function testChoosingTheFirstSnapshotChangesItsSummary(): void { $form = $this->form(); $last = $this->text($form, 'snapInfo'); $this->clickRow($form, 'snapshots', 0); $first = $this->text($form, 'snapInfo'); self::assertNotSame($last, $first); self::assertStringContainsString('Epoch 0 · 160 objects', $first); self::assertSame('shop-0.cryo · 160 objects', $this->items($form, 'snapshots')[0]); } public function testEveryRadioOfTheNavigationShowsItsOwnPage(): void { $form = $this->form(); foreach (\App\Form\MainForm::VIEWS as $view => [$radio, $page]) { $this->clickOn($form, $radio); self::assertSame($view, $form->view()); self::assertTrue((bool)$this->w($form, $page)->props['visible'], $page); foreach (\App\Form\MainForm::VIEWS as [, $other]) { if ($other !== $page) { self::assertFalse((bool)$this->w($form, $other)->props['visible'], "$other hidden on $view"); } } self::assertNotSame('', $this->text($form, 'viewTitle')); } } public function testAnInvalidFileIsReportedAndOneSnapshotCannotBeCompared(): void { $form = $this->form(); $bad = sys_get_temp_dir() . '/not-a-snapshot.cryo'; file_put_contents($bad, 'hello'); $form->openFiles([$bad, \JumPHP\Kernel\Engine::get()->config->path('assets/demo/shop-2.cryo')]); $this->game->run(1); self::assertCount(1, $this->items($form, 'snapshots')); self::assertStringContainsString('not a .cryo file', $this->text($form, 'viewTitle')); self::assertStringContainsString('at least 2 snapshots', $this->text($form, 'viewTitle')); @unlink($bad); $this->clickOn($form, 'demo'); self::assertCount(5, $this->items($form, 'snapshots')); } public function testThePhpReaderReadsSizesAndSentinelsLikeTheExtension(): void { $r = PhpCryoReader::open(dirname(__DIR__) . '/assets/demo/shop-4.cryo'); $info = $r->info(); self::assertSame(1, $info['format']); self::assertSame(4, $info['epoch']); self::assertSame(480, $info['objects_with_site'], 'the closures are not tracked: no site'); self::assertSame(['site', 'count', 'bytes'], array_keys($r->top('site', 1)[0])); self::assertSame('5.0 KB', Studio::bytes(5120)); self::assertSame('Studio', Studio::native() ? 'ext' : 'Studio', 'tests run with the PHP reader (no ext-cryo in the JumPHP image)'); }}