0

I am beginner Yii2 contributor. When I contribute in yiisoft/yii2 project, it is quite clear how to deploy the project and run its phpunit-tests. But I have some questions about working with extensions:

  1. First I add an extension with composer require. Then git clone the same extension inside my home directory. After that I replace the first directory with symlink, which pointed to the second one. It is quite convenient due to I can see changes on the site, but I can't use composer anymore.

  2. How to run the extension`s tests? They often depend on Yii2 app class, but

$ vendor/bin/phpunit vendor/yiisoft/yii2-elasticsearch/tests/
PHP Fatal error:  Class 'yiiunit\extensions\elasticsearch\TestCase' not found in /var/www/yii2.test/vendor/yiisoft/yii2-elasticsearch/tests/ActiveDataProviderTest.php on line 11
$ vendor/bin/phpunit vendor/yiisoft/yii2-queue/tests/
PHP Fatal error:  Class 'tests\TestCase' not found in /var/www/yii2.test/vendor/yiisoft/yii2-queue/tests/JobEventTest.php on line 22

Should I specify a config file? Or should I run these tests independently of the framework?

So, would you please share with me the best practices about this situation?

GHopper
  • 366
  • 4
  • 15

1 Answers1

1

You should run these tests outside of the framework. From extension perspective, yiisoft/yii2 is a dependency and should be installed in vendor directory inside of extension directory. So in short, you should go to extension directory and call composer install. After this you should get directory structure similar to this:

extension/
├── src/
│   └── ...
├── vendor/
│   ├── yiisoft/
│   │   ├── yii2/
│   │   └── ...
│   └── ...
├──composer.json
└── ...

Then you can run tests directly from extension directory (probably by vendor/bin/phpunit command).

rob006
  • 21,383
  • 5
  • 53
  • 74
  • Ok, it is clear now, but frustrates me a little. And can you tell some words about the first question? Is it a good idea to access the sources by symlink? How to perform vendors update after that? Is here any other way to get real-time result during the work? – GHopper Jan 21 '19 at 13:25
  • In perfect world you should not need to do this at all - extension should be standalone and all possible scenarios should be covered by unit tests. So there is no need to link extension to your application, to make any test. But if I really need to test some patch in my application, I'm adding `vcs` repository which points to my fork - in this way you may use power of git and composer at the same time. See [this answer](https://stackoverflow.com/a/50008138/5812455) for more details. – rob006 Jan 21 '19 at 14:39