Unit Testing Extensions

Hey guys,

This might be a really stupid question but I couldn’t find any information for the life of me so here I go:

I am currently working on an extension that I install into the vendor folder via composer. This extension extends Yii base classes and I would like to unit test it.

I can’t unit test on its own since it depends on Yii2 files.

How should I proceed? I’ve tried looking around for a bootstrap file etc… etc… No dice, I either get errors or path issues.

Thanks in advance guys.

As long as you don’t need a working app and just the framework files, you could add composer.lock and /vendor/* to your .gitignore(you should do that anyway, if you are developing a library/extension). You should be able to set-up you local testing environment using composer update --dev --prefer-dist. This should also work on travis (replace update with install)

Hey,

Thanks for taking the time to reply. Are you suggesting that I include Yii2 as a dependency for my extension (only in dev mode obviously). Is this the only option? I think it would work to some extent but you aren’t really testing how your extension would behave within Yii2. You might also be missing some bootstrap configuration via yii\base\BootstrapInterface ?