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=
"../Copy-an-existing-installation-over-SSH-and-serve-it-locally/">Copy an existing installation over SSH and serve it locally
</a>
159 <a class=
"" href=
"../Create-and-serve-multiple-Shaarlis-(farm)/">Create and serve multiple Shaarlis (farm)
</a>
163 <a class=
"" href=
"../Download-CSS-styles-from-an-OPML-list/">Download CSS styles from an OPML list
</a>
167 <a class=
"" href=
"../Datastore-hacks/">Datastore hacks
</a>
172 <li class=
"toctree-l1">
174 <a class=
"" href=
"../Troubleshooting/">Troubleshooting
</a>
177 <li class=
"toctree-l1">
179 <span class=
"caption-text">Development
</span>
183 <a class=
"" href=
"../Development-guidelines/">Development guidelines
</a>
187 <a class=
"" href=
"../Continuous-integration-tools/">Continuous integration tools
</a>
191 <a class=
"" href=
"../GnuPG-signature/">GnuPG signature
</a>
195 <a class=
"" href=
"../Coding-guidelines/">Coding guidelines
</a>
199 <a class=
"" href=
"../Directory-structure/">Directory structure
</a>
203 <a class=
"" href=
"../3rd-party-libraries/">3rd party libraries
</a>
207 <a class=
"" href=
"../Plugin-System/">Plugin System
</a>
211 <a class=
"" href=
"../Release-Shaarli/">Release Shaarli
</a>
215 <a class=
"" href=
"../Versioning-and-Branches/">Versioning and Branches
</a>
219 <a class=
"" href=
"../Security/">Security
</a>
223 <a class=
"" href=
"../Static-analysis/">Static analysis
</a>
227 <a class=
"" href=
"../Theming/">Theming
</a>
229 <li class=
" current">
231 <a class=
"current" href=
"./">Unit tests
</a>
234 <li class=
"toctree-l3"><a href=
"#setup-your-environment-for-tests">Setup your environment for tests
</a></li>
238 <li><a class=
"toctree-l4" href=
"#sample-usage">Sample usage
</a></li>
240 <li><a class=
"toctree-l4" href=
"#install-shaarli-dev-dependencies">Install Shaarli dev dependencies
</a></li>
242 <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>
244 <li><a class=
"toctree-l4" href=
"#run-unit-tests">Run unit tests
</a></li>
246 <li><a class=
"toctree-l4" href=
"#test-results-and-coverage">Test results and coverage
</a></li>
251 <li class=
"toctree-l3"><a href=
"#executing-specific-tests">Executing specific tests
</a></li>
259 <li class=
"toctree-l1">
261 <span class=
"caption-text">About
</span>
265 <a class=
"" href=
"../FAQ/">FAQ
</a>
269 <a class=
"" href=
"../Community-&-Related-software/">Community & Related software
</a>
279 <section data-toggle=
"wy-nav-shift" class=
"wy-nav-content-wrap">
282 <nav class=
"wy-nav-top" role=
"navigation" aria-label=
"top navigation">
283 <i data-toggle=
"wy-nav-top" class=
"fa fa-bars"></i>
284 <a href=
"..">Shaarli Documentation
</a>
288 <div class=
"wy-nav-content">
289 <div class=
"rst-content">
290 <div role=
"navigation" aria-label=
"breadcrumbs navigation">
291 <ul class=
"wy-breadcrumbs">
292 <li><a href=
"..">Docs
</a> »</li>
296 <li>Development
»</li>
301 <li class=
"wy-breadcrumbs-aside">
303 <a href=
"https://github.com/shaarli/Shaarli/edit/master/docs/Unit-tests.md"
304 class=
"icon icon-github"> Edit on GitHub
</a>
311 <div class=
"section">
313 <h3 id=
"setup-your-environment-for-tests">Setup your environment for tests
</h3>
314 <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>
315 <p>Regarding Composer, you can either use:
316 <em> a system-wide version, e.g. installed through your distro's package manager
317 </em> a local version, downloadable
<a href=
"https://getcomposer.org/download/">here
</a></p>
318 <h4 id=
"sample-usage">Sample usage
</h4>
319 <pre><code class=
"bash"># system-wide version
324 $ php composer.phar self-update
325 $ php composer.phar install
326 $ php composer.phar update
329 <h4 id=
"install-shaarli-dev-dependencies">Install Shaarli dev dependencies
</h4>
330 <pre><code class=
"bash">$ cd /path/to/shaarli
334 <h4 id=
"install-and-enable-xdebug-to-generate-phpunit-coverage-reports">Install and enable Xdebug to generate PHPUnit coverage reports
</h4>
335 <p>For Debian-based distros:
</p>
336 <pre><code class=
"bash">$ aptitude install php5-xdebug
339 <p>For ArchLinux:
</p>
340 <pre><code class=
"bash">$ pacman -S xdebug
343 <p>Then add the following line to
<code>/etc/php/php.ini
</code>:
</p>
344 <pre><code class=
"ini">zend_extension=xdebug.so
347 <h4 id=
"run-unit-tests">Run unit tests
</h4>
348 <p>Successful test suite:
</p>
349 <pre><code class=
"bash">$ make test
354 PHPUnit
4.6.9 by Sebastian Bergmann and contributors.
356 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
358 ....................................
360 Time:
759 ms, Memory:
8.25Mb
362 OK (
36 tests,
65 assertions)
365 <p>Test suite with failures and errors:
</p>
366 <pre><code class=
"bash">$ make test
370 PHPUnit
4.6.9 by Sebastian Bergmann and contributors.
372 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
374 E..FF...............................
376 Time:
802 ms, Memory:
8.25Mb
380 1) LinkDBTest::testConstructLoggedIn
381 Missing argument
2 for LinkDB::__construct(), called in /home/virtualtam/public_html/shaarli/tests/Link\
382 DBTest.php on line
79 and defined
384 /home/virtualtam/public_html/shaarli/application/LinkDB.php:
58
385 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:
79
389 There were
2 failures:
391 1) LinkDBTest::testCheckDBNew
392 Failed asserting that two strings are equal.
396 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
397 +'
85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
399 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:
121
401 2) LinkDBTest::testCheckDBLoad
402 Failed asserting that two strings are equal.
406 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
407 +'
85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
409 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:
133
412 Tests:
36, Assertions:
63, Errors:
1, Failures:
2.
415 <h4 id=
"test-results-and-coverage">Test results and coverage
</h4>
416 <p>By default, PHPUnit will run all suitable tests found under the
<code>tests
</code> directory.
</p>
417 <p>Each test has
3 possible outcomes:
418 <em> <code>.
</code> - success
419 </em> <code>F
</code> - failure: the test was run but its results are invalid
420 * the code does not behave as expected
421 * dependencies to external elements: globals, session, cache...
422 *
<code>E
</code> - error: something went wrong and the tested code has crashed
423 * typos in the code, or in the test code
424 * dependencies to missing external elements
</p>
425 <p>If Xdebug has been installed and activated, two coverage reports will be generated:
426 <em> a summary in the console
427 </em> a detailed HTML report with metrics for tested code
428 * to open it in a web browser:
<code>firefox coverage/index.html
&</code></p>
429 <h3 id=
"executing-specific-tests">Executing specific tests
</h3>
430 <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>
431 <pre><code class=
"php">/**
432 * Netscape bookmark import
435 class BookmarkImportTest extends PHPUnit_Framework_TestCase
441 <p>To run all tests annotated with
<code>@group WIP
</code>:
</p>
442 <pre><code class=
"bash">$ vendor/bin/phpunit --group WIP tests/
449 <div class=
"rst-footer-buttons" role=
"navigation" aria-label=
"footer navigation">
451 <a href=
"../FAQ/" class=
"btn btn-neutral float-right" title=
"FAQ">Next
<span class=
"icon icon-circle-arrow-right"></span></a>
454 <a href=
"../Theming/" class=
"btn btn-neutral" title=
"Theming"><span class=
"icon icon-circle-arrow-left"></span> Previous
</a>
461 <div role=
"contentinfo">
462 <!-- Copyright etc -->
466 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>.
476 <div class=
"rst-versions" role=
"note" style=
"cursor: pointer">
477 <span class=
"rst-current-version" data-toggle=
"rst-current-version">
479 <a href=
"https://github.com/shaarli/Shaarli" class=
"fa fa-github" style=
"float: left; color: #fcfcfc"> GitHub
</a>
482 <span><a href=
"../Theming/" style=
"color: #fcfcfc;">« Previous
</a></span>
485 <span style=
"margin-left: 15px"><a href=
"../FAQ/" style=
"color: #fcfcfc">Next
»</a></span>
489 <script src=
"../js/theme.js"></script>