Ejemplo n.º 1
0
 /**
  * @param Request $request
  *
  * @return Response
  * @throws \Exception
  */
 public function doRequest($request)
 {
     $inputStream = fopen('php://memory', 'r+');
     $content = $request->getContent();
     if ($content !== null) {
         fwrite($inputStream, $content);
         rewind($inputStream);
     }
     $queryParams = [];
     $postParams = [];
     $queryString = parse_url($request->getUri(), PHP_URL_QUERY);
     if ($queryString != '') {
         parse_str($queryString, $queryParams);
     }
     if ($request->getMethod() !== 'GET') {
         $postParams = $request->getParameters();
     }
     $serverParams = $request->getServer();
     if (!isset($serverParams['SCRIPT_NAME'])) {
         //required by WhoopsErrorHandler
         $serverParams['SCRIPT_NAME'] = 'Codeception';
     }
     $zendRequest = new ServerRequest($serverParams, $this->convertFiles($request->getFiles()), $request->getUri(), $request->getMethod(), $inputStream, $this->extractHeaders($request));
     $zendRequest = $zendRequest->withCookieParams($request->getCookies())->withQueryParams($queryParams)->withParsedBody($postParams);
     $cwd = getcwd();
     chdir(codecept_root_dir());
     $this->application->run($zendRequest);
     chdir($cwd);
     $this->request = $zendRequest;
     $response = $this->responseCollector->getResponse();
     $this->responseCollector->clearResponse();
     return new Response($response->getBody(), $response->getStatusCode(), $response->getHeaders());
 }
Ejemplo n.º 2
0
 protected function makeTestCase($file, $name = '')
 {
     return Stub::make('\Codeception\Lib\DescriptiveTestCase', [
             'getReportFields' => ['file' => codecept_root_dir() . $file],
             'getName' => $name]
     );
 }
Ejemplo n.º 3
0
 public function testShortcutFilter()
 {
     $config = ['coverage' => ['include' => ['tests/*'], 'exclude' => ['tests/unit/CodeGuy.php']]];
     $this->filter->whiteList($config);
     $fileFilter = $this->filter->getFilter();
     $this->assertFalse($fileFilter->isFiltered(codecept_root_dir('tests/unit/c3Test.php')));
     $this->assertTrue($fileFilter->isFiltered(codecept_root_dir('tests/unit/CodeGuy.php')));
 }
 /**
  * Get the Drupal root directory.
  *
  * @return string
  *   The root directory of the Drupal installation.
  */
 private function getDrupalRoot()
 {
     // We can't get getcwd() as a default parameter, so this will have to do.
     if (is_null($this->config['drupalRoot'])) {
         return codecept_root_dir();
     } else {
         // If a user has passed in a path to their Drupal root, then we'll still need to append the current working
         // directory to it.
         return codecept_root_dir($this->config['drupalRoot']);
     }
 }
Ejemplo n.º 5
0
 public function testOneFileWithHtml()
 {
     $this->config['path'] = 'tests/data/claypit/tests/skipped/';
     $this->config['class_name'] = 'SkipGuy';
     $this->execute(array('suite' => 'skipped', '--single-file' => true, '--format' => 'html'));
     $this->assertEquals(codecept_root_dir() . 'tests/data/scenarios/skipped.html', $this->filename);
     $this->assertContains('<h3>I WANT TO MAKE IT INCOMPLETE</h3>', $this->content);
     $this->assertContains('<h3>I WANT TO SKIP IT</h3>', $this->content);
     $this->assertContains('<body><h3>', $this->content);
     $this->assertContains('</body></html>', $this->content);
     $this->assertContains('* Skip_Me rendered', $this->output);
     $this->assertContains('* Incomplete_Me rendered', $this->output);
 }
 /**
  * Get the Drupal root directory.
  *
  * @return string
  *   The root directory of the Drupal installation.
  */
 public function getDrupalRoot()
 {
     // We can't get getcwd() as a default parameter, so this will have to do.
     if (is_null($this->config['root'])) {
         return codecept_root_dir();
     }
     // Allow a user to pass an relative or an absolute path.
     if (is_null($this->config['relative']) || $this->config['relative'] !== 'yes') {
         return $this->config['root'];
     } else {
         return codecept_root_dir($this->config['root']);
     }
 }
Ejemplo n.º 7
0
 /**
  * Called after suite.
  *
  * Fail the suite and output changes, if any differences was detected.
  */
 public function _afterSuite()
 {
     // Filter out files that's disappeared. This allows for processing
     // the files before we've finished the test run.
     $changes = array_filter($this->changes, function ($file) {
         return file_exists($file . self::NEWSUFFIX);
     });
     if (!empty($changes)) {
         $fileLines = array_map(function ($file) {
             $short_name = preg_replace('/^' . preg_quote(codecept_root_dir(), '/') . '/', '', $file);
             if (file_exists($file . self::SUFFIX)) {
                 return "Changed: " . $short_name . self::NEWSUFFIX;
             }
             return "New: " . $short_name . self::NEWSUFFIX;
         }, $changes);
         $message = "Visual changes detected:\n";
         $message .= implode("\n", $fileLines);
         $this->fail($message);
     }
 }
Ejemplo n.º 8
0
 protected function _before()
 {
     $this->tarotDeck = new TarotDeck('custom', [codecept_root_dir() . 'resources/']);
     $this->tarotDraw = new TarotDraw($this->tarotDeck);
 }
Ejemplo n.º 9
0
<?php

/**
 * @file Global bootstrap for all codeception tests
 */
Codeception\Util\Autoload::addNamespace('Tribe__Events__WP_UnitTestCase', __DIR__ . '/_support');
Codeception\Util\Autoload::addNamespace('Tribe\\Events\\Test', __DIR__ . '/_support');
require_once codecept_root_dir('tribe-autoload.php');
Ejemplo n.º 10
0
 /**
  * @return string
  */
 protected function getRootFolder()
 {
     return isset($this->config['rootFolder']) ? $this->config['rootFolder'] : rtrim(codecept_root_dir(), DIRECTORY_SEPARATOR);
 }
Ejemplo n.º 11
0
 public function _initialize()
 {
     if (!is_file(codecept_root_dir() . $this->config['configFile'])) {
         throw new ModuleConfigException(__CLASS__, "The application config file does not exist: " . codecept_root_dir() . $this->config['configFile']);
     }
     $this->defineConstants();
 }
 public function getLocalConfigFilePath()
 {
     return codecept_root_dir('commands-config.yml');
 }
Ejemplo n.º 13
0
function codecept_relative_path($path)
{
    return substr($path, strlen(codecept_root_dir()));
}
Ejemplo n.º 14
0
 public function _beforeSuite($settings = [])
 {
     $store = null;
     if ($this->ormModule instanceof DataMapper) {
         // for Doctrine
         $store = new RepositoryStore($this->ormModule->_getEntityManager());
     }
     $this->factoryMuffin = new FactoryMuffin($store);
     if ($this->config['factories']) {
         foreach ((array) $this->config['factories'] as $factoryPath) {
             $realpath = realpath(codecept_root_dir() . $factoryPath);
             if ($realpath === false) {
                 throw new ModuleException($this, 'The path to one of your factories is not correct. Please specify the directory relative to the codeception.yml file (ie. _support/factories).');
             }
             $this->factoryMuffin->loadFactories($realpath);
         }
     }
 }
 /**
  * @param InputInterface $input
  * @return mixed|string
  */
 protected function getSetupFilePath(InputInterface $input)
 {
     $destination = $input->getOption('destination');
     $file = $destination ? $destination : codecept_root_dir('setup.yml');
     return $file;
 }
 protected function getFixturePath($fixture)
 {
     return codecept_root_dir() . $this->config['fixtures'] . "/" . $fixture . '.yml';
 }
Ejemplo n.º 17
0
 public function _beforeSuite($settings = [])
 {
     if (!class_exists('League\\FactoryMuffin\\FactoryMuffin')) {
         throw new \Exception('FactoryMuffin not installed. Please add `"league/factory-muffin": "^3.0"` to composer.json');
     }
     if (!class_exists('League\\FactoryMuffin\\Faker\\Facade')) {
         throw new \Exception('FactoryMuffin requires Faker integration. Please add `"league/factory-muffin-faker": "^1.0"` to composer.json');
     }
     $store = null;
     if ($this->ormModule instanceof DataMapper) {
         // for Doctrine
         $store = new RepositoryStore($this->ormModule->_getEntityManager());
     }
     $this->factoryMuffin = new FactoryMuffin($store);
     if ($this->config['factories']) {
         foreach ((array) $this->config['factories'] as $factoryPath) {
             $this->factoryMuffin->loadFactories(realpath(codecept_root_dir() . $factoryPath));
         }
     }
 }
Ejemplo n.º 18
0
 protected function _before()
 {
     $this->filename = __DIR__ . DIRECTORY_SEPARATOR . basename(codecept_root_dir());
     $this->filesystem = $this->prophesize('tad\\WPBrowser\\Filesystem\\Filesystem');
     $this->filesystem->is_dir(__DIR__)->willReturn(true);
     $this->filesystem->is_writeable(__DIR__)->willReturn(true);
     $this->event = $this->prophesize('\\Codeception\\Event\\SuiteEvent');
     $this->printEvent = $this->prophesize('\\Codeception\\Event\\PrintResultEvent');
 }
Ejemplo n.º 19
0
<?php

// Here you can initialize variables that will be available to your tests
require codecept_root_dir() . '/src/Lottery.php';
Ejemplo n.º 20
0
 /**
  * @param string $folder = null The absolute path to the WordPress root installation folder.
  *
  * @throws ModuleConfigException
  */
 protected function loadConfigFile($folder = null)
 {
     $folder = $folder ?: codecept_root_dir();
     $frags = $this->config['configFile'];
     $frags = is_array($frags) ?: [$frags];
     foreach ($frags as $frag) {
         if (!empty($frag)) {
             $configFile = Utils::findHereOrInParent($frag, $folder);
             if (!file_exists($configFile)) {
                 throw new ModuleConfigException(__CLASS__, "\nConfig file `{$frag}` could not be found in WordPress root folder or above.");
             }
             require_once $configFile;
         }
     }
 }
Ejemplo n.º 21
0
 protected function _before()
 {
     $this->instance = new Engine(new Suit([codecept_root_dir() . 'resources/'], 'yml'));
 }
Ejemplo n.º 22
0
    /**
     * @test
     * it should support loops in execs
     */
    public function it_should_support_loops_in_execs()
    {
        $dir = vfsStream::setup();
        $configFile = new vfsStreamFile('conf.yaml');
        $configFileContent = <<<YAML
foo:
    exec:
        for: loopVar in one,two,three 
        value: touch \$loopVar.txt
YAML;
        $configFile->setContent($configFileContent);
        $dir->addChild($configFile);
        $application = new Application();
        $application->add(new Setup());
        $command = $application->find('setup');
        $commandTester = new CommandTester($command);
        $helper = $command->getHelper('question');
        $helper->setInputStream($this->getInputStream("12\n"));
        $commandTester->execute(['command' => $command->getName(), 'config' => $dir->url() . '/conf.yaml']);
        $expectedFiles = [codecept_root_dir('one.txt'), codecept_root_dir('two.txt'), codecept_root_dir('three.txt')];
        foreach ($expectedFiles as $expectedFile) {
            $this->assertFileExists($expectedFile);
        }
        foreach ($expectedFiles as $file) {
            unlink($file);
        }
    }
Ejemplo n.º 23
0
 public function _after(\Codeception\TestCase $test)
 {
     $this->getModule('Filesystem')->deleteDir(codecept_data_dir() . 'sandbox');
     Config::setOutput(new ConsoleOutput());
     chdir(codecept_root_dir());
 }
 protected function tearDown()
 {
     if (file_exists(codecept_root_dir('fake-tests-dir'))) {
         unlinkDir(codecept_root_dir('fake-tests-dir'));
     }
 }
Ejemplo n.º 25
0
 public function _after(\Codeception\TestCase $test)
 {
     $this->getModule('Filesystem')->deleteDir(codecept_data_dir() . 'sandbox');
     \Robo\Runner::setPrinter(null);
     chdir(codecept_root_dir());
 }
Ejemplo n.º 26
0
 public function _after(\Codeception\TestCase $test)
 {
     $this->getModule('Filesystem')->deleteDir(codecept_data_dir() . 'sandbox');
     $this->getContainer()->add('output', new ConsoleOutput());
     chdir(codecept_root_dir());
 }
Ejemplo n.º 27
0
<?php

// This is global bootstrap for autoloading
use Codeception\Util\Autoload;
Autoload::addNamespace('consultnn\\helpers', codecept_root_dir());
Ejemplo n.º 28
0
 protected function _before()
 {
     $this->path = codecept_root_dir() . 'resources/';
     $this->tarotDeck = new TarotDeck('custom', [$this->path]);
 }