2 <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
3 <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
6 <meta http-equiv=
"X-UA-Compatible" content=
"IE=edge">
7 <meta name=
"viewport" content=
"width=device-width, initial-scale=1.0">
10 <link rel=
"shortcut icon" href=
"../img/favicon.ico">
11 <title>Unit tests - Shaarli Documentation
</title>
12 <link href='https://fonts.googleapis.com/css?family=Lato:
400,
700|Roboto+Slab:
400,
700|Inconsolata:
400,
700' rel='stylesheet' type='text/css'
>
14 <link rel=
"stylesheet" href=
"../css/theme.css" type=
"text/css" />
15 <link rel=
"stylesheet" href=
"../css/theme_extra.css" type=
"text/css" />
16 <link rel=
"stylesheet" href=
"../css/highlight.css">
17 <link href=
"../github-markdown.css" rel=
"stylesheet">
21 var mkdocs_page_name = "Unit tests";
22 var mkdocs_page_input_path = "Unit-tests.md";
23 var mkdocs_page_url = "/Unit-tests/";
26 <script src=
"../js/jquery-2.1.1.min.js"></script>
27 <script src=
"../js/modernizr-2.8.3.min.js"></script>
28 <script type=
"text/javascript" src=
"../js/highlight.pack.js"></script>
32 <body class=
"wy-body-for-nav" role=
"document">
34 <div class=
"wy-grid-for-nav">
37 <nav data-toggle=
"wy-nav-shift" class=
"wy-nav-side stickynav">
38 <div class=
"wy-side-nav-search">
39 <a href=
".." class=
"icon icon-home"> Shaarli Documentation
</a>
41 <form id =
"rtd-search-form" class=
"wy-form" action=
"../search.html" method=
"get">
42 <input type=
"text" name=
"q" placeholder=
"Search docs" />
47 <div class=
"wy-menu wy-menu-vertical" data-spy=
"affix" role=
"navigation" aria-label=
"main navigation">
51 <li class=
"toctree-l1">
53 <a class=
"" href=
"..">Home
</a>
56 <li class=
"toctree-l1">
58 <span class=
"caption-text">Setup
</span>
62 <a class=
"" href=
"../Download-and-Installation/">Download and Installation
</a>
66 <a class=
"" href=
"../Upgrade-and-migration/">Upgrade and migration
</a>
70 <a class=
"" href=
"../Server-requirements/">Server requirements
</a>
74 <a class=
"" href=
"../Server-configuration/">Server configuration
</a>
78 <a class=
"" href=
"../Server-security/">Server security
</a>
82 <a class=
"" href=
"../Shaarli-configuration/">Shaarli configuration
</a>
86 <a class=
"" href=
"../Plugins/">Plugins
</a>
91 <li class=
"toctree-l1">
93 <span class=
"caption-text">Docker
</span>
97 <a class=
"" href=
"../Docker-101/">Docker
101</a>
101 <a class=
"" href=
"../Shaarli-images/">Shaarli images
</a>
105 <a class=
"" href=
"../Reverse-proxy-configuration/">Reverse proxy configuration
</a>
109 <a class=
"" href=
"../Docker-resources/">Docker resources
</a>
114 <li class=
"toctree-l1">
116 <span class=
"caption-text">Usage
</span>
120 <a class=
"" href=
"../Features/">Features
</a>
124 <a class=
"" href=
"../Bookmarklet/">Bookmarklet
</a>
128 <a class=
"" href=
"../Browsing-and-searching/">Browsing and searching
</a>
132 <a class=
"" href=
"../Firefox-share/">Firefox share
</a>
136 <a class=
"" href=
"../RSS-feeds/">RSS feeds
</a>
140 <a class=
"" href=
"../REST-API/">REST API
</a>
145 <li class=
"toctree-l1">
147 <span class=
"caption-text">How To
</span>
151 <a class=
"" href=
"../Backup,-restore,-import-and-export/">Backup, restore, import and export
</a>
155 <a class=
"" href=
"../Various-hacks/">Various hacks
</a>
160 <li class=
"toctree-l1">
162 <a class=
"" href=
"../Troubleshooting/">Troubleshooting
</a>
165 <li class=
"toctree-l1">
167 <span class=
"caption-text">Development
</span>
171 <a class=
"" href=
"../Development-guidelines/">Development guidelines
</a>
175 <a class=
"" href=
"../Continuous-integration-tools/">Continuous integration tools
</a>
179 <a class=
"" href=
"../GnuPG-signature/">GnuPG signature
</a>
183 <a class=
"" href=
"../Coding-guidelines/">Coding guidelines
</a>
187 <a class=
"" href=
"../Directory-structure/">Directory structure
</a>
191 <a class=
"" href=
"../3rd-party-libraries/">3rd party libraries
</a>
195 <a class=
"" href=
"../Plugin-System/">Plugin System
</a>
199 <a class=
"" href=
"../Release-Shaarli/">Release Shaarli
</a>
203 <a class=
"" href=
"../Versioning-and-Branches/">Versioning and Branches
</a>
207 <a class=
"" href=
"../Security/">Security
</a>
211 <a class=
"" href=
"../Static-analysis/">Static analysis
</a>
215 <a class=
"" href=
"../Theming/">Theming
</a>
217 <li class=
" current">
219 <a class=
"current" href=
"./">Unit tests
</a>
222 <li class=
"toctree-l3"><a href=
"#setup-your-environment-for-tests">Setup your environment for tests
</a></li>
226 <li><a class=
"toctree-l4" href=
"#sample-usage">Sample usage
</a></li>
228 <li><a class=
"toctree-l4" href=
"#install-shaarli-dev-dependencies">Install Shaarli dev dependencies
</a></li>
230 <li><a class=
"toctree-l4" href=
"#install-and-enable-xdebug-to-generate-phpunit-coverage-reports">Install and enable Xdebug to generate PHPUnit coverage reports
</a></li>
232 <li><a class=
"toctree-l4" href=
"#run-unit-tests">Run unit tests
</a></li>
234 <li><a class=
"toctree-l4" href=
"#test-results-and-coverage">Test results and coverage
</a></li>
239 <li class=
"toctree-l3"><a href=
"#executing-specific-tests">Executing specific tests
</a></li>
247 <li class=
"toctree-l1">
249 <span class=
"caption-text">About
</span>
253 <a class=
"" href=
"../FAQ/">FAQ
</a>
257 <a class=
"" href=
"../Community-&-Related-software/">Community & Related software
</a>
267 <section data-toggle=
"wy-nav-shift" class=
"wy-nav-content-wrap">
270 <nav class=
"wy-nav-top" role=
"navigation" aria-label=
"top navigation">
271 <i data-toggle=
"wy-nav-top" class=
"fa fa-bars"></i>
272 <a href=
"..">Shaarli Documentation
</a>
276 <div class=
"wy-nav-content">
277 <div class=
"rst-content">
278 <div role=
"navigation" aria-label=
"breadcrumbs navigation">
279 <ul class=
"wy-breadcrumbs">
280 <li><a href=
"..">Docs
</a> »</li>
284 <li>Development
»</li>
289 <li class=
"wy-breadcrumbs-aside">
291 <a href=
"https://github.com/shaarli/Shaarli/edit/master/docs/Unit-tests.md"
292 class=
"icon icon-github"> Edit on GitHub
</a>
299 <div class=
"section">
301 <h3 id=
"setup-your-environment-for-tests">Setup your environment for tests
</h3>
302 <p>The framework used is
<a href=
"https://phpunit.de/">PHPUnit
</a>; it can be installed with
<a href=
"https://getcomposer.org/">Composer
</a>, which is a dependency management tool.
</p>
303 <p>Regarding Composer, you can either use:
304 <em> a system-wide version, e.g. installed through your distro's package manager
305 </em> a local version, downloadable
<a href=
"https://getcomposer.org/download/">here
</a></p>
306 <h4 id=
"sample-usage">Sample usage
</h4>
307 <pre><code class=
"bash"># system-wide version
312 $ php composer.phar self-update
313 $ php composer.phar install
314 $ php composer.phar update
317 <h4 id=
"install-shaarli-dev-dependencies">Install Shaarli dev dependencies
</h4>
318 <pre><code class=
"bash">$ cd /path/to/shaarli
322 <h4 id=
"install-and-enable-xdebug-to-generate-phpunit-coverage-reports">Install and enable Xdebug to generate PHPUnit coverage reports
</h4>
323 <p>For Debian-based distros:
</p>
324 <pre><code class=
"bash">$ aptitude install php5-xdebug
327 <p>For ArchLinux:
</p>
328 <pre><code class=
"bash">$ pacman -S xdebug
331 <p>Then add the following line to
<code>/etc/php/php.ini
</code>:
</p>
332 <pre><code class=
"ini">zend_extension=xdebug.so
335 <h4 id=
"run-unit-tests">Run unit tests
</h4>
336 <p>Successful test suite:
</p>
337 <pre><code class=
"bash">$ make test
342 PHPUnit
4.6.9 by Sebastian Bergmann and contributors.
344 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
346 ....................................
348 Time:
759 ms, Memory:
8.25Mb
350 OK (
36 tests,
65 assertions)
353 <p>Test suite with failures and errors:
</p>
354 <pre><code class=
"bash">$ make test
358 PHPUnit
4.6.9 by Sebastian Bergmann and contributors.
360 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
362 E..FF...............................
364 Time:
802 ms, Memory:
8.25Mb
368 1) LinkDBTest::testConstructLoggedIn
369 Missing argument
2 for LinkDB::__construct(), called in /home/virtualtam/public_html/shaarli/tests/Link\
370 DBTest.php on line
79 and defined
372 /home/virtualtam/public_html/shaarli/application/LinkDB.php:
58
373 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:
79
377 There were
2 failures:
379 1) LinkDBTest::testCheckDBNew
380 Failed asserting that two strings are equal.
384 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
385 +'
85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
387 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:
121
389 2) LinkDBTest::testCheckDBLoad
390 Failed asserting that two strings are equal.
394 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
395 +'
85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
397 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:
133
400 Tests:
36, Assertions:
63, Errors:
1, Failures:
2.
403 <h4 id=
"test-results-and-coverage">Test results and coverage
</h4>
404 <p>By default, PHPUnit will run all suitable tests found under the
<code>tests
</code> directory.
</p>
405 <p>Each test has
3 possible outcomes:
406 <em> <code>.
</code> - success
407 </em> <code>F
</code> - failure: the test was run but its results are invalid
408 * the code does not behave as expected
409 * dependencies to external elements: globals, session, cache...
410 *
<code>E
</code> - error: something went wrong and the tested code has crashed
411 * typos in the code, or in the test code
412 * dependencies to missing external elements
</p>
413 <p>If Xdebug has been installed and activated, two coverage reports will be generated:
414 <em> a summary in the console
415 </em> a detailed HTML report with metrics for tested code
416 * to open it in a web browser:
<code>firefox coverage/index.html
&</code></p>
417 <h3 id=
"executing-specific-tests">Executing specific tests
</h3>
418 <p>Add a
<a href=
"https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.group"><code>@group
</code></a> annotation in a test class or method comment:
</p>
419 <pre><code class=
"php">/**
420 * Netscape bookmark import
423 class BookmarkImportTest extends PHPUnit_Framework_TestCase
429 <p>To run all tests annotated with
<code>@group WIP
</code>:
</p>
430 <pre><code class=
"bash">$ vendor/bin/phpunit --group WIP tests/
437 <div class=
"rst-footer-buttons" role=
"navigation" aria-label=
"footer navigation">
439 <a href=
"../FAQ/" class=
"btn btn-neutral float-right" title=
"FAQ">Next
<span class=
"icon icon-circle-arrow-right"></span></a>
442 <a href=
"../Theming/" class=
"btn btn-neutral" title=
"Theming"><span class=
"icon icon-circle-arrow-left"></span> Previous
</a>
449 <div role=
"contentinfo">
450 <!-- Copyright etc -->
454 Built with
<a href=
"http://www.mkdocs.org">MkDocs
</a> using a
<a href=
"https://github.com/snide/sphinx_rtd_theme">theme
</a> provided by
<a href=
"https://readthedocs.org">Read the Docs
</a>.
464 <div class=
"rst-versions" role=
"note" style=
"cursor: pointer">
465 <span class=
"rst-current-version" data-toggle=
"rst-current-version">
467 <a href=
"https://github.com/shaarli/Shaarli" class=
"fa fa-github" style=
"float: left; color: #fcfcfc"> GitHub
</a>
470 <span><a href=
"../Theming/" style=
"color: #fcfcfc;">« Previous
</a></span>
473 <span style=
"margin-left: 15px"><a href=
"../FAQ/" style=
"color: #fcfcfc">Next
»</a></span>
477 <script src=
"../js/theme.js"></script>