Beispiel #1
0
 public function afterSuite(SuiteEvent $e)
 {
     if (!$this->isEnabled()) {
         return;
     }
     $this->mergeToPrint($e->getResult()->getCodeCoverage());
 }
 public function updateActor(SuiteEvent $e)
 {
     $settings = $e->getSettings();
     $modules = $e->getSuite()->getModules();
     $actorActionsFile = Configuration::supportDir() . '_generated' . DIRECTORY_SEPARATOR . $settings['class_name'] . 'Actions.php';
     if (!file_exists($actorActionsFile)) {
         codecept_debug("Generating {$settings['class_name']}Actions...");
         $this->generateActorActions($actorActionsFile, $settings);
         return;
     }
     // load actor class to see hash
     $handle = @fopen($actorActionsFile, "r");
     if ($handle and is_writable($actorActionsFile)) {
         $line = @fgets($handle);
         if (preg_match('~\\[STAMP\\] ([a-f0-9]*)~', $line, $matches)) {
             $hash = $matches[1];
             $currentHash = Actions::genHash($modules, $settings);
             // regenerate actor class when hashes do not match
             if ($hash != $currentHash) {
                 codecept_debug("Rebuilding {$settings['class_name']}...");
                 @fclose($handle);
                 $this->generateActorActions($actorActionsFile, $settings);
                 return;
             }
         }
         @fclose($handle);
     }
 }
 public function terminate()
 {
     if ($this->suiteEvent) {
         $this->suiteEvent->getResult()->stopOnError(true);
         $this->suiteEvent->getResult()->stopOnFailure(true);
     }
     throw new \RuntimeException("\n\n---------------------------\nTESTS EXECUTION TERMINATED\n---------------------------\n");
 }
Beispiel #4
0
 public function beforeClass(SuiteEvent $e)
 {
     foreach ($e->getSuite()->tests() as $test) {
         /** @var $test \PHPUnit_Framework_Test  * */
         $testClass = get_class($test);
         $this->hooks[$testClass] = \PHPUnit_Util_Test::getHookMethods($testClass);
     }
     $this->runHooks('beforeClass');
 }
Beispiel #5
0
 public function handle(SuiteEvent $e)
 {
     $settings = $e->getSettings();
     if ($settings['error_level']) {
         $this->errorLevel = $settings['error_level'];
     }
     error_reporting(eval("return {$this->errorLevel};"));
     set_error_handler([$this, 'errorHandler']);
     register_shutdown_function([$this, 'shutdownHandler']);
 }
Beispiel #6
0
 public function moduleInit(SuiteEvent $event)
 {
     $settings = $event->getSettings();
     $config = [];
     if (array_key_exists("extensions", $settings) && array_key_exists("enabled", $settings["extensions"])) {
         if (in_array(trim(get_class($this), "/"), $settings["extensions"]["enabled"])) {
             $this->startServer();
         }
     }
 }
Beispiel #7
0
 public function beforeSuite(SuiteEvent $e)
 {
     $suite = $e->getSuite();
     if (!$suite instanceof Suite) {
         return;
     }
     $this->modules = $suite->getModules();
     foreach ($this->modules as $module) {
         $module->_beforeSuite($e->getSettings());
     }
 }
Beispiel #8
0
 public function loadBootstrap(SuiteEvent $e)
 {
     $settings = $e->getSettings();
     if (!isset($settings['bootstrap'])) {
         return;
     }
     $bootstrap = $settings['path'] . $settings['bootstrap'];
     if (!is_file($bootstrap)) {
         throw new ConfigurationException("Bootstrap file {$bootstrap} can't be loaded");
     }
     require_once $bootstrap;
 }
Beispiel #9
0
 public function unlink(\Codeception\Event\SuiteEvent $e)
 {
     $rootFolder = $this->getRootFolder();
     $destination = $this->getDestination($rootFolder, $e->getSettings());
     if ($this->filesystem->file_exists($destination)) {
         $unlinked = $this->filesystem->unlink($destination);
         if (!$unlinked) {
             // let's not kill the suite but let's notify the user
             $this->writeln('Could not unlink file [' . $destination . '], manual removal is required.');
         }
         $this->writeln('Unliked plugin folder [' . $destination . ']');
     }
 }
Beispiel #10
0
 public function afterSuite(SuiteEvent $e)
 {
     if (!$this->isEnabled()) {
         return;
     }
     $suite = $e->getSuite()->getName();
     if ($this->options['xml']) {
         $this->retrieveAndPrintXml($suite);
     }
     if ($this->options['html']) {
         $this->retrieveAndPrintHtml($suite);
     }
 }
 public function beforeClass(SuiteEvent $e)
 {
     foreach ($e->getSuite()->tests() as $test) {
         /** @var $test \PHPUnit_Framework_Test  * */
         if ($test instanceof \PHPUnit_Framework_TestSuite_DataProvider) {
             $potentialTestClass = strstr($test->getName(), '::', true);
             $this->hooks[$potentialTestClass] = \PHPUnit_Util_Test::getHookMethods($potentialTestClass);
         }
         $testClass = get_class($test);
         $this->hooks[$testClass] = \PHPUnit_Util_Test::getHookMethods($testClass);
     }
     $this->runHooks('beforeClass');
 }
 public function handle(SuiteEvent $e)
 {
     $settings = $e->getSettings();
     if ($settings['error_level']) {
         $this->errorLevel = eval("return {$settings['error_level']};");
     }
     error_reporting($this->errorLevel);
     // We must register shutdown function before deprecation error handler to restore previous error handler
     // and silence DeprecationErrorHandler yelling about 'THE ERROR HANDLER HAS CHANGED!'
     register_shutdown_function([$this, 'shutdownHandler']);
     $this->registerDeprecationErrorHandler();
     $this->oldHandler = set_error_handler([$this, 'errorHandler']);
 }
 /**
  * After suite callback
  *
  * @param \Codeception\Event\SuiteEvent $e
  */
 public function afterSuite(SuiteEvent $e)
 {
     /** @var $suite \PHPUnit_Framework_TestSuite */
     $suite = $e->getSuite();
     if ($suite->getName() === 'acceptance') {
         $this->afterSuiteAcceptance($e);
     }
     if ($suite->getName() === 'functional') {
         $this->afterSuiteFunctional($e);
     }
     if ($suite->getName() === 'unit') {
         $this->afterSuiteUnit($e);
     }
 }
Beispiel #14
0
 public function beforeSuite(SuiteEvent $e)
 {
     $this->namespace = "";
     $settings = $e->getSettings();
     if (isset($settings['namespace'])) {
         $this->namespace = $settings['namespace'];
     }
     $this->message("%s Tests (%d) ")->with(ucfirst($e->getSuite()->getName()), $e->getSuite()->count())->style('bold')->width($this->width, '-')->prepend("\n")->writeln();
     if ($e->getSuite() instanceof Suite) {
         $message = $this->message(implode(', ', array_map(function ($module) {
             return $module->_getName();
         }, $e->getSuite()->getModules())));
         $message->style('info')->prepend('Modules: ')->writeln(OutputInterface::VERBOSITY_VERBOSE);
     }
     $this->message('')->width($this->width, '-')->writeln(OutputInterface::VERBOSITY_VERBOSE);
 }
Beispiel #15
0
 /**
  * @test
  * it should allow for relative destinations
  */
 public function it_should_allow_for_relative_destinations()
 {
     mkdir(codecept_data_dir('destination'), 0777, true);
     $this->config = ['files' => [codecept_data_dir('some-file') => 'tests/_data/destination/some-file', codecept_data_dir('some-folder') => 'tests/_data/destination/some-folder']];
     $sut = $this->make_instance();
     $sut->copyFiles($this->suiteEvent->reveal());
     $destination = codecept_data_dir('destination');
     $this->assertFileExists($destination . '/some-file');
     $this->assertFileExists($destination . '/some-folder');
     $this->assertFileExists($destination . '/some-folder/some-file');
 }
 public function before(\Codeception\Event\SuiteEvent $se)
 {
     $suite = $se->getSuite();
     $tests = $suite->tests();
     foreach ($tests as $id => $test) {
         if (is_a($test, 'Codeception\\Test\\Cest')) {
             $testClass = $test->getTestClass();
             $testClassName = get_class($testClass);
             $testMethod = $test->getTestMethod();
             $testFile = $test->getMetadata()->getFilename();
             $testActor = $test->getMetadata()->getCurrent('actor');
             $dataMethod = Annotation::forMethod($testClass, $testMethod)->fetch('dataprovider');
             try {
                 if (empty($dataMethod)) {
                     continue;
                 }
                 if (false === is_callable([$testClass, $dataMethod])) {
                     throw new \Exception();
                 }
                 $dataProvider = new \PHPUnit_Framework_TestSuite_DataProvider();
                 $examples = $testClassName::$dataMethod();
                 foreach ($examples as $example) {
                     if ($example === null) {
                         throw new TestParseException($testFile, "Invalid values format returned by DataProvider {$dataMethod} for {$testClassName}->{$testMethod}.");
                     }
                     $dataTest = new CestFormat($testClass, $testMethod, $testFile);
                     $dataTest->getMetadata()->setServices(['di' => $test->getMetadata()->getService('di'), 'dispatcher' => $test->getMetadata()->getService('dispatcher'), 'modules' => $test->getMetadata()->getService('modules')]);
                     $dataTest->getMetadata()->setCurrent(['actor' => $testActor, 'example' => $example]);
                     $step = new Comment('', $dataTest->getMetadata()->getCurrent('example'));
                     $dataTest->getScenario()->setFeature($dataTest->getSpecFromMethod() . ' | ' . $step->getArgumentsAsString(100));
                     $groups = Annotation::forMethod($testClass, $testMethod)->fetchAll('group');
                     $dataProvider->addTest($dataTest, $groups);
                 }
                 $tests[$id] = $dataProvider;
             } catch (\Exception $e) {
                 throw new TestParseException($testFile, "DataProvider {$dataMethod} for {$testClassName}->{$testMethod} is invalid or not callable." . PHP_EOL . "Make sure this is a public static function.");
             }
         }
     }
     $suite->setTests($tests);
 }
Beispiel #17
0
 public function beforeSuite(SuiteEvent $e)
 {
     $this->module = $this->getServerConnectionModule();
     $this->applySettings($e->getSettings());
     if (!$this->isEnabled()) {
         return;
     }
     $this->suiteName = $e->getSuite()->baseName;
     if ($this->settings['remote_config']) {
         $this->addC3AccessHeader(self::COVERAGE_HEADER_CONFIG, $this->settings['remote_config']);
     }
     $knock = $this->c3Request('clear');
     if ($knock === false) {
         throw new RemoteException('
             CodeCoverage Error.
             Check the file "c3.php" is included in your application.
             We tried to access "/c3/report/clear" but this URI was not accessible.
             You can review actual error messages in c3tmp dir.
             ');
     }
 }
Beispiel #18
0
 public function updateGuy(SuiteEvent $e)
 {
     $settings = $e->getSettings();
     $guyFile = $settings['path'] . $settings['class_name'] . '.php';
     // load guy class to see hash
     $handle = @fopen($guyFile, "r");
     if ($handle and is_writable($guyFile)) {
         $line = @fgets($handle);
         if (preg_match('~\\[STAMP\\] ([a-f0-9]*)~', $line, $matches)) {
             $hash = $matches[1];
             $currentHash = Actor::genHash(SuiteManager::$actions, $settings);
             // regenerate guy class when hashes do not match
             if ($hash != $currentHash) {
                 codecept_debug("Rebuilding {$settings['class_name']}...");
                 $guyGenerator = new Actor($settings);
                 @fclose($handle);
                 $generated = $guyGenerator->produce();
                 @file_put_contents($guyFile, $generated);
                 return;
             }
         }
         @fclose($handle);
     }
 }
Beispiel #19
0
 /**
  * @test
  * it should allow specifying the root folder in the configuration
  */
 public function it_should_allow_specifying_the_root_folder_in_the_configuration()
 {
     $rootFolder = __DIR__;
     $defaultDestinationFolder = '/default';
     $defaultDestination = $defaultDestinationFolder;
     $envDestinations = ['default' => $defaultDestinationFolder];
     $this->config = ['mode' => 'plugin', 'destination' => $envDestinations, 'rootFolder' => $rootFolder];
     $this->event->getSettings()->willReturn(['current_environment' => 'default']);
     $this->filesystem->file_exists($defaultDestination . DIRECTORY_SEPARATOR . basename($rootFolder))->willReturn(false);
     $this->filesystem->is_dir($defaultDestinationFolder)->willReturn(true);
     $this->filesystem->is_writeable($defaultDestinationFolder)->willReturn(true);
     $this->filesystem->is_dir($rootFolder)->willReturn(true);
     $this->filesystem->is_readable($rootFolder)->willReturn(true);
     $this->filesystem->symlink(rtrim($rootFolder, DIRECTORY_SEPARATOR), $defaultDestination . DIRECTORY_SEPARATOR . basename($rootFolder), true)->shouldBeCalled();
     $sut = $this->make_instance();
     $sut->symlink($this->event->reveal());
 }
Beispiel #20
0
 public function beforeSuite(SuiteEvent $e)
 {
     $suite = str_replace('\\', '_', $e->getSuite()->getName());
     $this->logHandler = new RotatingFileHandler($this->path . $suite, $this->config['max_files']);
 }
Beispiel #21
0
 public function receiveModuleContainer(SuiteEvent $e)
 {
     $this->modules = $e->getSuite()->getModules();
 }
Beispiel #22
0
    /**
     * @param SuiteEvent $e
     */
    protected function buildResultsTable(SuiteEvent $e)
    {
        $this->columns = array(40, 5);
        foreach ($e->getSuite()->tests() as $test) {
            if ($test instanceof TestCase) {
                $this->columns[0] = max(
                    $this->columns[0],
                    20 + strlen($test->getFeature()) + strlen($test->getFileName())
                );
                continue;
            }
            if ($test instanceof \PHPUnit_Framework_TestSuite_DataProvider) {
                $test = $test->testAt(0);
                $output_length = $test instanceof \Codeception\TestCase
                    ? strlen($test->getFeature()) + strlen($test->getFileName())
                    : $test->toString();

                $this->columns[0] = max(
                    $this->columns[0],
                    15 +$output_length
                );
                continue;
            }
            $this->columns[0] = max($this->columns[0], 10 + strlen($test->toString()));
        }
    }
 public function afterSuite(\Codeception\Event\SuiteEvent $e)
 {
     $name = $e->getSettings()['class_name'];
     teamcity_console_logger(MessageTemplate::TestSuiteEnd($name));
     teamcity_console_logger(MessageTemplate::BlockEnd($name));
 }
 public function suiteBefore(SuiteEvent $suiteEvent)
 {
     $suite = $suiteEvent->getSuite();
     $suiteName = $suite->getName();
     $event = new TestSuiteStartedEvent($suiteName);
     if (class_exists($suiteName)) {
         $annotationManager = new Annotation\AnnotationManager(Annotation\AnnotationProvider::getClassAnnotations(get_class($suite)));
         $annotationManager->updateTestSuiteEvent($event);
     }
     $this->uuid = $event->getUuid();
     $this->getLifecycle()->fire($event);
 }
 public function beforeSuite(SuiteEvent $event)
 {
     if (!is_null($this->resource)) {
         $this->stopServer();
     }
     $settings = $event->getSettings();
     $config = [];
     if (array_key_exists("extensions", $settings)) {
         if (array_key_exists("config", $settings["extensions"])) {
             if (array_key_exists("Codeception\\Extension\\PhpBuiltinServer", $settings["extensions"]["config"])) {
                 $config = $settings["extensions"]["config"]["Codeception\\Extension\\PhpBuiltinServer"];
             }
         }
     }
     $this->config = array_merge($this->orgConfig, $config);
     $this->validateConfig();
     $this->startServer();
     if (isset($settings["extensions"]["enabled"]) && in_array(trim(get_class($this), "/"), $settings["extensions"]["enabled"])) {
         $this->startServer();
     }
     // dummy to keep reference to this instance, so that it wouldn't be destroyed immediately
 }
Beispiel #26
0
 public function stopOnFail(SuiteEvent $e)
 {
     $e->getResult()->stopOnError(true);
     $e->getResult()->stopOnFailure(true);
 }
 /**
  * After suite callback
  *
  * @param \Codeception\Event\SuiteEvent $e
  */
 public function afterSuite(SuiteEvent $e)
 {
     if ($e->getSuite()->getName() === 'acceptance') {
         $this->afterSuiteAcceptance($e);
     }
 }
Beispiel #28
0
 public function beforeSuite(SuiteEvent $e)
 {
     foreach (SuiteManager::$modules as $module) {
         $module->_beforeSuite($e->getSettings());
     }
 }
Beispiel #29
0
 /**
  * @param SuiteEvent $e
  */
 protected function buildResultsTable(SuiteEvent $e)
 {
     $this->columns = [40, 5];
     foreach ($e->getSuite()->tests() as $test) {
         if ($test instanceof TestCase) {
             $this->columns[0] = max($this->columns[0], 20 + strlen($test->getFeature()) + strlen($test->getFileName()));
             continue;
         }
         if ($test instanceof \PHPUnit_Framework_TestSuite_DataProvider) {
             $test = $test->testAt(0);
             $output_length = $test instanceof TestCase ? strlen($test->getFeature()) + strlen($test->getFileName()) : strlen($test->toString());
             $this->columns[0] = max($this->columns[0], 15 + $output_length);
             continue;
         }
         $this->columns[0] = max($this->columns[0], 10 + strlen($test->toString()));
     }
     $cols = $this->columns[0];
     if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && php_sapi_name() == "cli" && getenv('TERM') && getenv('TERM') != 'unknown') {
         $cols = intval(`command -v tput >> /dev/null 2>&1 && tput cols`);
     }
     if ($cols < $this->columns[0]) {
         $this->columns[0] = $cols - $this->columns[1];
     }
 }
 /**
  * Handle SUITE_BEFORE event.
  *
  * Create a full standalone TYPO3 instance within typo3temp/var/tests/acceptance,
  * create a database and create database schema.
  *
  * @param SuiteEvent $suiteEvent
  * @throws Exception
  */
 public function bootstrapTypo3Environment(SuiteEvent $suiteEvent)
 {
     $testbase = new Testbase();
     $testbase->enableDisplayErrors();
     $testbase->defineBaseConstants();
     $testbase->defineOriginalRootPath();
     $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests/acceptance');
     $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
     $instancePath = ORIGINAL_ROOT . 'typo3temp/var/tests/acceptance';
     $testbase->defineTypo3ModeBe();
     $testbase->setTypo3TestingContext();
     $testbase->removeOldInstanceIfExists($instancePath);
     // Basic instance directory structure
     $testbase->createDirectory($instancePath . '/fileadmin');
     $testbase->createDirectory($instancePath . '/typo3temp/var/transient');
     $testbase->createDirectory($instancePath . '/typo3temp/assets');
     $testbase->createDirectory($instancePath . '/typo3conf/ext');
     $testbase->createDirectory($instancePath . '/uploads');
     // Additionally requested directories
     foreach ($this->additionalFoldersToCreate as $directory) {
         $testbase->createDirectory($instancePath . '/' . $directory);
     }
     $testbase->createLastRunTextfile($instancePath);
     $testbase->setUpInstanceCoreLinks($instancePath);
     // ext:styleguide is always loaded
     $testExtensionsToLoad = array_merge(['typo3conf/ext/styleguide'], $this->testExtensionsToLoad);
     $testbase->linkTestExtensionsToInstance($instancePath, $testExtensionsToLoad);
     $testbase->linkPathsInTestInstance($instancePath, $this->pathsToLinkInTestInstance);
     $localConfiguration = $testbase->getOriginalDatabaseSettingsFromEnvironmentOrLocalConfiguration();
     $originalDatabaseName = $localConfiguration['DB']['Connections']['Default']['dbname'];
     // Append the unique identifier to the base database name to end up with a single database per test case
     $localConfiguration['DB']['Connections']['Default']['dbname'] = $originalDatabaseName . '_at';
     $testbase->testDatabaseNameIsNotTooLong($originalDatabaseName, $localConfiguration);
     // Set some hard coded base settings for the instance. Those could be overruled by
     // $this->configurationToUseInTestInstance if needed again.
     $localConfiguration['BE']['debug'] = true;
     $localConfiguration['BE']['lockHashKeyWords'] = '';
     $localConfiguration['BE']['installToolPassword'] = '******';
     $localConfiguration['SYS']['isInitialInstallationInProgress'] = false;
     $localConfiguration['SYS']['isInitialDatabaseImportDone'] = true;
     $localConfiguration['SYS']['displayErrors'] = false;
     $localConfiguration['SYS']['debugExceptionHandler'] = '';
     $localConfiguration['SYS']['trustedHostsPattern'] = 'localhost:8000';
     $localConfiguration['SYS']['encryptionKey'] = 'iAmInvalid';
     // @todo: This sql_mode should be enabled as soon as styleguide and dataHandler can cope with it
     //$localConfiguration['SYS']['setDBinit'] = 'SET SESSION sql_mode = \'STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY\';';
     $localConfiguration['SYS']['caching']['cacheConfigurations']['extbase_object']['backend'] = NullBackend::class;
     $testbase->setUpLocalConfiguration($instancePath, $localConfiguration, $this->configurationToUseInTestInstance);
     $defaultCoreExtensionsToLoad = ['core', 'extbase', 'fluid', 'filelist', 'extensionmanager', 'lang', 'setup', 'rsaauth', 'saltedpasswords', 'backend', 'belog', 'install', 't3skin', 'frontend', 'recordlist', 'reports', 'sv', 'scheduler'];
     $testbase->setUpPackageStates($instancePath, $defaultCoreExtensionsToLoad, $this->coreExtensionsToLoad, $testExtensionsToLoad);
     $testbase->setUpBasicTypo3Bootstrap($instancePath);
     $testbase->setUpTestDatabase($localConfiguration['DB']['Connections']['Default']['dbname'], $originalDatabaseName);
     $testbase->loadExtensionTables();
     $testbase->createDatabaseStructure();
     // Unset a closure or phpunit kicks in with a 'serialization of \Closure is not allowed'
     // Alternative solution:
     // unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']['extbase']);
     $suite = $suiteEvent->getSuite();
     $suite->setBackupGlobals(false);
     foreach ($this->xmlDatabaseFixtures as $fixture) {
         $testbase->importXmlDatabaseFixture(ORIGINAL_ROOT . $fixture);
     }
     // styleguide generator uses DataHandler for some parts. DataHandler needs an initialized BE user
     // with admin right and the live workspace.
     Bootstrap::getInstance()->initializeBackendUser();
     $GLOBALS['BE_USER']->user['admin'] = 1;
     $GLOBALS['BE_USER']->user['uid'] = 1;
     $GLOBALS['BE_USER']->workspace = 0;
     Bootstrap::getInstance()->initializeLanguageObject();
     $styleguideGenerator = new Generator();
     $styleguideGenerator->create();
 }