instances -> node inspector: edges, retained size, path to a root, back. */ final class ClassesInspectorTest extends CryoTestCase { private function openFirstQuery(\App\Form\MainForm $form): void { $this->clickOn($form, 'navClasses'); $this->clickRow($form, 'classes', $this->rowWith($form, 'classes', 'Query')); $this->clickRow($form, 'instances', 0); } public function testAClickOnAClassListsItsInstances(): void { $form = $this->form(); $this->clickOn($form, 'navClasses'); self::assertStringStartsWith('Query 400 objects', $this->items($form, 'classes')[0]); self::assertStringContainsString('retained 45.', $this->items($form, 'classes')[0]); $this->clickRow($form, 'classes', 0); self::assertCount(400, $this->items($form, 'instances')); self::assertStringContainsString('400 instances of Query', $this->text($form, 'instancesTitle')); self::assertStringContainsString('Query 56 B epoch 4 shop_worker.php:17 SqlLogger::log', $this->items($form, 'instances')[0]); $this->game->shot('classes'); } public function testAnInstanceOpensInTheInspector(): void { $form = $this->form(); $this->openFirstQuery($form); self::assertSame('inspector', $form->view()); self::assertTrue((bool)$this->w($form, 'navInspector')->props['checked']); self::assertMatchesRegularExpression('/^#\d+ Query \(object\) 56 B, retained \d+ B$/', $this->text($form, 'nodeTitle')); $info = $this->text($form, 'nodeInfo'); self::assertStringContainsString('Created at: demo/shop_worker.php:17 SqlLogger::log', $info); self::assertStringContainsString('Written at: demo/shop_worker.php:18 SqlLogger::log', $info); self::assertStringContainsString('Stack: shop_worker.php:17 SqlLogger::log ← shop_worker.php:74 handleBatch ← shop_worker.php:95 {main}', $info); self::assertStringStartsWith('sql → #', $this->items($form, 'outEdges')[0]); self::assertMatchesRegularExpression('/^#\d+ array → \[\d+\]$/', $this->items($form, 'inEdges')[0]); } public function testThePathToARootAndTheEdgesAreClickable(): void { $form = $this->form(); $this->openFirstQuery($form); $query = $form->inspected(); $this->clickOn($form, 'pathButton'); $path = $this->items($form, 'pathRows'); self::assertSame('Path 1', $path[0]); self::assertStringContainsString('static_prop SqlLogger::$log', $path[1]); self::assertMatchesRegularExpression("/→ \\[\\d+\\] #$query Query$/", $path[2]); $this->game->shot('inspector'); $this->clickRow($form, 'pathRows', 1); // the root array $array = $form->inspected(); self::assertNotSame($query, $array); self::assertStringContainsString('(array)', $this->text($form, 'nodeTitle')); self::assertStringContainsString('Root: static_prop SqlLogger::$log', $this->text($form, 'nodeInfo')); self::assertCount(400, $this->items($form, 'outEdges')); $this->clickRow($form, 'outEdges', 0); // back down to the first query self::assertSame($query, $form->inspected()); $this->clickRow($form, 'outEdges', 0); // its sql string self::assertStringContainsString('(string)', $this->text($form, 'nodeTitle')); self::assertSame(['(none)'], $this->items($form, 'outEdges')); $this->clickOn($form, 'back'); self::assertSame('classes', $form->view()); } }