Skip to content

Commit 3579d06

Browse files
authored
detect the suite from a test path relative to the current working dir (Codeception#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 Codeception#4432
1 parent 9b174d1 commit 3579d06

File tree

10 files changed

+97
-5
lines changed

10 files changed

+97
-5
lines changed

src/Codeception/Command/Run.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class Run extends Command
117117
*/
118118
protected $output;
119119

120-
121120
/**
122121
* Sets Run arguments
123122
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException
@@ -456,9 +455,28 @@ protected function matchSingleTest($suite, $config)
456455
}
457456
}
458457

459-
// Run single test without included tests
460-
if (! Configuration::isEmpty() && strpos($suite, $config['paths']['tests']) === 0) {
461-
return $this->matchTestFromFilename($suite, $config['paths']['tests']);
458+
if (! Configuration::isEmpty()) {
459+
// Run single test without included tests
460+
if (strpos($suite, $config['paths']['tests']) === 0) {
461+
return $this->matchTestFromFilename($suite, $config['paths']['tests']);
462+
}
463+
464+
// Run single test from working directory
465+
$realTestDir = realpath(Configuration::testsDir());
466+
$cwd = getcwd();
467+
if (strpos($realTestDir, $cwd) === 0) {
468+
$file = $suite;
469+
if (strpos($file, ':') !== false) {
470+
list($file) = explode(':', $suite, -1);
471+
}
472+
$realPath = $cwd . DIRECTORY_SEPARATOR . $file;
473+
if (file_exists($realPath) || is_dir($realPath)) {
474+
return $this->matchTestFromFilename(
475+
$cwd . DIRECTORY_SEPARATOR . $suite,
476+
$realTestDir
477+
);
478+
}
479+
}
462480
}
463481
}
464482

@@ -487,7 +505,6 @@ protected function runIncludedSuites($suites, $parent_dir)
487505
}
488506
}
489507

490-
491508
protected function currentNamespace()
492509
{
493510
$config = Configuration::config();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
class CodeceptionYmlInRandomDirCest
3+
{
4+
/**
5+
* @param CliGuy $I
6+
*/
7+
public function runTestPath(\CliGuy $I)
8+
{
9+
$I->amInPath('tests/data/codeception_yml_in_random_dir');
10+
$I->executeCommand('run -c random/subdir/codeception.yml tests/unit/ExampleCest.php');
11+
12+
$I->seeResultCodeIs(0);
13+
$I->dontSeeInShellOutput('RuntimeException');
14+
$I->dontSeeInShellOutput('could not be found');
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
actor: Tester
2+
paths:
3+
tests: ../../tests
4+
log: ../../tests/_output
5+
data: ../../tests/_data
6+
support: ../../tests/_support
7+
settings:
8+
bootstrap: ../../tests/_bootstrap.php
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
// This is global bootstrap for autoloading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
/**
5+
* Inherited Methods
6+
* @method void wantToTest($text)
7+
* @method void wantTo($text)
8+
* @method void execute($callable)
9+
* @method void expectTo($prediction)
10+
* @method void expect($prediction)
11+
* @method void amGoingTo($argumentation)
12+
* @method void am($role)
13+
* @method void lookForwardTo($achieveValue)
14+
* @method void comment($description)
15+
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
16+
*
17+
* @SuppressWarnings(PHPMD)
18+
*/
19+
class UnitTester extends \Codeception\Actor
20+
{
21+
use _generated\UnitTesterActions;
22+
23+
/**
24+
* Define custom actions here
25+
*/
26+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Codeception Test Suite Configuration
2+
#
3+
# Suite for unit (internal) tests.
4+
5+
class_name: UnitTester
6+
modules:
7+
enabled:
8+
- Asserts
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
class ExampleCest
4+
{
5+
public function successful(UnitTester $I)
6+
{
7+
$I->assertTrue(true);
8+
}
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
// Here you can initialize variables that will be available to your tests

0 commit comments

Comments
 (0)