yii2-app-basic icon indicating copy to clipboard operation
yii2-app-basic copied to clipboard

Namespace and path inconsistencies with Yii2 Testing documentation

Open vercotux opened this issue 6 years ago • 5 comments

This is not a question. It is an issue pointing out the inconsistencies between this project, the yii2 testing documentation and other yii2 components, which have resulted in costing developers dozens of workhours trying to figure out.

In the Yii2 Testing Documentation the namespace for codeception unit tests is shown as: namespace app\tests\unit\models;

Meanwhile in yii2-app-basic (which also uses codeception) the namespace for codeception unit tests is: namespace tests\models;.

Which convention are we supposed to follow? Why are they different?

The whole thing becomes even more confusing when you try to figure out fixtures. According to Yii2 Testing Documentation, test fixtures are supposed to be located under the following namespace: app\tests\fixtures

But then the same documentation says:

By default fixtures will be searched under tests\unit\fixtures namespace

This seems to match the default path for fixtures generated by yii2-faker which is @tests/unit/fixtures/data

However, the Yii2 Testing Documentation then gives an example of the data path as:

// fixture data located in tests/_data/user.php
'dataFile' => codecept_data_dir() . 'user.php'

Why? That is not where yii2-faker puts the generated data by default and the documentation does not explain why it is different.

Could we please do something about it? IMO the template apps and other related components should accurately reflect what is described in the documentation, not implement it in their own unique way.

vercotux avatar Nov 09 '17 06:11 vercotux

Seems to be related to yiisoft/yii2-faker#31.

ricpelo avatar Feb 24 '18 17:02 ricpelo

Aside from that, why fixtures should be inside the unit directory? Are fixtures related only to unit testing, and not to functional or acceptance testing?

ricpelo avatar Feb 24 '18 17:02 ricpelo

I've split this issue into tree different ones with their corresponding PR's:

Issue PR
yiisoft/yii2-app-basic#170 yiisoft/yii2-app-basic#171
yiisoft/yii2#15769 yiisoft/yii2#15770
yiisoft/yii2-faker#33 yiisoft/yii2-faker#34

ricpelo avatar Feb 25 '18 11:02 ricpelo

These changes, in addition to providing necessary consistency, brings compatibility with extensions like ElisDN/yii2-gii-fixture-generator:

public $fixtureNs = 'tests\fixtures';
public $dataPath = '@tests/fixtures/data';

See: https://github.com/ElisDN/yii2-gii-fixture-generator/blob/648782b60d346a17baa273a32e9a424717b6f0c9/src/Generator.php#L20-L22

ricpelo avatar Feb 25 '18 15:02 ricpelo

Bumped the same confusion. tests\* is not working . Am going to change everything to app\tests*

mtangoo avatar Nov 01 '19 15:11 mtangoo