public function setPrompt(script\prompt $prompt = null) { if ($prompt === null) { $prompt = new script\prompt(); } $this->prompt = $prompt->setOutputWriter($this->writer); return $this; }
/** * @param string $message * * @return string */ public function ask($message) { $runAgainText = "Press <Enter> to reexecute, press any other key and <Enter> to stop..."; if ($message != $runAgainText) { return parent::ask($message); } /** @var \mageekguy\atoum\writers\std\out $outputWriter */ $outputWriter = $this->getOutputWriter(); $watcher = new ResourceWatcher(); $onEvent = function (FilesystemEvent $event) use($watcher, $outputWriter) { $outputWriter->write($event->getResource()->getId() . " has been modified." . PHP_EOL); $watcher->stop(); }; foreach ($this->configuration->getWatchedFiles() as $watchedFile) { $watcher->track($watchedFile, $watchedFile); $watcher->addListener($watchedFile, $onEvent); } foreach ($this->getRunner()->getTestPaths() as $path) { $watcher->track($path, $path); $watcher->addListener($path, $onEvent); } $outputWriter->write('Waiting for a file to change to run the test(s)... (Use CTRL+C to stop)' . PHP_EOL); $watcher->start(); return ''; }
public function testAsk() { $this->if($prompt = new testedClass())->and($writer = new \mock\atoum\writer())->and($reader = new \mock\atoum\reader())->and($prompt->setOutputWriter($writer))->and($prompt->setInputReader($reader))->and($this->calling($reader)->read = $line = uniqid())->then->string($prompt->ask($question = uniqid()))->isEqualTo($line)->mock($writer)->call('write')->withArguments($question)->once()->string($prompt->ask($question = uniqid()))->isEqualTo($line); }
public function testSetPrompt() { $this->if($script = new mock\script(uniqid()))->then->object($script->setPrompt($prompt = new prompt()))->isIdenticalTo($script)->object($script->getPrompt())->isIdenticalTo($prompt)->object($prompt->getOutputWriter())->isIdenticalTo($script->getOutputWriter())->given($defaultPrompt = new prompt(), $defaultPrompt->setOutputWriter($script->getOutputWriter()))->then->object($script->setPrompt())->isIdenticalTo($script)->object($script->getPrompt())->isNotIdenticalTo($prompt)->isEqualTo($defaultPrompt); }