-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Starting test suite for Craft #3382
Conversation
Added a base class test(future) Added a json tester class and method Added more date time testing methods Added more app testing methods
Added 3 new tests to the date time helper. Added db helper test Added html helper test
Removed date.timezone from config tests Added emoji filtering to the filterByValue Added a mock of the component helper Fixed bugs with the datetimehelper abstraction and a value misread Fixed a typo in the db helper added a second brace to the html helper mocks Corrected an assumption for the json test Added a mock for the urlhelper
…and fixed some bugs.
… with string test
…l support for tests aswell
Added assetManagerConfig to config checker. Refactored the exception check in string test Moved view test to under the /web dir
Added namespace and license to view test Added correct license to all test classes
Some 'stubbing' is done to avoid working directly with Craft::$app->getSession(); Sessions in php CLI can be strange and it serves no added purpose to test this. Plus its nice to have an example in the codebase on a way to mock/stub classes.
@narration-sd Thanks! Appreciate it! I wanted to post an update on the test suite's current position. I managed to make more progress over the holidays on learning more about testing and adding more tests on the Testing philosophyIt must be noted that the tests aren't strict 'unit' tests in the traditional sense. Strict unit testing commonly means that a lot of mocking must be done to isolate the function/block of code you are trying to test. This has several upsides however it does limit the scope of the test. The schematic plugin implements this style of testing in a really good way. See https://github.com/nerds-and-company/schematic/blob/master/tests/_support/Helper/Unit.php and you will see that the Rather than mocking all parts of the Craft service locator, I opted for a more integration focused approach. In the current test suite the An awsome comparison of the difference between these testing styles can be found here: https://martinfowler.com/articles/mocksArentStubs.html Craft module:This week I will be adding a commit that ensures the Craft codeception module can do the following things:
All of this will be configurable via the codeception.yml file. The module extends the Yii2 module so no functionality is lost. Conclusion:@angrybrad The testing philosophy is something I want to get your opinion on. Have there been any internal discussions at P&T on whether to use a more mocking focused style of testing versus a more integration focused style? If a more mocking style is preffered (i.e the schematic plugin) it wont be that much work to rewrite the tests to reflect this. Timeline wise after the Craft module is complete I want to return to complete the |
Might need to get feedback on this. Might be a more effecient way to do this that iam overlooking (re: mocking)
@lemiwinkz Thanks for your patience and the awesome work, Giel. We've spent the afternoon wrapping our head around the PR and think it's a great starting point. Have merged this into a branch here (https://github.com/craftcms/cms/tree/feature/tests) and will be working on it from there before merging into |
As discussed over Slack with @angrybrad i have been working on several tests for the helpers and validators for Craft. These tests are relatively low hanging fruit and they aren't many in numbers but its a start atleast.
Conventions followed
Followed the Yii 2 convention of namespacing the tests with craftunit\
Mock implementations of classes are found under _support/mockclasses. These classes are used to test method such as
craft\helpers\Db::prepareValueForDb()
where we need to test what happens if a serializable is passed in.DB tests for the helpers are found under helpers/dbhelper/* Mysql or PostgreSql specific tests have their own specific test suite that gets skipped if the DB env is not applicable. This is done because for some functions inside this helper can result in different outputs with the same input I.E Running
craft\helpers\Db::parseParam
on 'grez can return different results than MySql in certain conditions.One or two problems
On some tests we are getting issues with coverage simply because getting
\Craft::$app->getRequest()->getIsCpRequest()
to return true has proven difficult.Also some Db helper tests are missing because i first want to figure out a different way to setup the test environment. Currently using the MySql dump works however it is painfully slow when running more tests. More importantly running tests with a Postgres .dump file is very buggy (atleast when i attempted it). Ill open up a separate issue to float the potential idea of setting up and breaking down the test environment with the
install.php
migration as this should be far more performant and should work equally on MySql and 'grez - aswell as provide a test for this specific code aswell which is an added bonus.From here
Ill start working on finalizing the final tests for the above suite(a couple assertions are still missing) and move on to the Element and Migration helper. I want to get the helpers and validators done first and then start moving into the services.
Ill also start working on a Craft base plugin class which should also provide some support services for plugin/module testing and to see how we can setup fixtures for Craft's element types. In general i want see how we can integrate the work done by Bob Olde Hampsink/Robuust over at: https://github.com/robuust/craft-fixtures into the core.
Anyway. Thats my ramble done 👍. If theres anything that needs fixing ill be happy to hear it!