1
votes

I created a custom component loaded by Composer.

Here is the structure of my code when my component is loaded.

  • MyProject
    • vendor
      • myComponent

AFTER that, I created the file myComponentTest.php to run an unit test with Codeception.

  • MyProject
    • tests
      • myComponentTest.php
    • vendor
      • myComponent

It works very well with the command :

./vendor/bin/codecept run

Alright. Nothing special about it. The Codeception test is ok ! :)


But I guess the procedure is wrong, the file myComponentTest.php should be in to the vendor/myComponent directory, am I right ?

Because, this unit test is only related to the component. For example, If I decide to remove the component, it won't remove my myComponentTet.php file, so I'll have some error when I'll run my unit tests.

BUT, if I move my MyComponentTest.php into the vendor/myComponent directory, I won't be able to run this test, because the Codeception command only execute tests from the tests directory.

So what should I do please ? I'm confused about that. Thanks.

1
There is no reason to run tests from vendor directory. You should make your component a separate composer library and run its tests when you work on that library, not when you work on your app. - Naktibalda

1 Answers

0
votes

See how testing is implemented in projects with sub-projects in Yii2 framework

codeception.yml in root project directory

include:
    - common
    - frontend
    - backend
paths:
    log: console/runtime/logs
settings:
    colors: true

Where common|frontend|backend directory with codeception.yml files

I hope this helps.