Extensions Testing

Hello Yii community!

I’ve been scratching an itch with a little extension I wrote and would like to release it more publicly but want to be sure to provide proper tests before doing so. This has brought up two questions for me:

  • What’s the proper protocol for packaging and running tests with extensions? I’ve not seen too much writing on the subject and really would like to package my tests with the release. I realize I could include a tests/ folder and just expect users to copy it over but is there a better way?

  • When a test involves interacting with a datafile (eg, opening, closing, writing), is there a best practice for dealing with the file? Should I package a sample file and copy / write / destroy? Should I attempt to file_put_contents on the fly? Is there a preferred location for temporary test data files to live?

Thank you so much for your help. Looking forward to giving back a bit.

  1. Providing tests directory is OK, I think. You’ll need to provide a readme about how to run tests as well. I believe PHPUnit is able to run tests w/o copying them anywhere.

  2. Test definitely should clean up all the mess it did. So delete temp files after these are used. A good place to store temp files is runtime directory. By default it’s located in your protected dir.

btw., you should have about 3 or 5 posts to be able to publish your extension into extensions section at Yii website.

Thanks Samdark, I’ll keep that all in mind. Runtime directory is a big help. Just couldn’t seem to find the right place for it.