Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect the suite from a test path relative to the current working dir #6051

Merged
merged 4 commits into from Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 25 additions & 11 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 @@ -429,12 +428,6 @@ public function execute(InputInterface $input, OutputInterface $output)

protected function matchSingleTest($suite, $config)
{
// Workaround when codeception.yml is inside tests directory and tests path is set to "."
// @see https://github.com/Codeception/Codeception/issues/4432
if (isset($config['paths']['tests']) && $config['paths']['tests'] === '.' && !preg_match('~^\.[/\\\]~', $suite)) {
$suite = './' . $suite;
}

// running a single test when suite has a configured path
if (isset($config['suites'])) {
foreach ($config['suites'] as $s => $suiteConfig) {
Expand All @@ -443,6 +436,9 @@ protected function matchSingleTest($suite, $config)
}
$testsPath = $config['paths']['tests'] . DIRECTORY_SEPARATOR . $suiteConfig['path'];
if ($suiteConfig['path'] === '.') {
if ($config['paths']['tests'] === '.') {
return ['', $s, $suite];
ctrl-f5 marked this conversation as resolved.
Show resolved Hide resolved
}
$testsPath = $config['paths']['tests'];
}
if (preg_match("~^$testsPath/(.*?)$~", $suite, $matches)) {
Expand All @@ -453,9 +449,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 @@ -484,7 +499,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