public function setUp() { $this->dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher(); $this->testcase = new \Codeception\TestCase\Cept(); $this->testcase->configDispatcher($this->dispatcher)->configName('mocked test')->configFile(\Codeception\Configuration::dataDir() . 'SimpleCept.php')->initConfig(); \Codeception\SuiteManager::$modules['EmulateModuleHelper']->assertions = 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $suite = $input->getArgument('suite'); $config = \Codeception\Configuration::config(); $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config); @mkdir($path = \Codeception\Configuration::dataDir() . 'scenarios'); @mkdir($path = $path . DIRECTORY_SEPARATOR . $suite); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $suiteManager = new \Codeception\SuiteManager($dispatcher, $suite, $suiteconf); if (isset($suiteconf['bootstrap'])) { if (file_exists($suiteconf['path'] . $suiteconf['bootstrap'])) { require_once $suiteconf['path'] . $suiteconf['bootstrap']; } } $suiteManager->loadTests(); $tests = $suiteManager->getSuite()->tests(); foreach ($tests as $test) { if (!$test instanceof \Codeception\TestCase\Cept) { continue; } $test->loadScenario(); $features = $test->getScenarioText(); $name = $this->underscore(substr($test->getFileName(), 0, -8)); $output->writeln("* {$name} generated"); file_put_contents($path . DIRECTORY_SEPARATOR . $name . '.txt', $features); } }
public function setUp() { $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql'); $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql); $this->sql = explode("\n", $sql); $this->sqlite = Db::create($this->config['dsn'], $this->config['user'], $this->config['password']); $this->sqlite->cleanup(); }
protected function loadDump() { $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql'); $sql = preg_replace('%/\*(?:(?!\*/).)*\*/%s', "", $sql); $sql = explode("\n", $sql); $sqlite = \Codeception\Util\Driver\Db::create($this->config['dsn'], $this->config['user'], $this->config['password']); $sqlite->load($sql); }
/** * Constructor is setting up the path for the images * * @param array $config */ public function __construct(array $config) { if (array_key_exists('expectedImageDir', $config)) { $this->storageDir = $config["expectedImageDir"]; } else { $this->storageDir = \Codeception\Configuration::dataDir() . 'VisualCeption/expected/'; } }
public function setUp() { $this->module = new \Codeception\Module\REST(); $connector = new \Codeception\Util\Connector\Universal(); $connector->setIndex(\Codeception\Configuration::dataDir() . '/rest/index.php'); $this->module->client = $connector; $this->module->_before(Stub::makeEmpty('\\Codeception\\TestCase\\Cest')); $this->module->client->setServerParameters(array('SCRIPT_FILENAME' => 'index.php', 'SCRIPT_NAME' => 'index', 'SERVER_NAME' => 'localhost', 'SERVER_PROTOCOL' => 'http')); }
/** * When running multiple environments, getClassesFromFile() method in SuiteManager is called once for each env. * See \Codeception\Codecept::runSuite() - for each env new SuiteManager is created and tests loaded. * Make sure that calling getClassesFromFile() multiple times will always return the same classes. * * @group core */ public function testAddCestWithEnv() { $file = \Codeception\Configuration::dataDir() . 'SimpleCestWithNamespace.php'; $this->suiteman->addCest($file); $this->assertEquals(3, $this->suiteman->getSuite()->count()); $newSuiteMan = Stub::make('\\Codeception\\SuiteManager', array('dispatcher' => $this->dispatcher, 'suite' => new PHPUnit_Framework_TestSuite(), 'settings' => array('bootstrap' => false, 'class_name' => 'CodeGuy', 'namespace' => ''))); $newSuiteMan->addCest($file); $this->assertEquals(3, $newSuiteMan->getSuite()->count()); }
public function setUp() { $this->module = new \Codeception\Module\SOAP(make_container()); $this->module->_setConfig(array('schema' => 'http://www.w3.org/2001/xml.xsd', 'endpoint' => 'http://codeception.com/api/wsdl')); $this->layout = \Codeception\Configuration::dataDir() . '/xml/layout.xml'; $this->module->isFunctional = true; $this->module->_before(Stub::makeEmpty('\\Codeception\\Test\\Test')); $this->module->client = Stub::makeEmpty('\\Codeception\\Lib\\Connector\\Universal'); }
/** * When running multiple environments, getClassesFromFile() method in SuiteManager is called once for each env. * See \Codeception\Codecept::runSuite() - for each env new SuiteManager is created and tests loaded. * Make sure that calling getClassesFromFile() multiple times will always return the same classes. * * @group core */ public function testAddCestWithEnv() { $file = \Codeception\Configuration::dataDir() . 'SimpleNamespacedTest.php'; $this->suiteman->loadTests($file); $this->assertEquals(3, $this->suiteman->getSuite()->count()); $newSuiteMan = new \Codeception\SuiteManager($this->dispatcher, 'suite', \Codeception\Configuration::$defaultSuiteSettings); $newSuiteMan->loadTests($file); $this->assertEquals(3, $newSuiteMan->getSuite()->count()); }
public function setUp() { $this->dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher(); $conf = \Codeception\Configuration::config(); require_once \Codeception\Configuration::dataDir() . 'DummyClass.php'; $file = \Codeception\Configuration::dataDir() . 'SimpleCest.php'; require_once $file; $this->testcase = new \Codeception\TestCase\Cest($this->dispatcher, array('name' => '', 'file' => $file, 'class' => new SimpleCest(), 'method' => 'helloWorld', 'static' => false, 'signature' => 'DummyClass.helloWorld')); }
protected function setUp() { if (!extension_loaded('xdebug')) { $this->markTestSkipped('xdebug extension required for c3test.'); } $this->c3 = Configuration::dataDir() . 'claypit/c3.php'; $this->c3_dir = Configuration::dataDir() . 'claypit/c3tmp/'; $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE'] = 'test'; $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG'] = 'debug'; }
public function setUp() { require_once \Codeception\Configuration::dataDir() . '/services/UserModel.php'; require_once \Codeception\Configuration::dataDir() . '/services/UserService.php'; $this->test = $this->makeTest(); $this->scenario = $this->test->getScenario(); $this->module = new \Codeception\Module\Unit(); $this->module->_initialize(); $this->module->_before($this->test); }
public function setUp() { $connector = new \Codeception\Lib\Connector\Universal(); $connector->setIndex(\Codeception\Configuration::dataDir() . '/rest/index.php'); $connectionModule = new \Codeception\Module\PhpBrowser(); $connectionModule->client = $connector; $this->module = Stub::make('\\Codeception\\Module\\REST', ['getModules' => [$connectionModule]]); $this->module->_initialize(); $this->module->_before(Stub::makeEmpty('\\Codeception\\TestCase\\Cest')); $this->module->client->setServerParameters(['SCRIPT_FILENAME' => 'index.php', 'SCRIPT_NAME' => 'index', 'SERVER_NAME' => 'localhost', 'SERVER_PROTOCOL' => 'http']); }
public static function setUpBeforeClass() { $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql'); $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql); self::$sql = explode("\n", $sql); try { self::$sqlite = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']); self::$sqlite->cleanup(); } catch (\Exception $e) { } }
public static function setUpBeforeClass() { self::$module = new \Codeception\Module\Db(make_container()); self::$module->_setConfig(self::$config); self::$module->_initialize(); $sqlite = self::$module->driver; $sqlite->cleanup(); $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql'); $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql); $sql = explode("\n", $sql); $sqlite->load($sql); }
public function setUp() { $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/mysql.sql'); $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql); $this->sql = explode("\n", $sql); try { $this->mysql = Db::create($this->config['dsn'], $this->config['user'], $this->config['password']); } catch (\Exception $e) { $this->markTestSkipped('Coudn\'t establish connection to database'); return; } $this->mysql->cleanup(); }
public static function setUpBeforeClass() { if (getenv('APPVEYOR')) { self::$config['password'] = '******'; } $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/mysql.sql'); $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql); self::$sql = explode("\n", $sql); try { $mysql = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']); $mysql->cleanup(); } catch (\Exception $e) { } }
protected function execute(InputInterface $input, OutputInterface $output) { $suite = $input->getArgument('suite'); $config = \Codeception\Configuration::config($input->getOption('config')); $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config); if ($input->getOption('path')) { $path = $input->getOption('path'); } else { $path = \Codeception\Configuration::dataDir() . 'scenarios'; } @mkdir($path); if (!is_writable($path)) { throw new \Codeception\Exception\Configuration("Path for logs is not writable. Please, set appropriate access mode for log path."); } $path = $path . DIRECTORY_SEPARATOR . $suite; if ($input->getOption('single-file')) { file_put_contents($path . '.txt', ''); } else { @mkdir($path); } $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $suiteManager = new \Codeception\SuiteManager($dispatcher, $suite, $suiteconf); if ($suiteconf['bootstrap']) { if (file_exists($suiteconf['path'] . $suiteconf['bootstrap'])) { require_once $suiteconf['path'] . $suiteconf['bootstrap']; } } $suiteManager->loadTests(); $tests = $suiteManager->getSuite()->tests(); if ($input->getOption('format')) { $format = $input->getOption('format'); } else { $format = 'text'; } foreach ($tests as $test) { if (!$test instanceof \Codeception\TestCase\Cept) { continue; } $test->preload(); $features = $test->getScenarioText($format); $name = $this->underscore(substr($test->getFileName(), 0, -8)); if ($input->getOption('single-file')) { file_put_contents($path . '.txt', $features . PHP_EOL, FILE_APPEND); $output->writeln("* {$name} rendered"); } else { file_put_contents($path . DIRECTORY_SEPARATOR . $name . '.txt', $features); $output->writeln("* {$name} generated"); } } }
public function setUp() { if (!function_exists('pg_connect')) { return $this->markTestSkipped("Postgres extensions not loaded"); } $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/postgres.sql'); $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql); $this->sql = explode("\n", $sql); try { $this->postgres = Db::create($this->config['dsn'], $this->config['user'], $this->config['password']); } catch (\Exception $e) { $this->markTestSkipped('Coudn\'t establish connection to database'); return; } $this->postgres->cleanup(); }
private function mergeOptions($options) { foreach ($this->options as $option => $default) { $value = isset($options[$option]) ? $options[$option] : $default; if (!$value) { $options[$option] = isset($this->config['settings'][$option]) ? $this->config['settings'][$option] : $this->options[$option]; } } if ($options['report']) { $options['silent'] = true; } if ($options['html']) { $options['html'] = \Codeception\Configuration::dataDir() . 'result.html'; } return $options; }
protected function execute(InputInterface $input, OutputInterface $output) { $suite = $input->getArgument('suite'); $suiteConf = $this->getSuiteConfig($suite, $input->getOption('config')); $path = $input->getOption('path') ? $input->getOption('path') : Configuration::dataDir() . 'scenarios'; $format = $input->getOption('format'); @mkdir($path); if (!is_writable($path)) { throw new ConfigurationException("Path {$path} is not writable. Please, set valid permissions for folder to store scenarios."); } $path = $path . DIRECTORY_SEPARATOR . $suite; if (!$input->getOption('single-file')) { @mkdir($path); } $suiteManager = new \Codeception\SuiteManager(new EventDispatcher(), $suite, $suiteConf); if ($suiteConf['bootstrap']) { if (file_exists($suiteConf['path'] . $suiteConf['bootstrap'])) { require_once $suiteConf['path'] . $suiteConf['bootstrap']; } } $tests = $this->getTests($suiteManager); $scenarios = ""; foreach ($tests as $test) { if (!$test instanceof ScenarioDriven) { continue; } $feature = $test->getScenarioText($format); $name = $this->underscore(basename($test->getFileName(), '.php')); // create separate file for each test in Cest if ($test instanceof Cest && !$input->getOption('single-file')) { $name .= '.' . $this->underscore($test->getTestMethod()); } if ($input->getOption('single-file')) { $scenarios .= $feature; $output->writeln("* {$name} rendered"); } else { $feature = $this->decorate($feature, $format); $this->save($path . DIRECTORY_SEPARATOR . $name . $this->formatExtension($format), $feature, true); $output->writeln("* {$name} generated"); } } if ($input->getOption('single-file')) { $this->save($path . $this->formatExtension($format), $this->decorate($scenarios, $format), true); } }
/** * Initialize the module and read the config. * Throws a runtime exception, if the * reference image dir is not set in the config * * @throws \RuntimeException * @throws InvalidElementStateException */ public function _initialize() { if (array_key_exists('maximumDeviation', $this->config)) { $this->maximumDeviation = $this->config['maximumDeviation']; } if (array_key_exists('referenceDirectory', $this->config)) { $this->referenceScreenshotDirectory = $this->config['referenceDirectory']; } else { $this->referenceScreenshotDirectory = Configuration::dataDir() . 'Puffin/'; } if (!is_dir($this->referenceScreenshotDirectory) && !@mkdir($this->referenceScreenshotDirectory, 0777, true)) { throw new InvalidElementStateException('Unable to create screenshot directory'); } if (array_key_exists('currentImageDir', $this->config)) { $this->screenshotDirectory = $this->config['currentImageDir']; } else { $this->screenshotDirectory = Configuration::logDir() . 'debug/tmp/'; } }
/** * Aware of data provider * * @return array */ public function awareOfProvider() { // Return the providers if previously loaded static $providers = []; if (!empty($providers)) { // HHVM doesn't like yield... // foreach($providers as $k => $p){ // (yield $k => $p); // } return $providers; } // Faker is not available when in the context // of a data provider. We therefore must ensure to // create the instance if not already created. $faker = Factory::create(); // Source of providers $dataDir = Configuration::dataDir() . 'awareOf/'; // Obtain a list of all providers $finder = new Finder(); $finder->files()->name('*.php')->in($dataDir); // Load all found providers foreach ($finder as $file) { // Include file and obtain method $method = (include $file->getRealPath()); // Invoke the method and get the array $provider = $method($faker); // Merge provider into list of providers $providers = array_merge($providers, $provider); } // Finally, return the providers // HHVM doesn't like yield... // foreach($providers as $k => $p){ // (yield $k => $p); // } return $providers; }
public function __construct() { $this->client = new \Codeception\Lib\Connector\Universal(); $this->client->setIndex(\Codeception\Configuration::dataDir() . '/app/index.php'); }
public function setUp() { $conf = \Codeception\Configuration::config(); require_once $file = \Codeception\Configuration::dataDir() . 'DummyClass.php'; $this->dummy = new DummyClass(true); }
protected function _before() { $this->sourceLicense = Configuration::dataDir() . 'license/MyCustomLicense'; $this->destinationFolder = Configuration::outputDir(); }
protected function setUp() { $this->testLoader = new \Codeception\Test\Loader(['path' => \Codeception\Configuration::dataDir()]); }
public function attachFile($field, $filename) { $form = $this->getFormFor($field = $this->getFieldByLabelOrCss($field)); $path = Configuration::dataDir() . $filename; if (!is_readable($path)) { $this->fail("file {$filename} not found in Codeception data path. Only files stored in data path accepted"); } $form[$field->attr('name')]->upload($path); }
public static function setUpBeforeClass() { require_once \Codeception\Configuration::dataDir() . 'register_command/examples/MyCustomCommand.php'; }
/** * Returns absolute path to the requested object which is expected to be in * the data directory of a testing project. * * @since 1.0.1 * * @param string $appendPath A relative path to the requested object. * @return string The absolute path to the object. */ function codecept_data_dir($appendPath = '') { return \Codeception\Configuration::dataDir() . $appendPath; }