-
Notifications
You must be signed in to change notification settings - Fork 294
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
Add Unit Tests to improve stability and avoid code regressions #71
Comments
Unit tests would be great to have.
We could start by moving classes to a |
By experience, it's safer to first cover features with unit tests, then you can see what is broken / hidden when refactoring (in other words, "blind" refactoring, along with being a tedious task, is definitely not recommended...). I think there is an historical & practical reason for Shaarli to be made of a single file, but, as it is now comprised of several resource (style, images, templates) subdirs, it would greatly benefit of having a more modular shape (a better readability makes spotting bugs and maintaining code way easier). |
I really like the idea of creating unit tests. The original goal of @sebsauvage was indeed to have everything contained in
As far as I'm concerned, we're past the "fits in a single file" stage, and I agree with creating the unit tests first, and then refactoring into [0] |
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to declare dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to declare dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Related #130 (comment):
|
|
A few things to check for:
|
Some test-able points:
And the way more advanced stuff (for the sole sake of awareness):
As a starter, I suggest writing tests for the
if it's OK, I'll start working on a PR to experiment unit test features; as usual, any feedback will be much appreciated :) |
Yep, please proceed! A well commented test script would help. It's still a bit unclear to me how/what to test. |
Relates to shaarli#71 Coverage: - constructor. Utilities: - Composer: PHPUnit; - Makefile: test target. TODO: - write the actual tests; - factorize test config (globals, settings) - more Makefile options: - code coverage; - test discovery - output formatting. TODO (to be discussed): - make LinkDB code PSR-compliant; - reformat code comments; - use PHP's autoload for Shaarli classes. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Coverage: - constructor. Utilities: - Composer: PHPUnit; - Makefile: test target. TODO: - write the actual tests; - factorize test config (globals, settings) - more Makefile options: - code coverage; - test discovery; - output formatting. TODO (to be discussed): - make LinkDB code PSR-compliant; - reformat code comments; - use PHP's autoload for Shaarli classes. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Coverage: - constructor. Utilities: - Composer: PHPUnit; - Makefile: test target. TODO: - write the actual tests; - factorize test config (globals, settings) - more Makefile options: - update lint targets; - code coverage; - test discovery; - output formatting. TODO (to be discussed): - make LinkDB code PSR-compliant; - reformat code comments; - use PHP's autoload for Shaarli classes. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Coverage: - constructor. Utilities: - Composer: PHPUnit; - Makefile: test target. TODO: - write the actual tests; - factorize test config (globals, settings) - more Makefile options: - update lint targets; - code coverage; - test discovery; - output formatting. TODO (to be discussed): - make LinkDB code PSR-compliant; - use PHP's autoload for Shaarli classes. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Coverage: - constructor. Utilities: - Composer: PHPUnit; - Makefile: test target. TODO: - write the actual tests; - factorize test config (globals, settings) - more Makefile options: - update lint targets; - code coverage; - test discovery; - output formatting. TODO (to be discussed): - make LinkDB code PSR-compliant; - use PHP's autoload for Shaarli classes. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Coverage: - constructor. Utilities: - Composer: add PHPUnit to dev dependencies; - Makefile: - update lint targets; - add test targets. TODO: - write the actual tests; - more Makefile options: - code coverage; - test discovery; - output formatting. TODO (to be discussed): - make LinkDB code PSR-compliant; - use PHP's autoload for Shaarli classes. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Relates to shaarli#71 Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Relates to shaarli#71 Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Relates to shaarli#71 Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Relates to shaarli#71 LinkDB - move to application/LinkDB.php - code cleanup - indentation - whitespaces - formatting - comment cleanup - add missing documentation - unify formatting Test coverage for LinkDB - constructor - public / private access - link-related methods Shaarli utilities (LinkDB dependencies) - move startsWith() and endsWith() functions to application/Utils.php - add test coverage Dev utilities - Composer: add PHPUnit to dev dependencies - Makefile: - update lint targets - add test targets - generate coverage reports Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Relates to shaarli#71 LinkDB - move to application/LinkDB.php - code cleanup - indentation - whitespaces - formatting - comment cleanup - add missing documentation - unify formatting Test coverage for LinkDB - constructor - public / private access - link-related methods Shaarli utilities (LinkDB dependencies) - move startsWith() and endsWith() functions to application/Utils.php - add test coverage Dev utilities - Composer: add PHPUnit to dev dependencies - Makefile: - update lint targets - add test targets - generate coverage reports Signed-off-by: VirtualTam <virtualtam@flibidi.net>
I did a demo on integration tests (running against a webserver) over there: #16 (comment) Maybe that's interesting to add (testing not multiple source distributions, but the current github code only). What do you guys think? P.S.: a driver to run the tests may be mink - see http://robbiemackay.com/2013/05/03/automating-behat-and-mink-tests-with-travis-ci/ |
@mro thanks for taking the first step towards functional testing ;-) After a quick glance to phptestdemo, it seems to fairly increase the complexity of the Travis configuration, and will require a bit of tuning to get a minimal setup suitable to testing Shaarli. Some comments & ideas:
I have to admit I'm quite enthusiastic with experimenting functional testing, which could be introduced starting #333 - Refactor HTTP / Url functions (HTTP requests and response headers involved) |
@virtualtam things may not be so easy (when testing multiple shaarli versions as I want to do). See https://travis-ci.org/mro/phptestdemo/builds/78607719 The issues there - even with a extremely simple test - are:
Both restrictions may be acceptable for this community shaarli. See https://github.com/mro/phptestdemo/tree/feature/docker |
Regarding the port limitation, I wonder if authbind could be used within a Travis docker appliance to allow serving on Example (provided chmod/chown are available): touch /etc/authbind/byport/80
chmod 500 /etc/authbind/byport/80
chown <MY_PROCESS_USER> /etc/authbind/byport/80 |
ok, pushed the integration tests a bit further, see #16 (comment) |
Closing this generic thread as we're improving test coverage along code refactoring. |
The core of Shaarli is a big chunk of PHP:
index.php
.It contains all the methods, which doesn't make editing and debugging convenient (lack of modularity). A good way to avoid bugs and regressions would be to implement unit testing, starting with sensitive features:
This could be done with a unit test framework like PHPUnit; see the awesome Kanboard project for an example implementation.
Some readings about the pros of unit testing everything:
The text was updated successfully, but these errors were encountered: