index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <!DOCTYPE html>
  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]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <link rel="shortcut icon" href="../img/favicon.ico">
  9. <title>Unit tests - Shaarli Documentation</title>
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>
  11. <link rel="stylesheet" href="../css/theme.css" type="text/css" />
  12. <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
  13. <link rel="stylesheet" href="../css/highlight.css">
  14. <link href="../github-markdown.css" rel="stylesheet">
  15. <script>
  16. // Current page data
  17. var mkdocs_page_name = "Unit tests";
  18. var mkdocs_page_input_path = "Unit-tests.md";
  19. var mkdocs_page_url = "/Unit-tests/";
  20. </script>
  21. <script src="../js/jquery-2.1.1.min.js"></script>
  22. <script src="../js/modernizr-2.8.3.min.js"></script>
  23. <script type="text/javascript" src="../js/highlight.pack.js"></script>
  24. </head>
  25. <body class="wy-body-for-nav" role="document">
  26. <div class="wy-grid-for-nav">
  27. <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
  28. <div class="wy-side-nav-search">
  29. <a href=".." class="icon icon-home"> Shaarli Documentation</a>
  30. <div role="search">
  31. <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
  32. <input type="text" name="q" placeholder="Search docs" />
  33. </form>
  34. </div>
  35. </div>
  36. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  37. <ul class="current">
  38. <li class="toctree-l1">
  39. <a class="" href="..">Home</a>
  40. </li>
  41. <li class="toctree-l1">
  42. <span class="caption-text">Setup</span>
  43. <ul class="subnav">
  44. <li class="">
  45. <a class="" href="../Download-and-Installation/">Download and Installation</a>
  46. </li>
  47. <li class="">
  48. <a class="" href="../Upgrade-and-migration/">Upgrade and migration</a>
  49. </li>
  50. <li class="">
  51. <a class="" href="../Server-requirements/">Server requirements</a>
  52. </li>
  53. <li class="">
  54. <a class="" href="../Server-configuration/">Server configuration</a>
  55. </li>
  56. <li class="">
  57. <a class="" href="../Server-security/">Server security</a>
  58. </li>
  59. <li class="">
  60. <a class="" href="../Shaarli-configuration/">Shaarli configuration</a>
  61. </li>
  62. <li class="">
  63. <a class="" href="../Plugins/">Plugins</a>
  64. </li>
  65. </ul>
  66. </li>
  67. <li class="toctree-l1">
  68. <span class="caption-text">Docker</span>
  69. <ul class="subnav">
  70. <li class="">
  71. <a class="" href="../docker/docker-101/">Docker 101</a>
  72. </li>
  73. <li class="">
  74. <a class="" href="../docker/shaarli-images/">Shaarli images</a>
  75. </li>
  76. <li class="">
  77. <a class="" href="../docker/reverse-proxy-configuration/">Reverse proxy configuration</a>
  78. </li>
  79. <li class="">
  80. <a class="" href="../docker/resources/">Docker resources</a>
  81. </li>
  82. </ul>
  83. </li>
  84. <li class="toctree-l1">
  85. <span class="caption-text">Usage</span>
  86. <ul class="subnav">
  87. <li class="">
  88. <a class="" href="../Features/">Features</a>
  89. </li>
  90. <li class="">
  91. <a class="" href="../Bookmarklet/">Bookmarklet</a>
  92. </li>
  93. <li class="">
  94. <a class="" href="../Browsing-and-searching/">Browsing and searching</a>
  95. </li>
  96. <li class="">
  97. <a class="" href="../Firefox-share/">Firefox share</a>
  98. </li>
  99. <li class="">
  100. <a class="" href="../RSS-feeds/">RSS feeds</a>
  101. </li>
  102. <li class="">
  103. <a class="" href="../REST-API/">REST API</a>
  104. </li>
  105. </ul>
  106. </li>
  107. <li class="toctree-l1">
  108. <span class="caption-text">How To</span>
  109. <ul class="subnav">
  110. <li class="">
  111. <a class="" href="../Backup,-restore,-import-and-export/">Backup, restore, import and export</a>
  112. </li>
  113. <li class="">
  114. <a class="" href="../Various-hacks/">Various hacks</a>
  115. </li>
  116. </ul>
  117. </li>
  118. <li class="toctree-l1">
  119. <a class="" href="../Troubleshooting/">Troubleshooting</a>
  120. </li>
  121. <li class="toctree-l1">
  122. <span class="caption-text">Development</span>
  123. <ul class="subnav">
  124. <li class="">
  125. <a class="" href="../Development-guidelines/">Development guidelines</a>
  126. </li>
  127. <li class="">
  128. <a class="" href="../Continuous-integration-tools/">Continuous integration tools</a>
  129. </li>
  130. <li class="">
  131. <a class="" href="../GnuPG-signature/">GnuPG signature</a>
  132. </li>
  133. <li class="">
  134. <a class="" href="../Coding-guidelines/">Coding guidelines</a>
  135. </li>
  136. <li class="">
  137. <a class="" href="../Directory-structure/">Directory structure</a>
  138. </li>
  139. <li class="">
  140. <a class="" href="../3rd-party-libraries/">3rd party libraries</a>
  141. </li>
  142. <li class="">
  143. <a class="" href="../Plugin-System/">Plugin System</a>
  144. </li>
  145. <li class="">
  146. <a class="" href="../Release-Shaarli/">Release Shaarli</a>
  147. </li>
  148. <li class="">
  149. <a class="" href="../Versioning-and-Branches/">Versioning and Branches</a>
  150. </li>
  151. <li class="">
  152. <a class="" href="../Security/">Security</a>
  153. </li>
  154. <li class="">
  155. <a class="" href="../Static-analysis/">Static analysis</a>
  156. </li>
  157. <li class="">
  158. <a class="" href="../Theming/">Theming</a>
  159. </li>
  160. <li class=" current">
  161. <a class="current" href="./">Unit tests</a>
  162. <ul class="subnav">
  163. <li class="toctree-l3"><a href="#setup-your-environment-for-tests">Setup your environment for tests</a></li>
  164. <ul>
  165. <li><a class="toctree-l4" href="#sample-usage">Sample usage</a></li>
  166. <li><a class="toctree-l4" href="#install-shaarli-dev-dependencies">Install Shaarli dev dependencies</a></li>
  167. <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>
  168. <li><a class="toctree-l4" href="#run-unit-tests">Run unit tests</a></li>
  169. <li><a class="toctree-l4" href="#test-results-and-coverage">Test results and coverage</a></li>
  170. </ul>
  171. <li class="toctree-l3"><a href="#executing-specific-tests">Executing specific tests</a></li>
  172. </ul>
  173. </li>
  174. </ul>
  175. </li>
  176. <li class="toctree-l1">
  177. <span class="caption-text">About</span>
  178. <ul class="subnav">
  179. <li class="">
  180. <a class="" href="../FAQ/">FAQ</a>
  181. </li>
  182. <li class="">
  183. <a class="" href="../Community-&-Related-software/">Community & Related software</a>
  184. </li>
  185. </ul>
  186. </li>
  187. </ul>
  188. </div>
  189. &nbsp;
  190. </nav>
  191. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  192. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  193. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  194. <a href="..">Shaarli Documentation</a>
  195. </nav>
  196. <div class="wy-nav-content">
  197. <div class="rst-content">
  198. <div role="navigation" aria-label="breadcrumbs navigation">
  199. <ul class="wy-breadcrumbs">
  200. <li><a href="..">Docs</a> &raquo;</li>
  201. <li>Development &raquo;</li>
  202. <li>Unit tests</li>
  203. <li class="wy-breadcrumbs-aside">
  204. <a href="https://github.com/shaarli/Shaarli/edit/master/docs/Unit-tests.md"
  205. class="icon icon-github"> Edit on GitHub</a>
  206. </li>
  207. </ul>
  208. <hr/>
  209. </div>
  210. <div role="main">
  211. <div class="section">
  212. <h3 id="setup-your-environment-for-tests">Setup your environment for tests</h3>
  213. <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>
  214. <p>Regarding Composer, you can either use:
  215. <em> a system-wide version, e.g. installed through your distro's package manager
  216. </em> a local version, downloadable <a href="https://getcomposer.org/download/">here</a></p>
  217. <h4 id="sample-usage">Sample usage</h4>
  218. <pre><code class="bash"># system-wide version
  219. $ composer install
  220. $ composer update
  221. # local version
  222. $ php composer.phar self-update
  223. $ php composer.phar install
  224. $ php composer.phar update
  225. </code></pre>
  226. <h4 id="install-shaarli-dev-dependencies">Install Shaarli dev dependencies</h4>
  227. <pre><code class="bash">$ cd /path/to/shaarli
  228. $ composer update
  229. </code></pre>
  230. <h4 id="install-and-enable-xdebug-to-generate-phpunit-coverage-reports">Install and enable Xdebug to generate PHPUnit coverage reports</h4>
  231. <p>For Debian-based distros:</p>
  232. <pre><code class="bash">$ aptitude install php5-xdebug
  233. </code></pre>
  234. <p>For ArchLinux:</p>
  235. <pre><code class="bash">$ pacman -S xdebug
  236. </code></pre>
  237. <p>Then add the following line to <code>/etc/php/php.ini</code>:</p>
  238. <pre><code class="ini">zend_extension=xdebug.so
  239. </code></pre>
  240. <h4 id="run-unit-tests">Run unit tests</h4>
  241. <p>Successful test suite:</p>
  242. <pre><code class="bash">$ make test
  243. -------
  244. PHPUNIT
  245. -------
  246. PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
  247. Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
  248. ....................................
  249. Time: 759 ms, Memory: 8.25Mb
  250. OK (36 tests, 65 assertions)
  251. </code></pre>
  252. <p>Test suite with failures and errors:</p>
  253. <pre><code class="bash">$ make test
  254. -------
  255. PHPUNIT
  256. -------
  257. PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
  258. Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
  259. E..FF...............................
  260. Time: 802 ms, Memory: 8.25Mb
  261. There was 1 error:
  262. 1) LinkDBTest::testConstructLoggedIn
  263. Missing argument 2 for LinkDB::__construct(), called in /home/virtualtam/public_html/shaarli/tests/Link\
  264. DBTest.php on line 79 and defined
  265. /home/virtualtam/public_html/shaarli/application/LinkDB.php:58
  266. /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:79
  267. --
  268. There were 2 failures:
  269. 1) LinkDBTest::testCheckDBNew
  270. Failed asserting that two strings are equal.
  271. --- Expected
  272. +++ Actual
  273. @@ @@
  274. -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
  275. +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
  276. /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:121
  277. 2) LinkDBTest::testCheckDBLoad
  278. Failed asserting that two strings are equal.
  279. --- Expected
  280. +++ Actual
  281. @@ @@
  282. -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
  283. +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
  284. /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:133
  285. FAILURES!
  286. Tests: 36, Assertions: 63, Errors: 1, Failures: 2.
  287. </code></pre>
  288. <h4 id="test-results-and-coverage">Test results and coverage</h4>
  289. <p>By default, PHPUnit will run all suitable tests found under the <code>tests</code> directory.</p>
  290. <p>Each test has 3 possible outcomes:
  291. <em> <code>.</code> - success
  292. </em> <code>F</code> - failure: the test was run but its results are invalid
  293. * the code does not behave as expected
  294. * dependencies to external elements: globals, session, cache...
  295. * <code>E</code> - error: something went wrong and the tested code has crashed
  296. * typos in the code, or in the test code
  297. * dependencies to missing external elements</p>
  298. <p>If Xdebug has been installed and activated, two coverage reports will be generated:
  299. <em> a summary in the console
  300. </em> a detailed HTML report with metrics for tested code
  301. * to open it in a web browser: <code>firefox coverage/index.html &amp;</code></p>
  302. <h3 id="executing-specific-tests">Executing specific tests</h3>
  303. <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>
  304. <pre><code class="php">/**
  305. * Netscape bookmark import
  306. * @group WIP
  307. */
  308. class BookmarkImportTest extends PHPUnit_Framework_TestCase
  309. {
  310. [...]
  311. }
  312. </code></pre>
  313. <p>To run all tests annotated with <code>@group WIP</code>:</p>
  314. <pre><code class="bash">$ vendor/bin/phpunit --group WIP tests/
  315. </code></pre>
  316. </div>
  317. </div>
  318. <footer>
  319. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  320. <a href="../FAQ/" class="btn btn-neutral float-right" title="FAQ">Next <span class="icon icon-circle-arrow-right"></span></a>
  321. <a href="../Theming/" class="btn btn-neutral" title="Theming"><span class="icon icon-circle-arrow-left"></span> Previous</a>
  322. </div>
  323. <hr/>
  324. <div role="contentinfo">
  325. <!-- Copyright etc -->
  326. </div>
  327. 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>.
  328. </footer>
  329. </div>
  330. </div>
  331. </section>
  332. </div>
  333. <div class="rst-versions" role="note" style="cursor: pointer">
  334. <span class="rst-current-version" data-toggle="rst-current-version">
  335. <a href="https://github.com/shaarli/Shaarli" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
  336. <span><a href="../Theming/" style="color: #fcfcfc;">&laquo; Previous</a></span>
  337. <span style="margin-left: 15px"><a href="../FAQ/" style="color: #fcfcfc">Next &raquo;</a></span>
  338. </span>
  339. </div>
  340. <script src="../js/theme.js"></script>
  341. </body>
  342. </html>