-
Notifications
You must be signed in to change notification settings - Fork 297
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
LinkDB: move to a proper file, add test coverage #218
Conversation
66d380f
to
240c581
Compare
This is great, thank you. |
@nodiscc you're welcome ;-) IMO, this PR is not yet ready for being merged, as some aspects and conventions need to be defined. I've added a bunch of
|
I agree with @nodiscc, this is really great. I didn't really review the code itself, but it looks fine to me. Your TODOs in And according to coverage, this is definitely a good start: 2 notes:
|
No problem with #222, this PR will be rebased on
5.3 is a bit old, though :-)
HTML Coverage reports are definitely a plus, they're very convenient to browse for information
I usually don't add TODOs inside code when an issue tracker is available, but given the size of the PR, they may prove helpful when reviewing (think of them as memos)
|
I know and I don't think it's important, but it is worth mention it. It's probably easy to fix if we want to though.
Yep. I've just add
Yes, that's what I meant. :) So, what do you think this PR needs to be "mergeable"? |
I think I'll add a makefile target to generate the coverage report, and proof-read the code for typos; if everyone's OK with the current structure (classes going under |
Test coverage added, 2 reports are generated after running tests (provided Xdebug is installed & enabled):
The configuration takes place in
|
also great.
Your TODOs are very helpful and could be split in 2 categories
TODOs related to tests improvements, could be added as items in #71
I would also be ok with no PHP 5.3 compatibility
Rebasing large commits several times is cumbersome - though I just discovered N’arbitrez vos conflits Git qu’une fois grâce à rerere which looks excellent - so I'd be ok to merge this, when it is confirmed that is it better than what we have? = A question that comes to mind is: can the test methods be manipulated to malicious purposes when accessible on an Internet-facing Shaarli (data disclosure, data loss, filling up disk space with test results...). How do we test tests? |
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>
PR updated with By the way, when using Apache2, a lot of non-PHP resources are available through a browser, should we raise an issue to add a proper root
Hence the importance of ensuring test code is not reachable outside the CLI. I can test this PR against the following servers on Linux:
Do you know of other (commonly used) servers that would be subject to access vulnerabilities and would require further testing?
By nature, test code should never, ever, access or depend on production data. Enforcing this helps a lot in detecting unsafe, poorly written and/or untestable code.
i've been wondering this for some time now, with no satisfying answer but this general reasoning:
|
+1 for this pull request |
Just to know what all of you think about.. |
Thanks @nicolasdanelon for the link! It's good to have one more example for implementing tests and structuring code :)
Files and dirs can be excluded from deliverables, e.g. using a
Having test code provided along production code doesn't mean that test code is reachable from production servers.
There are (at least) two ways to perform this, with a similar end result:
Here's an example for Shaarli:
Some rewriting modules for popular Web servers:
Some web frameworks providing routing features: After a quick glance at PrestaShop's source code and deliverables, it looks like it uses a custom URL dispatcher, see classes/Dispatcher.php
TL;DR: may not be a priority for now (pre-1.0) Both software can hardly be compared:
While being kept secure, Shaarli must stay simple to setup, and server dependencies (packages, modules, configuration) should be avoided (users may not have access to them). A couple well-thought |
Awesome answer :) thanks @virtualtam |
Will merge on sunday 21.
|
Also keep in mind that tests are contained in PHP classes which are never instanciated. |
OK for merging, I'll take time to write a guide to running & writing tests :) |
Thanks! Merged. |
Documentation updated, thanks also for writing a clear summary. |
Relates to shaarli#218 Removes "hidden" access to the following variables: - $GLOBALS['config']['datastore'] - PHPPREFIX - PHPSUFFIX Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Relates to shaarli#218 Removes "hidden" access to the following variables: - $GLOBALS['config']['datastore'] - PHPPREFIX - PHPSUFFIX Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Relates to shaarli#95, shaarli#218 Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Hi all!
This is a first polished draft to bring unitary tests to Shaarli 😄
To help revewing the PR, and bring some logic to the test-writing process, I've split this comment in 3 sections:
As usual, feel free to comment the PR, make suggestions, ask for explanations... ^^
Commit message
Setup your environment for tests
The framework used is PHPUnit; it can be installed with Composer, which is a dependency management tool.
Regarding Composer, you can either use:
Sample usage
Install Shaarli dev dependencies
$ cd /path/to/shaarli $ composer update
Install and enable Xdebug to generate PHPUnit coverage reports
For Debian-based distros:
For ArchLinux:
Then add the following line to
/etc/php/php.ini
:zend_extension=xdebug.so
Run unit tests
$ make test
Development notes
The main aspects of the PR are to:
LinkDB
class fromindex.php
to its own fileSyntax
I've tried to stick to the PHP Standard Recommendations (PSR), especially:
To this effect:
Structure
As stated in a previous comment, classes have been moved under the
application
directory; feel free to suggest a more appropriate or explicit location (e.g.lib
,classes
,shaarlib
...)!