Skip to content

Commit

Permalink
detect the suite from a test path relative to the current working dir (
Browse files Browse the repository at this point in the history
…#6051)

* detect the suite from a test path relative to the current working directory

* when tests and suite paths are "." we can safely set the suite

* test for codeception.yaml in random subdir

* revert generic solution for #4432
  • Loading branch information
ctrl-f5 committed Jan 23, 2021
1 parent 9b174d1 commit 3579d06
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Codeception/Command/Run.php
Expand Up @@ -117,7 +117,6 @@ class Run extends Command
*/
protected $output;


/**
* Sets Run arguments
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException
Expand Down Expand Up @@ -456,9 +455,28 @@ protected function matchSingleTest($suite, $config)
}
}

// Run single test without included tests
if (! Configuration::isEmpty() && strpos($suite, $config['paths']['tests']) === 0) {
return $this->matchTestFromFilename($suite, $config['paths']['tests']);
if (! Configuration::isEmpty()) {
// Run single test without included tests
if (strpos($suite, $config['paths']['tests']) === 0) {
return $this->matchTestFromFilename($suite, $config['paths']['tests']);
}

// Run single test from working directory
$realTestDir = realpath(Configuration::testsDir());
$cwd = getcwd();
if (strpos($realTestDir, $cwd) === 0) {
$file = $suite;
if (strpos($file, ':') !== false) {
list($file) = explode(':', $suite, -1);
}
$realPath = $cwd . DIRECTORY_SEPARATOR . $file;
if (file_exists($realPath) || is_dir($realPath)) {
return $this->matchTestFromFilename(
$cwd . DIRECTORY_SEPARATOR . $suite,
$realTestDir
);
}
}
}
}

Expand Down Expand Up @@ -487,7 +505,6 @@ protected function runIncludedSuites($suites, $parent_dir)
}
}


protected function currentNamespace()
{
$config = Configuration::config();
Expand Down
16 changes: 16 additions & 0 deletions tests/cli/CodeceptionYmlInRandomDirCest.php
@@ -0,0 +1,16 @@
<?php
class CodeceptionYmlInRandomDirCest
{
/**
* @param CliGuy $I
*/
public function runTestPath(\CliGuy $I)
{
$I->amInPath('tests/data/codeception_yml_in_random_dir');
$I->executeCommand('run -c random/subdir/codeception.yml tests/unit/ExampleCest.php');

$I->seeResultCodeIs(0);
$I->dontSeeInShellOutput('RuntimeException');
$I->dontSeeInShellOutput('could not be found');
}
}
@@ -0,0 +1,8 @@
actor: Tester
paths:
tests: ../../tests
log: ../../tests/_output
data: ../../tests/_data
support: ../../tests/_support
settings:
bootstrap: ../../tests/_bootstrap.php
2 changes: 2 additions & 0 deletions tests/data/codeception_yml_in_random_dir/tests/_bootstrap.php
@@ -0,0 +1,2 @@
<?php
// This is global bootstrap for autoloading
@@ -0,0 +1,2 @@
*
!.gitignore
@@ -0,0 +1,26 @@
<?php


/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;

/**
* Define custom actions here
*/
}
@@ -0,0 +1,2 @@
*
!.gitignore
8 changes: 8 additions & 0 deletions tests/data/codeception_yml_in_random_dir/tests/unit.suite.yml
@@ -0,0 +1,8 @@
# Codeception Test Suite Configuration
#
# Suite for unit (internal) tests.

class_name: UnitTester
modules:
enabled:
- Asserts
@@ -0,0 +1,9 @@
<?php

class ExampleCest
{
public function successful(UnitTester $I)
{
$I->assertTrue(true);
}
}
@@ -0,0 +1,2 @@
<?php
// Here you can initialize variables that will be available to your tests

0 comments on commit 3579d06

Please sign in to comment.