dr Anton
dr Anton

Reputation: 124

Why there is a folder tests in a root of yii2 framework?

It is basic template. I use this command to generate test file and run:

$ ./vendor/bin/codecept generate:test unit Example
$ ./vendor/bin/codecept run

This file appears in folder /vendor/bin/tests/unit. I can't push this file to GitHub. Why test files appear in vendor folder? What Should I do to make test files save in tests folder in the root of the project?

Upvotes: 1

Views: 308

Answers (1)

ajmedway
ajmedway

Reputation: 1492

You will need to debug your paths and resolve the config issue that is causing this.

The path used is set on line 45 of file: vendor/codeception/base/src/Codeception/Command/GenerateTest.php

There you will see this code, which creates the new directory:

$path = $this->createDirectoryFor($config['path'], $class);

The value of $config['path'] is determined in method suiteSettings, line 285 in file vendor/codeception/base/src/Codeception/Configuration.php

Here you will see this code, which sets the path for the config:

    $settings['path'] = self::$dir . DIRECTORY_SEPARATOR . $config['paths']['tests']
        . DIRECTORY_SEPARATOR . $settings['path'] . DIRECTORY_SEPARATOR;

Add the following code before these 2 lines:

    echo 'self::$dir ' . print_r(self::$dir, true) . PHP_EOL;
    echo '$config[paths][tests] ' . print_r($config['paths']['tests'], true) . PHP_EOL;
    echo '$settings[path] ' . print_r($settings['path'], true) . PHP_EOL;
    exit;

Now, run your command again to execute this debug code:

./vendor/bin/codecept generate:test unit Example

For my setup, which is generating tests in <system_root>/public_html/basic/tests/unit/ExampleTest.php from the same commands as you, I see the following:

  • self::$dir => <system_root>/public_html/basic
  • $config[paths][tests] => tests
  • $settings[path] => unit

OBSERVATION - From your comment I see that your codeception.yml file is correct with default values for various testing subdirectories.

RECOMMENDATIONS

$config[paths][tests] appears to be wrong in your case - debug this and resolve the path config based on your findings.

Note that there is a core codeception.yml in the vendor package and also there should be one in your app root, i.e.

  • <system_root>/public_html/basic/vendor/codeception/base/codeception.yml

  • <system_root>/public_html/basic/codeception.yml

Values in the latter take precedence!

Upvotes: 2

Related Questions