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

Calling script by class name (implied folder structure) #6089

Closed
alexkuc opened this issue Jan 14, 2021 · 6 comments
Closed

Calling script by class name (implied folder structure) #6089

alexkuc opened this issue Jan 14, 2021 · 6 comments

Comments

@alexkuc
Copy link

alexkuc commented Jan 14, 2021

Currently, I have a nested structure of folders for my scripts, e.g.

tests
tests / folder
tests / folder / subfolder
tests / folder / subfolder / test1.php

Is it possible to call test1 without specify the full path?

Currently, if I call codecept run <suite> test1, I get error:

File or path test1 not found

But if I call via full path, it works fine:

codecept run <suite> folder/subfolder/test1.php 

Looking at Loader.php, I can see that it is looking for file path, instead of class names.

So I guess my scenario is unsupported?

@Naktibalda
Copy link
Member

The closest thing you can do is filter by test name - codecept run <suite> :Test1

@alexkuc
Copy link
Author

alexkuc commented Jan 16, 2021

This is perfect and worked for me as expected i.e. executed exactly that specific test.

Is this mentioned in the docs? I have checked Commands#Run but this use case was not mentioned.

I can create a PR to update the docs if you feel this feature should be publicly documented.

@Naktibalda
Copy link
Member

It is a variation of codecept run acceptance MyCest:myTestInIt without class name.

@alexkuc
Copy link
Author

alexkuc commented Jan 18, 2021

I am not sure if I follow the format.

Here's what I did - https://github.com/alexkuc/codeception-issue-6089

Example 1 - running codecept run unit TestCest:

Codeception PHP Testing Framework v4.1.15
Powered by PHPUnit 9.5.1 by Sebastian Bergmann and contributors.

In Loader.php line 96:

  File or path TestCest not found

Example 2 - running codecept run unit :TestCest:

Codeception PHP Testing Framework v4.1.15
Powered by PHPUnit 9.5.1 by Sebastian Bergmann and contributors.

Unit Tests (2) -------------------------------------------------------------------------------------
✔ TestCest: Boring test (0.00s)
✔ TestCest: Interesting test (0.00s)
----------------------------------------------------------------------------------------------------


Time: 00:00.111, Memory: 8.00 MB

OK (2 tests, 0 assertions)

Example 3 - running codecept run unit TestCest:BoringTest:

Codeception PHP Testing Framework v4.1.15
Powered by PHPUnit 9.5.1 by Sebastian Bergmann and contributors.

In Loader.php line 96:

  File or path TestCest not found

Example 4 - running codecept run unit :TestCest:BoringTest:

Codeception PHP Testing Framework v4.1.15
Powered by PHPUnit 9.5.1 by Sebastian Bergmann and contributors.

Unit Tests (1) -------------------------------------------------------------------------------------
✔ TestCest: Boring test (0.00s)
----------------------------------------------------------------------------------------------------


Time: 00:00.202, Memory: 8.00 MB

OK (1 test, 0 assertions)

In summary,

command outcome
codecept run unit TestCest not found
codecept run unit :TestCest test found - all test methods run
codecept run unit TestCest:BoringTest not found
codecept run unit :TestCest:BoringTest test found - runs specific method

@alexkuc
Copy link
Author

alexkuc commented Jan 27, 2021

So after experimenting more I have reached a conclusion that you can pass part of the namespace and it executes the appropriate tests:

Command Outcome
codecept run unit :Folder works
codecept run unit :SubFolder works

Tests taken from https://github.com/alexkuc/codeception-issue-6089

Docs for Run command do not mention that you can use namespace or part of it.

Is it something missing from documentation? Or did I misunderstand something?

@Naktibalda
Copy link
Member

Namespace is part of class name.
:foo is equivalent to using --filter foo with PHPUnit and it filters by class name and/or method name.

There are some examples of using filters in https://codeception.com/docs/02-GettingStarted#Running-Tests

When #6105 is merged, codecept run :Namespace will work too.

@alexkuc alexkuc closed this as completed Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants