/** * Test Command benchmark. */ public function testBenchmark() { /** @var OutputInterface|MockObject $output */ $output = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface'); $output->expects($this->exactly(3))->method('writeln'); $output->expects($this->at(0))->method('writeln')->with($this->equalTo('')); $output->expects($this->at(1))->method('writeln')->with($this->stringContains('<info>Job finished in ')); $output->expects($this->at(2))->method('writeln')->with($this->stringContains('<info>Memory usage: ')); $benchmark = new CommandBenchmark($output); $benchmark->start(); $benchmark->finish(); // Restart benchmark, to test output statistics array. $benchmark->start(); $data = $benchmark->finish(false); $this->assertArrayHasKey('start', $data); $this->assertArrayHasKey('finish', $data); $this->assertArrayHasKey('duration', $data); $this->assertArrayHasKey('memory_peak', $data); }
/** * Starts service with provided parameters. * * @param InputInterface $input * @param OutputInterface $output * @param string $serviceClass * @param string $prefix */ protected function start(InputInterface $input, OutputInterface $output, $serviceClass, $prefix) { $benchmark = new CommandBenchmark($output); $benchmark->start(); /** @var PipelineStarter $service */ $service = $this->getContainer()->get($serviceClass); $factory = $service->getPipelineFactory(); $factory->setProgressBar(new ProgressBar($output)); $service->startPipeline($prefix, $input->getArgument('target')); $benchmark->finish(); }