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

Allow running specific tests without .php extension #1531

Merged
merged 6 commits into from Dec 19, 2014

Conversation

@antonioribeiro
Copy link
Contributor

@antonioribeiro antonioribeiro commented Nov 11, 2014

This is only to allow people to run tests using

codecept run functional MyCept

instead of

codecept run functional MyCept.php
$filepath = str_replace([$this->path, '\\'], ['', '/'], $file);

// If the file doesn't exists AND there it has is no .php extension,
// add the extension

This comment has been minimized.

@Ragazzo

Ragazzo Nov 11, 2014
Contributor

can you fix wording a little bit ?

This comment has been minimized.

@antonioribeiro

antonioribeiro Nov 11, 2014
Author Contributor

Better?

        // Add the path to the file name.
        $filepath = str_replace([$this->path, '\\'], ['', '/'], $file);

        // If the file doesn't exists AND it has no .php extension,
        // add the extension.
        if (!file_exists($filepath) && substr($filepath, -strlen(self::PHPEXT)) !== self::PHPEXT) {
            $filepath .= self::PHPEXT;
        }

This comment has been minimized.

@Ragazzo

Ragazzo Nov 11, 2014
Contributor

yes, is was confusing, can you also put it on one line, since for several lines /* */ is used )

@Ragazzo
Copy link
Contributor

@Ragazzo Ragazzo commented Nov 11, 2014

I like it , was about to do the same 👍 tired of specyfing .php , since there is no autocomplite in console for this purpose

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Nov 11, 2014

Can I run specific methods from tests?

codecept run functional MyCest:testLogin

will this work?

@antonioribeiro
Copy link
Contributor Author

@antonioribeiro antonioribeiro commented Nov 11, 2014

Yes it does

codecept pnh

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Nov 12, 2014

Sorry I was fighting my router all day long, and didn't have a chance to get into the internet.
I will take a look at this PR tomorrow

@MasonM
Copy link
Contributor

@MasonM MasonM commented Nov 14, 2014

👍 nice

@zbateson
Copy link
Member

@zbateson zbateson commented Nov 14, 2014

I love the idea, but there are a couple of issues with the solution IMHO.

The file_exists call will always return false. The path it's testing in the example above would be 'Codeception/TestLoaderTest' not 'tests/unit/Codeception/TestLoaderTest', so it can never be true from what I can tell.

The const doesn't seem that useful to me. I think it would be more readable if it was just '.php'.

This makes me wonder however if this solution is appropriately placed. Perhaps it makes more sense in loadTest where the full path can be tested properly.

This would also allow us to use full paths if we want, which would give us the sought-after autocomplete as well 👯

An extra if (!file_exists(...)) after checking if the extension is needed could check if the path is relative from the current dir rather than relative from tests/suitename.

Something like:

$relative = $this->relativeName($path);
if (!file_exists($path) && file_exists($relative)) {
    $path = $relative;
}

(not exactly because it would be better to check the other way around - currently $path is updated first but that may not make sense if we wanted to do something like this)

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Nov 17, 2014

I agree with @zbateson, this should be improved.

@antonioribeiro
Copy link
Contributor Author

@antonioribeiro antonioribeiro commented Nov 17, 2014

I probably agree too :) But I was out. As soon as I get home I'll take a
better look at it.

On Monday, November 17, 2014, Michael Bodnarchuk notifications@github.com
wrote:

I agree with @zbateson https://github.com/zbateson, this should be
improved.


Reply to this email directly or view it on GitHub
#1531 (comment)
.

Enviado do meu iPad 3 - Texto nao acentuado propositalmente

@antonioribeiro
Copy link
Contributor Author

@antonioribeiro antonioribeiro commented Nov 18, 2014

Changed the logic a little bit and moved it to loadTest(), as pointed by @zbateson, first file_exists() doesn't take relative paths and that first one would never return true. Added makePath() and findPath() methods to reduce repetition and to not give too much responsibility to loadTest(). And now it also checks for files relative to the current directory, so it will work if you do:

codecept run unit tests/unit/Codeception/TestLoaderTest

Tested the solution with the following command lines:

codecept run unit Codeception
codecept run unit Codeception:testAddCept

codecept run unit /var/www/myapp.dev/vendor/codeception/codeception/tests/unit/Codeception
codecept run unit /var/www/myapp.dev/vendor/codeception/codeception/tests/unit/Codeception:testAddCept

codecept run unit Codeception/TestLoaderTest.php
codecept run unit Codeception/TestLoaderTest
codecept run unit Codeception/TestLoaderTest.php:testAddCept
codecept run unit Codeception/TestLoaderTest:testAddCept

codecept run unit /var/www/myapp.dev/vendor/codeception/codeception/tests/unit/Codeception/TestLoaderTest.php
codecept run unit /var/www/myapp.dev/vendor/codeception/codeception/tests/unit/Codeception/TestLoaderTest.php:testAddCept
codecept run unit /var/www/myapp.dev/vendor/codeception/codeception/tests/unit/Codeception/TestLoaderTest
codecept run unit /var/www/myapp.dev/vendor/codeception/codeception/tests/unit/Codeception/TestLoaderTest:testAddCept

codecept run unit tests/unit/Codeception
codecept run unit tests/unit/Codeception:testAddCept
codecept run unit tests/unit/Codeception/TestLoaderTest.php
codecept run unit tests/unit/Codeception/TestLoaderTest.php:testAddCept
codecept run unit tests/unit/Codeception/TestLoaderTest
codecept run unit tests/unit/Codeception/TestLoaderTest:testAddCept

Travis almost gave me a heart attack failing on 4aeefb4, but it was something in their server.

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Dec 19, 2014

Thanks to @antonioribeiro and @zbateson
It is a really useful improvement.

DavertMik added a commit that referenced this pull request Dec 19, 2014
Allow running specific tests without .php extension
@DavertMik DavertMik merged commit 70742c7 into Codeception:2.0 Dec 19, 2014
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
@antonioribeiro
Copy link
Contributor Author

@antonioribeiro antonioribeiro commented Dec 19, 2014

Thanks for merging it! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.