/**
  * Given a color name, colorize the provided text in that
  * color
  *
  * @param $key
  * @param $text
  * @return string
  */
 public function color($key, $text)
 {
     if (!$this->configuration->areColorsEnabled() || !$this->hasColorSupport()) {
         return $text;
     }
     $color = $this->colors[$key];
     return sprintf("%s%s%s", $color['left'], $text, $color['right']);
 }
 /**
  * Load the Peridot environment.
  *
  * @return void
  */
 public function load(ReaderInterface $reader)
 {
     $this->configuration = $reader->getConfiguration();
     require_once $this->configuration->getDsl();
     $peridotCallback = (include $this->configuration->getConfigurationFile());
     if (is_callable($peridotCallback)) {
         call_user_func($peridotCallback, $this->emitter);
     }
 }
Exemplo n.º 3
0
 /**
  * Given a color name, colorize the provided text in that
  * color
  *
  * @param $key
  * @param $text
  * @return string
  */
 public function color($key, $text)
 {
     $colorsEnabled = $this->configuration->areColorsEnabled() && $this->hasColorSupport();
     $colorsEnabledExplicit = $this->configuration->areColorsEnabledExplicit();
     if (!$colorsEnabled && !$colorsEnabledExplicit) {
         return $text;
     }
     $color = $this->colors[$key];
     return sprintf("%s%s%s", $color['left'], $text, $color['right']);
 }
Exemplo n.º 4
0
 /**
  * Run the Peridot application
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $this->configuration = ConfigurationReader::readInput($input);
     $this->environment->getEventEmitter()->emit('peridot.configure', [$this->configuration, $this]);
     $runner = $this->getRunner();
     $factory = new ReporterFactory($this->configuration, $output, $this->environment->getEventEmitter());
     $this->loadDsl($this->configuration->getDsl());
     $this->add(new Command($runner, $this->configuration, $factory, $this->environment->getEventEmitter()));
     $exitCode = parent::doRun($input, $output);
     $this->environment->getEventEmitter()->emit('peridot.end', [$exitCode, $input, $output]);
     return $exitCode;
 }
Exemplo n.º 5
0
 /**
  * Read configuration information from input
  *
  * @return Configuration
  */
 public function read()
 {
     $configuration = new Configuration();
     $options = ['grep' => [$configuration, 'setGrep'], 'no-colors' => [$configuration, 'disableColors'], 'force-colors' => [$configuration, 'enableColorsExplicit'], 'bail' => [$configuration, 'stopOnFailure'], 'configuration' => [$configuration, 'setConfigurationFile']];
     if ($path = $this->input->getArgument('path')) {
         $configuration->setPath($path);
     }
     foreach ($options as $option => $callable) {
         $this->callForOption($option, $callable);
     }
     return $configuration;
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  *
  * @param TestResult $result
  */
 public function run(TestResult $result)
 {
     $this->eventEmitter->on('test.failed', function () {
         if ($this->configuration->shouldStopOnFailure()) {
             $this->eventEmitter->emit('suite.halt');
         }
     });
     $this->eventEmitter->emit('runner.start');
     $this->suite->setEventEmitter($this->eventEmitter);
     $start = microtime(true);
     $this->suite->run($result);
     $this->eventEmitter->emit('runner.end', [microtime(true) - $start]);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  *
  * @param TestResult $result
  */
 public function run(TestResult $result)
 {
     $this->handleErrors();
     $this->eventEmitter->on('test.failed', function () {
         if ($this->configuration->shouldStopOnFailure()) {
             $this->eventEmitter->emit('suite.halt');
         }
     });
     $this->eventEmitter->emit('runner.start');
     $this->suite->setEventEmitter($this->eventEmitter);
     $this->suite->run($result);
     $this->eventEmitter->emit('runner.end');
     restore_error_handler();
 }
Exemplo n.º 8
0
 /**
  * Return the result as an integer.
  *
  * @return int
  */
 protected function getResult()
 {
     $result = new TestResult($this->eventEmitter);
     $this->getLoader()->load($this->configuration->getPath());
     $this->factory->create($this->configuration->getReporter());
     $this->runner->run($result);
     if ($result->getFailureCount() > 0) {
         return 1;
     }
     return 0;
 }
 /**
  * Configures Peridot to use Peridot\Concurrency\SuiteLoader
  * if the concurrent option is set. This plugin forces the use of the concurrent reporter
  * to ensure consistent and readable results.
  *
  * @return void
  */
 public function onPeridotLoad(Command $command, CoreConfiguration $config)
 {
     if (!$this->isConcurrencyEnabled()) {
         return;
     }
     $processes = $this->getInput()->getOption('processes');
     if ($processes) {
         $this->getConfiguration()->setProcesses((int) $processes);
     }
     $this->configureCommand($command);
     $config->setReporter('concurrent');
 }
Exemplo n.º 10
0
         });
         $passingChild = new Test("passing child", function () {
         });
         $failingChild = new Test("failing child", function () {
             throw new Exception("booo");
         });
         $passing2Child = new Test("passing2 child", function () {
         });
         $childSuite->addTest($passingChild);
         $childSuite->addTest($failingChild);
         $childSuite->addTest($passing2Child);
         $suite->addTest($childSuite);
         $passing2 = new Test("passing2 spec", function () {
         });
         $suite->addTest($passing2);
         $configuration = new Configuration();
         $configuration->stopOnFailure();
         $suite->setEventEmitter($this->eventEmitter);
         $runner = new Runner($suite, $configuration, $this->eventEmitter);
         $result = new TestResult($this->eventEmitter);
         $runner->run($result);
         assert($result->getTestCount() === 3, "spec count should be 3");
     });
 });
 $behavesLikeErrorEmitter = function () {
     $this->suite->addTest(new Test("my spec", function () {
         trigger_error("This is a user notice", E_USER_NOTICE);
     }));
     $error = [];
     $this->eventEmitter->on('error', function ($errno, $errstr, $errfile, $errline) use(&$error) {
         $error = array('errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline);
 /**
  * @param Configuration $config
  */
 public function onPeridotConfigure(Configuration $config)
 {
     $this->track($config->getPath());
 }
<?php

use Peridot\Concurrency\Configuration;
use Peridot\Configuration as CoreConfiguration;
describe('Configuration', function () {
    context('when attempting to access an unknown method', function () {
        it('should delegate to core configuration', function () {
            $core = new CoreConfiguration();
            $core->setGrep('*.test.php');
            $config = new Configuration($core);
            expect($config->getGrep())->to->equal('*.test.php');
        });
        it('should throw an exception if method does not exist', function () {
            $core = new CoreConfiguration();
            $config = new Configuration($core);
            expect([$config, 'getMysteryValue'])->to->throw('BadMethodCallException');
        });
    });
    describe('process accessors', function () {
        it('should allow access to process configuration property', function () {
            $config = new Configuration(new CoreConfiguration());
            expect($config->getProcesses())->to->equal(5);
            $config->setProcesses(4);
            expect($config->getProcesses())->to->equal(4);
        });
    });
});
use Peridot\Concurrency\Runner\StreamSelect\Message\StringPacker;
use Peridot\Concurrency\Runner\StreamSelect\Message\TestMessage;
use Peridot\Concurrency\Runner\StreamSelect\Model\Suite;
use Peridot\Concurrency\Runner\StreamSelect\Model\Test;
use Peridot\Configuration;
use Prophecy\Argument;
require 'TestMessageReader.php';
describe('Application', function () {
    $this->peridotAddChildScope(new TestMessageReader());
    beforeEach(function () {
        $this->emitter = new EventEmitter();
        $this->readStream = tmpfile();
        $this->writeStream = tmpfile();
        $this->message = new TestMessage($this->writeStream);
        $environment = new Environment($this->emitter, $this->readStream, $this->writeStream);
        $config = new Configuration();
        $config->setDsl(__DIR__ . '/../../../../fixtures/environment/dsl.php');
        $config->setConfigurationFile(__DIR__ . '/../../../../fixtures/environment/peridot.php');
        $reader = $this->getProphet()->prophesize('Peridot\\Concurrency\\Environment\\ReaderInterface');
        $reader->getConfiguration()->willReturn($config);
        $looper = $this->getProphet()->prophesize('Peridot\\Concurrency\\Runner\\StreamSelect\\Application\\LooperInterface');
        $looper->loop(Argument::type('Peridot\\Runner\\Context'), $environment, $this->message)->shouldBeCalled();
        $this->application = new Application($environment, $reader->reveal(), $looper->reveal());
        /**
         * An application does not listen until run.
         */
        $this->application->run($this->message);
    });
    afterEach(function () {
        fclose($this->readStream);
        fclose($this->writeStream);
Exemplo n.º 14
0
<?php

use Peridot\Configuration;
use Peridot\Concurrency\Environment\Reader;
describe('Reader', function () {
    beforeEach(function () {
        $configuration = new Configuration();
        //write config to environment
        $configuration->setDsl(__FILE__);
        $configuration->setGrep('*.test.php');
        $configuration->setPath('/path/to/tests');
        $configuration->setReporter('reporter');
        $configuration->disableColors();
        $configuration->stopOnFailure();
        $this->configuration = $configuration;
        $this->reader = new Reader(new Configuration());
    });
    describe('->getConfiguration()', function () {
        it('should fetch a configuration object populated by environment', function () {
            $config = $this->reader->getConfiguration();
            expect($config->getDsl())->to->equal($this->configuration->getDsl());
            expect($config->getGrep())->to->equal($this->configuration->getGrep());
            expect($config->getPath())->to->equal($this->configuration->getPath());
            expect($config->getReporter())->to->equal($this->configuration->getReporter());
            expect($config->areColorsEnabled())->to->equal($this->configuration->areColorsEnabled());
            expect($config->shouldStopOnFailure())->to->equal($this->configuration->shouldStopOnFailure());
        });
    });
});
use Peridot\Plugin\Watcher\LurkerWatcher;
use Peridot\Plugin\Watcher\WatcherInterface;
use Peridot\Plugin\Watcher\WatcherPlugin;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
describe('WatcherPlugin', function () {
    beforeEach(function () {
        $this->emitter = new EventEmitter();
        $this->watcher = new WatcherPlugin($this->emitter);
    });
    context('when peridot.configure event fires', function () {
        it('should add the test path to tracked paths', function () {
            $configuration = new Configuration();
            $configuration->setPath('/path/to/thing');
            $this->emitter->emit('peridot.configure', [$configuration]);
            assert($this->watcher->getTrackedPaths()[0] == $configuration->getPath(), "should track config path");
        });
    });
    $setupEnvironment = function () {
        $this->definition = new InputDefinition();
        $this->environment = new Environment($this->definition, $this->emitter, []);
    };
    context('when peridot.start event fires', function () use($setupEnvironment) {
        beforeEach($setupEnvironment);
        beforeEach(function () {
            $this->application = new Application($this->environment);
            $this->emitter->emit('peridot.start', [$this->environment, $this->application]);
        });