Example #1
0
 public function __construct()
 {
     $this->config = Configuration::config();
     $this->log_dir = Configuration::logDir();
     // prepare log dir
     parent::__construct();
 }
Example #2
0
 public function _failed(\Codeception\TestCase $test, $fail)
 {
     if (!$this->client || !$this->client->getInternalResponse()) {
         return;
     }
     file_put_contents(\Codeception\Configuration::logDir() . basename($test->getFileName()) . '.page.debug.html', $this->client->getInternalResponse()->getContent());
 }
Example #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $conf = $this->getGlobalConfig($input->getOption('config'));
     $output->writeln("<info>Cleaning up " . Configuration::logDir() . "...</info>");
     FileSystem::doEmptyDir(Configuration::logDir());
     $output->writeln("Done");
 }
Example #4
0
 public function __construct()
 {
     $this->config = Configuration::config();
     $this->log_dir = Configuration::logDir();
     // prepare log dir
     $this->phpUnitOverriders();
     parent::__construct();
 }
Example #5
0
 public function __construct($max_files = 3)
 {
     $this->path = \Codeception\Configuration::logDir();
     $this->max_files = $max_files;
     // internal log
     $logHandler = new \Monolog\Handler\RotatingFileHandler($this->path . 'codeception.log', $this->max_files);
     $this->logger = new \Monolog\Logger('Codeception');
     $this->logger->pushHandler($logHandler);
 }
Example #6
0
 public function generateFilename(CodeGuy $I)
 {
     $I->haveFakeClass($stub = Stub::make($this->class, array('test' => Stub::makeEmpty('\\Codeception\\TestCase\\Cept', array('getFileName' => function () {
         return 'testtest';
     })))));
     $I->executeTestedMethod($stub);
     $I->seeResultEquals(\Codeception\Configuration::logDir() . 'debug' . DIRECTORY_SEPARATOR . 'testtest - 1');
     $I->executeTestedMethod($stub, 'mytest');
     $I->seeResultEquals(\Codeception\Configuration::logDir() . 'debug' . DIRECTORY_SEPARATOR . 'testtest - 2 - mytest');
 }
 /**
  * Class constructor.
  *
  * @param array              $config
  * @param array              $options
  * @param PhireMockProcess   $process  optional PhiremockProcess object
  */
 public function __construct(array $config, array $options, PhiremockProcess $process = null)
 {
     $this->config['bin_path'] = Config::projectDir() . '../vendor/bin/phiremock';
     $this->config['logs_path'] = Config::logDir();
     parent::__construct($config, $options);
     $this->initProcess($process);
     list($ip, $port) = explode(':', $this->config['listen']);
     $this->process->start($ip, $port, $this->config['bin_path'], $this->config['logs_path'], $this->config['debug']);
     if ($this->config['startDelay']) {
         sleep($this->config['startDelay']);
     }
 }
Example #8
0
 public function _initialize()
 {
     $this->debug('Initializing PuffinReport');
     if (array_key_exists('logFile', $this->config)) {
         $this->logFile = $this->config['logFile'];
     } else {
         $this->logFile = Configuration::logDir() . 'vcresult.html';
     }
     if (array_key_exists('templateVars', $this->config)) {
         $this->templateVars = $this->config['templateVars'];
     }
     if (array_key_exists('templateFile', $this->config)) {
         $this->templateFile = $this->config['templateFile'];
     } else {
         $this->templateFile = __DIR__ . '/report/template.php';
     }
 }
 private function init()
 {
     $this->debug("Initializing VisualCeptionReport");
     if (array_key_exists('logFile', $this->config)) {
         $this->logFile = $this->config["logFile"];
     } else {
         $this->logFile = \Codeception\Configuration::logDir() . 'vcresult.html';
     }
     if (array_key_exists('templateVars', $this->config)) {
         $this->templateVars = $this->config["templateVars"];
     }
     if (array_key_exists('templateFile', $this->config)) {
         $this->templateFile = $this->config["templateFile"];
     } else {
         $this->templateFile = __DIR__ . "/report/template.php";
     }
 }
 private function startServer()
 {
     if ($this->resource !== null) {
         return;
     }
     $command = $this->getCommand();
     $descriptorSpec = [['pipe', 'r'], ['file', Configuration::logDir() . 'phpbuiltinserver.output.txt', 'w'], ['file', Configuration::logDir() . 'phpbuiltinserver.errors.txt', 'a']];
     $this->resource = proc_open($command, $descriptorSpec, $this->pipes, null, null, ['bypass_shell' => true]);
     if (!is_resource($this->resource)) {
         throw new ExtensionException($this, 'Failed to start server.');
     }
     if (!proc_get_status($this->resource)['running']) {
         proc_close($this->resource);
         throw new ExtensionException($this, 'Failed to start server.');
     }
     if ($this->config['startDelay'] > 0) {
         sleep($this->config['startDelay']);
     }
 }
 private function startServer()
 {
     if ($this->resource !== null) {
         return;
     }
     $command = $this->getCommand();
     $descriptorSpec = [['pipe', 'r'], ['file', Configuration::logDir() . 'phpbuiltinserver.output.txt', 'w'], ['file', Configuration::logDir() . 'phpbuiltinserver.errors.txt', 'a']];
     $this->resource = proc_open($command, $descriptorSpec, $this->pipes, null, null, ['bypass_shell' => true]);
     if (!is_resource($this->resource)) {
         throw new ExtensionException($this, 'Failed to start server.');
     }
     if (!proc_get_status($this->resource)['running']) {
         proc_close($this->resource);
         throw new ExtensionException($this, 'Failed to start server.');
     }
     $max_checks = 10;
     $checks = 0;
     $this->write("Waiting for the PHP server to be reachable");
     while (true) {
         if ($checks >= $max_checks) {
             throw new ExtensionException($this, 'PHP server never became reachable');
             break;
         }
         if ($fp = @fsockopen($this->config['hostname'], $this->config['port'], $errCode, $errStr, 10)) {
             $this->writeln('');
             $this->writeln("PHP server is now reachable");
             fclose($fp);
             break;
         }
         $this->write('.');
         $checks++;
         // Wait before checking again
         sleep(1);
     }
     // Clear progress line writing
     $this->writeln('');
 }
 /**
  * Class constructor.
  */
 public function __construct()
 {
     $this->defaults['logs-path'] = Config::logDir();
 }
Example #13
0
 /**
  * Makes a screenshot of current window and saves it to `tests/_log/debug`.
  *
  * ``` php
  * <?php
  * $I->amOnPage('/user/edit');
  * $I->makeScreenshot('edit page');
  * // saved to: tests/_log/debug/UserEdit - edit page.png
  * ?>
  * ```
  *
  * @param $name
  */
 public function makeScreenshot($name)
 {
     $debugDir = \Codeception\Configuration::logDir() . 'debug';
     if (!is_dir($debugDir)) {
         mkdir($debugDir, 0777);
     }
     $caseName = str_replace('Cept.php', '', $this->test->getFileName());
     $caseName = str_replace('Cept.php', '', $caseName);
     /**
      * This is used for Cept only
      *
      * To be consistent with Cest, no sub-dir would be created, '\' and '/' in $caseName would be replaced with '.'
      */
     $search = array('/', '\\');
     $replace = array('.', '.');
     $caseName = str_replace($search, $replace, $caseName);
     $screenName = $debugDir . DIRECTORY_SEPARATOR . $caseName . ' - ' . $name . '.png';
     $this->_saveScreenshot($screenName);
     $this->debug("Screenshot saved to {$screenName}");
 }
Example #14
0
<?php

require_once __DIR__ . '/_data/MyOutputFormatter.php';
require_once __DIR__ . '/_data/MyGroupHighlighter.php';
@unlink(\Codeception\Configuration::logDir() . 'order.txt');
$fh = fopen(\Codeception\Configuration::logDir() . 'order.txt', 'a');
fwrite($fh, 'B');
Example #15
0
 public function _failed(\Codeception\TestCase $test, $fail)
 {
     $output = \Codeception\Configuration::logDir() . DIRECTORY_SEPARATOR . basename($test->getFileName()) . '.page.debug.html';
     file_put_contents($output, $this->browser->getResponse()->getContent());
 }
 /**
  * Get a descriptorspec ready to pass to proc_open().
  *
  * @see proc_open()
  * @see startServer()
  *
  * @return array
  *   An array that can be passed to proc_open to be used as a descriptor spec.
  */
 private function getDescriptorSpec()
 {
     return [['pipe', 'r'], ['file', Configuration::logDir() . 'drush.runserver.output.txt', 'w'], ['file', Configuration::logDir() . 'drush.runserver.errors.txt', 'a']];
 }
Example #17
0
 public function _failed(\Codeception\TestCase $test, $fail)
 {
     file_put_contents(\Codeception\Configuration::logDir() . basename($test->getFileName()) . '.page.debug.html', $this->session->getPage()->getContent());
 }
Example #18
0
 protected function printPHP()
 {
     $writer = new \PHP_CodeCoverage_Report_PHP();
     $writer->process($this->coverage, Configuration::logDir() . 'coverage.serialized');
 }
Example #19
0
 public function _failed(\Codeception\TestCase $test, $error)
 {
     $this->_saveScreenshot(\Codeception\Configuration::logDir() . basename($test->getFileName()) . '.fail.png');
     $this->debug("Screenshot was saved into 'log' dir");
     $this->session->stop();
 }
Example #20
0
 public function _failed(\Codeception\TestCase $test, $fail)
 {
     $fileName = str_replace('::', '-', $test->getFileName());
     file_put_contents(\Codeception\Configuration::logDir() . basename($fileName) . '.page.fail.html', $this->session->getPage()->getContent());
 }
Example #21
0
 public function testScreenshot()
 {
     $this->module->amOnPage('/');
     @unlink(\Codeception\Configuration::logDir() . 'testshot.png');
     $this->module->_saveScreenshot(\Codeception\Configuration::logDir() . 'testshot.png');
     $this->assertFileExists(\Codeception\Configuration::logDir() . 'testshot.png');
     @unlink(\Codeception\Configuration::logDir() . 'testshot.png');
 }
Example #22
0
 public static function appendToFile($marker)
 {
     $fh = fopen(\Codeception\Configuration::logDir() . 'order.txt', 'a');
     fwrite($fh, $marker);
 }
 /**
  * Returns the image path including the filename of a deviation image
  *
  * @param $identifier identifies your test object
  * @return string Path of the deviation image
  */
 private function getDeviationScreenshotPath($identifier, $alternativePrefix = '')
 {
     $debugDir = \Codeception\Configuration::logDir() . 'debug/';
     $prefix = $alternativePrefix === '' ? 'compare' : $alternativePrefix;
     return $debugDir . $prefix . $this->getScreenshotName($identifier);
 }
Example #24
0
 public function testScreenshot()
 {
     $this->module->amOnPage('/');
     @unlink(\Codeception\Configuration::logDir() . 'testshot.png');
     $testName = "debugTest";
     $this->module->makeScreenshot($testName);
     $this->assertFileExists(\Codeception\Configuration::logDir() . 'debug/ - ' . $testName . '.png');
     @unlink(\Codeception\Configuration::logDir() . 'debug/ - ' . $testName . '.png');
     $this->module->_saveScreenshot(\Codeception\Configuration::logDir() . 'testshot.png');
     $this->assertFileExists(\Codeception\Configuration::logDir() . 'testshot.png');
     @unlink(\Codeception\Configuration::logDir() . 'testshot.png');
 }
Example #25
0
 protected function generateFilename($name = null)
 {
     $debugDir = \Codeception\Configuration::logDir() . 'debug';
     if (!is_dir($debugDir)) {
         mkdir($debugDir, 0777);
     }
     //make dir for screens
     //define screenshot name
     $this->fileOrderCounter++;
     $caseName = str_replace('Cept.php', '', $this->test->getFileName());
     $screenName = is_null($name) ? $caseName . ' - ' . $this->fileOrderCounter : $caseName . ' - ' . $this->fileOrderCounter . ' - ' . $name;
     return $debugDir . DIRECTORY_SEPARATOR . $screenName;
 }
Example #26
0
 public function dump()
 {
     return file_put_contents(\Codeception\Configuration::logDir() . 'user.txt', $this->name);
 }
Example #27
0
 protected function printXml()
 {
     $writer = new \PHP_CodeCoverage_Report_Clover();
     $writer->process($this->coverage, Configuration::logDir() . 'coverage.xml');
 }
Example #28
0
 protected function retrieveAndPrintXml($suite)
 {
     $destFile = \Codeception\Configuration::logDir() . $suite . '.remote.coverage.xml';
     file_put_contents($destFile, $this->getRemoteCoverageFile($this->module, 'clover'));
 }
Example #29
0
 public function doEnhancedRun(\PHPUnit_Framework_Test $suite, \PHPUnit_Framework_TestResult $result, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (is_integer($arguments['repeat'])) {
         $suite = new \PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     }
     $result->convertErrorsToExceptions(FALSE);
     if (!$arguments['convertNoticesToExceptions']) {
         \PHPUnit_Framework_Error_Notice::$enabled = FALSE;
     }
     if (!$arguments['convertWarningsToExceptions']) {
         \PHPUnit_Framework_Error_Warning::$enabled = FALSE;
     }
     if ($arguments['stopOnError']) {
         $result->stopOnError(TRUE);
     }
     if ($arguments['stopOnFailure']) {
         $result->stopOnFailure(TRUE);
     }
     if ($arguments['stopOnIncomplete']) {
         $result->stopOnIncomplete(TRUE);
     }
     if ($arguments['stopOnSkipped']) {
         $result->stopOnSkipped(TRUE);
     }
     if ($this->printer === NULL) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof \PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new \Codeception\PHPUnit\ResultPrinter\UI(NULL, $arguments['verbose'], $arguments['colors'], $arguments['debug']);
         }
     }
     if (isset($arguments['report'])) {
         if ($arguments['report']) {
             $this->printer = new \Codeception\PHPUnit\ResultPrinter\Report();
         }
     }
     if (empty(self::$persistentListeners)) {
         foreach ($this->defaultListeners as $listener => $value) {
             if (!isset($arguments[$listener])) {
                 $arguments[$listener] = $value;
             }
         }
         if ($arguments['html']) {
             self::$persistentListeners[] = new \Codeception\PHPUnit\ResultPrinter\HTML(\Codeception\Configuration::logDir() . 'report.html');
         }
         if ($arguments['xml']) {
             self::$persistentListeners[] = new \Codeception\PHPUnit\Log\JUnit(\Codeception\Configuration::logDir() . 'report.xml', false);
         }
         if ($arguments['tap']) {
             self::$persistentListeners[] = new \PHPUnit_Util_Log_TAP(\Codeception\Configuration::logDir() . 'report.tap.log');
         }
         if ($arguments['json']) {
             self::$persistentListeners[] = new \PHPUnit_Util_Log_JSON(\Codeception\Configuration::logDir() . 'report.json');
         }
         foreach (self::$persistentListeners as $listener) {
             $result->addListener($listener);
         }
     }
     $arguments['listeners'][] = $this->printer;
     // clean up listeners between suites
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     if ($arguments['strict']) {
         $result->strictMode(TRUE);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     unset($suite);
     foreach ($arguments['listeners'] as $listener) {
         $result->removeListener($listener);
     }
     return $result;
 }
Example #30
0
 public function _failed(\Codeception\TestCase $test, $error)
 {
     $this->session->getDriver()->getBrowser()->captureEntirePageScreenshot(\Codeception\Configuration::logDir() . basename($test->getFileName()) . '.debug.png', '');
     $this->debug("Screenshot was saved into 'log' dir");
     $this->session->stop();
 }