w($form, 'queryText')->text = ''; $this->clickOn($form, 'queryText'); $form->type($query . "\n"); $this->game->run(1); } public function testAQueryListsTheNodesItMatches(): void { $form = $this->form(); $this->clickOn($form, 'navQuery'); self::assertStringContainsString('nodes match', $this->text($form, 'queryStatus'), 'the default query: retained>1K'); $this->typeQuery($form, 'class=Query and size>=56'); self::assertStringStartsWith('200 nodes match', $this->text($form, 'queryStatus')); self::assertStringContainsString('Query 56 B', $this->items($form, 'queryRows')[0]); $this->typeQuery($form, 'class=Price* and epoch>=4'); self::assertStringStartsWith('60 nodes match', $this->text($form, 'queryStatus')); $this->game->shot('query'); $this->clickRow($form, 'queryRows', 0); self::assertSame('inspector', $form->view()); self::assertStringContainsString('Price', $this->text($form, 'nodeTitle')); } public function testAWrongQuerySaysWhere(): void { $form = $this->form(); $this->clickOn($form, 'navQuery'); $this->typeQuery($form, 'colour=red'); self::assertStringContainsString('invalid query near "colour=red"', $this->text($form, 'queryStatus')); self::assertSame([], $this->items($form, 'queryRows')); $this->clickOn($form, 'runQuery'); self::assertStringContainsString('invalid query', $this->text($form, 'queryStatus')); } public function testTheSeriesDrawsTheMemoryCurveWithItsMarks(): void { $form = $this->form(); $this->clickOn($form, 'navSeries'); /** @var MemoryChart $chart */ $chart = $this->w($form, 'chart'); $points = $chart->points; self::assertGreaterThan(20, count($points)); self::assertSame(['snapshot shop-0', 'snapshot shop-1', 'snapshot shop-2', 'snapshot shop-3', 'snapshot shop-4'], array_column($chart->marks, 1)); self::assertGreaterThan($points[0][1], $points[count($points) - 1][1], 'the memory grows'); self::assertStringContainsString('samples every 50 ms', $this->text($form, 'seriesInfo')); self::assertStringContainsString('5 marks', $this->text($form, 'seriesInfo')); self::assertGreaterThan(300, $chart->h, 'the curve takes the room left'); $this->game->shot('series'); } public function testAWrongSeriesFileIsReported(): void { $form = $this->form(); $bad = sys_get_temp_dir() . '/not-a-series.cryom'; file_put_contents($bad, 'CRYO nothing'); $form->openFiles([$bad]); $this->game->run(1); self::assertSame('series', $form->view()); self::assertStringContainsString('not a .cryom file', $this->text($form, 'seriesInfo')); self::assertSame([], $this->w($form, 'chart')->props['points']); @unlink($bad); $this->clickOn($form, 'demoSeries'); self::assertSame('shop.cryom', $this->text($form, 'seriesName')); self::assertNotSame([], $this->w($form, 'chart')->props['points']); } public function testTheSeriesReaderNeedsNo64BitInteger(): void { $s = MetricSeries::open(dirname(__DIR__) . '/assets/demo/shop.cryom'); $sum = $s->summary(); self::assertSame(1, $s->version); self::assertCount(5, $sum['marks']); self::assertGreaterThan(0, $sum['slope_mb_per_hour']); self::assertSame($sum['samples'], count($s->column('memory'))); foreach (['src/Cryo/PhpCryoReader.php', 'src/Cryo/PhpCryoDelta.php', 'src/Cryo/MetricSeries.php'] as $file) { $code = ''; foreach (token_get_all((string)file_get_contents(dirname(__DIR__) . '/' . $file)) as $token) { if (!is_array($token) || !in_array($token[0], [T_COMMENT, T_DOC_COMMENT], true)) { $code .= is_array($token) ? $token[1] : $token; // the code without its comments } } self::assertDoesNotMatchRegularExpression("~pack\\('(?:[^']*/)?[PqQJ]~", $code, "$file: no 64-bit pack/unpack (32-bit PHP in the browser)"); } } }