RSS Facebook Google+ Twitter

Joomla-Bugs

Neuigkeiten: Aktuelle Joomla!-Version: 3.9.0
Willkommen Gast. Bitte einloggen oder registrieren.

Autor Thema: PHPUnit  (Gelesen 2712 mal)

PHPUnit
« am: 04.06.2015, 09:58:07 »
Hallo,
ich hoffe ich bin hier richtig.

Ich habe mir gestern anhand dieser Anleitung:
https://docs.joomla.org/Running_Automated_Tests_for_the_Joomla_CMS

PHPUnit und die aktuelle joomla-cms von Github installiert/kopiert.

Und schon bei der ersten Ausführung entstehen Fragen, die vielleicht erfahrene Unit-Tester schnell beantworten können.

Ich habe als erstes einfach einmal nur phpunit eingegeben und mir wurden  14 Fehler ausgegeben:

PHPUnit 4.6.9 by Sebastian Bergmann and contributors.

Configuration read from F:\xampp\htdocs\joomla-cms\phpunit.xml.dist

.....S......................................................   60 / 5705 (  1%)
..........................................................FF  120 / 5705 (  2%)
F...FFFF............................................FF......  180 / 5705 (  3%)
........................................................S...  240 / 5705 (  4%)
............................................................  300 / 5705 (  5%)
............................................................  360 / 5705 (  6%)
............................................................  420 / 5705 (  7%)
............................................................  480 / 5705 (  8%)
........................................F...........F...F...  540 / 5705 (  9%)
...........................................................S  600 / 5705 ( 10%)
.........................................S..................  660 / 5705 ( 11%)
...SSS......................................................  720 / 5705 ( 12%)
............................................................  780 / 5705 ( 13%)
............................................................  840 / 5705 ( 14%)
............................................................  900 / 5705 ( 15%)
......................................SS.S..................  960 / 5705 ( 16%)
..............SSSS..S...I................SSSSSSSSSSSS....... 1020 / 5705 ( 17%)
............................................................ 1080 / 5705 ( 18%)
............................................................ 1140 / 5705 ( 19%)
............................................................ 1200 / 5705 ( 21%)
............................................................ 1260 / 5705 ( 22%)
............................................................ 1320 / 5705 ( 23%)
......................................................SS.... 1380 / 5705 ( 24%)
............................................................ 1440 / 5705 ( 25%)
............................................................ 1500 / 5705 ( 26%)
............................................................ 1560 / 5705 ( 27%)
..................SSSSSSSSS................................. 1620 / 5705 ( 28%)
............................................................ 1680 / 5705 ( 29%)
............................................................ 1740 / 5705 ( 30%)
.................................................S.......... 1800 / 5705 ( 31%)
............................................................ 1860 / 5705 ( 32%)
..................................................SS........ 1920 / 5705 ( 33%)
............................................................ 1980 / 5705 ( 34%)
............................................................ 2040 / 5705 ( 35%)
............................................................ 2100 / 5705 ( 36%)
............................................................ 2160 / 5705 ( 37%)
............................................................ 2220 / 5705 ( 38%)
............................................................ 2280 / 5705 ( 39%)
............................................................ 2340 / 5705 ( 41%)
............................................................ 2400 / 5705 ( 42%)
............................................................ 2460 / 5705 ( 43%)
............................................................ 2520 / 5705 ( 44%)
............................................................ 2580 / 5705 ( 45%)
............................................................ 2640 / 5705 ( 46%)
............................................................ 2700 / 5705 ( 47%)
..................SSSS...................................... 2760 / 5705 ( 48%)
............................F............................... 2820 / 5705 ( 49%)
............................................................ 2880 / 5705 ( 50%)
..............................F............................. 2940 / 5705 ( 51%)
............................................................ 3000 / 5705 ( 52%)
............................................................ 3060 / 5705 ( 53%)
............................................................ 3120 / 5705 ( 54%)
............................................................ 3180 / 5705 ( 55%)
............................................................ 3240 / 5705 ( 56%)
............................................................ 3300 / 5705 ( 57%)
............................................................ 3360 / 5705 ( 58%)
............................................................ 3420 / 5705 ( 59%)
............................................................ 3480 / 5705 ( 60%)
....................................SSSSSSSSSSSSSSSSSS...... 3540 / 5705 ( 62%)
............................................................ 3600 / 5705 ( 63%)
............................................................ 3660 / 5705 ( 64%)
............................................................ 3720 / 5705 ( 65%)
...................................S...S.................... 3780 / 5705 ( 66%)
.....................................................S...... 3840 / 5705 ( 67%)
............................................................ 3900 / 5705 ( 68%)
............................................................ 3960 / 5705 ( 69%)
............................................................ 4020 / 5705 ( 70%)
............................................................ 4080 / 5705 ( 71%)
............................................................ 4140 / 5705 ( 72%)
.............................S.............................. 4200 / 5705 ( 73%)
............................................................ 4260 / 5705 ( 74%)
............................................................ 4320 / 5705 ( 75%)
............................................................ 4380 / 5705 ( 76%)
..............................SSSSSS.....SSSSSSSS........... 4440 / 5705 ( 77%)
............................................................ 4500 / 5705 ( 78%)
............................................................ 4560 / 5705 ( 79%)
............................................................ 4620 / 5705 ( 80%)
............................................................ 4680 / 5705 ( 82%)
............................................................ 4740 / 5705 ( 83%)
............................................................ 4800 / 5705 ( 84%)
.........S..S............................................... 4860 / 5705 ( 85%)
............................................................ 4920 / 5705 ( 86%)
............................................................ 4980 / 5705 ( 87%)
...SSSS..................................................... 5040 / 5705 ( 88%)
....S.....S................................................. 5100 / 5705 ( 89%)
S........................................................... 5160 / 5705 ( 90%)
............................................................ 5220 / 5705 ( 91%)
................SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS........... 5280 / 5705 ( 92%)
.........................SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 5340 / 5705 ( 93%)
SSSSSS....................................SSSSSSSSSSSSSSSSSS 5400 / 5705 ( 94%)
SSSSSSSSSSSSSSSSSSSSSSS..................................... 5460 / 5705 ( 95%)
.SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 5520 / 5705 ( 96%)
SSSSSSSSSSS................................................S 5580 / 5705 ( 97%)
SSSSS..................................................SSSSS 5640 / 5705 ( 98%)
SSSSSSSSSSSSSSSSSSSS........................................ 5700 / 5705 ( 99%)
.....

Time: 5.8 minutes, Memory: 162.50Mb

There were 14 failures:

1) JHtmlBootstrapTest::testAlert
Verify that the alert script is initialised
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '(function($){
  $('.alert').alert();
  })(jQuery);'

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php:96

2) JHtmlBootstrapTest::testButton
Verify that the button script is initialised
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '(function($){
  $('.button').button();
  })(jQuery);'

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php:124

3) JHtmlBootstrapTest::testDropdown
Verify that the dropdown script is initialised
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '(function($){
  $('.dropdown-toggle').dropdown();
  })(jQuery);'

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php:152

4) JHtmlBootstrapTest::testEndTabSet
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '
 </div>'

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php:225

5) JHtmlBootstrapTest::testEndTab
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '
 </div>'

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php:240

6) JHtmlBootstrapTest::testEndPane
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '
 </div>'

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php:255

7) JHtmlBootstrapTest::testEndPanel
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '
 </div>'

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php:270

8) JHtmlSelectTest::testRadiolist with data set #0 ('<div class="controls">\n <labe.../div>\n', array(array('1', 'Yes', 'yesId'), array('0', 'No'), array('-1', 'Maybe')), 'myRadioListName')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '<div class="controls">
  <label for="yesId" id="yesId-lbl" class="radio">
 
  <input type="radio" name="myRadioListName" id="yesId" value="1"  >Yes
  </label>
  <label for="myRadioListName0" id="myRadioListName0-lbl" class="radio">
 
  <input type="radio" name="myRadioListName" id="myRadioListName0" value="0"  >No
  </label>
  <label for="myRadioListName-1" id="myRadioListName-1-lbl" class="radio">
 
  <input type="radio" name="myRadioListName" id="myRadioListName-1" value="-1"  >Maybe
  </label>
 </div>
 '

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlSelectTest.php:489

9) JHtmlSelectTest::testRadiolist with data set #1 ('<div class="controls">\n <labe.../div>\n', array(array('foo', 'FOO', 'fooId'), array('bar', 'BAR')), 'myFooBarListName', array('i am radio', 'jsfunc();'), 'key', 'val')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '<div class="controls">
  <label for="fooId" id="fooId-lbl" class="radio">
 
  <input type="radio" name="myFooBarListName" id="fooId" value="foo" class="i am radio" onchange="jsfunc();" >FOO
  </label>
  <label for="myFooBarListNamebar" id="myFooBarListNamebar-lbl" class="radio">
 
  <input type="radio" name="myFooBarListName" id="myFooBarListNamebar" value="bar" class="i am radio" onchange="jsfunc();" >BAR
  </label>
 </div>
 '

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlSelectTest.php:489

10) JToolbarButtonTest::testRender
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '<div class="btn-wrapper"  id="toolbar-test">
  <button onclick="if (document.adminForm.boxchecked.value==0){alert('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');}else{ Joomla.submitbutton('')}" class="btn btn-small">
  <span class="icon-test"></span>
  </button>
 </div>
 '

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\toolbar\JToolbarButtonTest.php:133

11) JToolbarButtonConfirmTest::testFetchButton
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '<button onclick="if (document.adminForm.boxchecked.value==0){alert('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');}else{if (confirm('Confirm action?')){Joomla.submitbutton('article.save');}}" class="btn btn-small">
  <span class="icon-confirm-test"></span>
  Confirm?</button>
 '

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\toolbar\button\JToolbarButtonConfirmTest.php:99

12) JToolbarButtonHelpTest::testFetchButton
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '<button onclick="Joomla.popupWindow('help/en-GB/JHELP_CONTENT_ARTICLE_MANAGER.html', 'JHELP', 700, 500, 1)" rel="help" class="btn btn-small">
  <span class="icon-question-sign"></span>
  JTOOLBAR_HELP</button>
 '

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\toolbar\button\JToolbarButtonHelpTest.php:102

13) JGithubGistsTest::testCreateGistFromFile
Expectation failed for method name is equal to <string:post> when invoked 1 time(s)
Parameter 1 for invocation JHttp::post('/gists', '{"files":{"gittest":{"content...gist"}', null, null) does not match expected value.
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'{"files":{"gittest":{"content":"GistContent\n"}},"public":true,"description":"This is a gist"}'
+'{"files":{"gittest":{"content":"GistContent\r\n"}},"public":true,"description":"This is a gist"}'

F:\xampp\htdocs\joomla-cms\libraries\joomla\github\package\gists.php:56
F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\joomla\github\JGithubGistsTest.php:148

14) JGithubPackageGistsTest::testCreateGistFromFile
Expectation failed for method name is equal to <string:post> when invoked 1 time(s)
Parameter 1 for invocation JHttp::post('/gists', '{"files":{"gittest":{"content...gist"}', null, null) does not match expected value.
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'{"files":{"gittest":{"content":"GistContent\n"}},"public":true,"description":"This is a gist"}'
+'{"files":{"gittest":{"content":"GistContent\r\n"}},"public":true,"description":"This is a gist"}'

F:\xampp\htdocs\joomla-cms\libraries\joomla\github\package\gists.php:56
F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\joomla\github\JGithubPackageGistsTest.php:145

FAILURES!
Tests: 5705, Assertions: 10136, Failures: 14, Skipped: 306, Incomplete: 1.





Den ersten Fehler wollte ich mir dann einmal genauer ansehen:

1) JHtmlBootstrapTest::testAlert
Verify that the alert script is initialised
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '(function($){
  $('.alert').alert();
  })(jQuery);'

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php:96



Der Fehler tritt hier in der Zeile 96 auf:

/**
* Tests the alert method.
*
* @return  void
*
* @since   3.1
*/
public function testAlert()
{
// Initialise the alert script
JHtmlBootstrap::alert();

// Get the document instance
$document = JFactory::getDocument();

$this->assertArrayHasKey(
'/media/jui/js/bootstrap.min.js',
$document->_scripts,
'Verify that the alert method initialises Bootstrap as well'
);

$this->assertEquals(
$document->_script['text/javascript'],
"(function($){\n\t\t\t\t$('.alert').alert();\n\t\t\t\t})(jQuery);",
'Verify that the alert script is initialised'
);
}





Ich wollte mir dann aus Interesse einfach einmal die Texte ausgeben lassen. Dabei habe ich aber gesehen, dass sie doch gleich sind. Ich habe in meinem System einfach die Testfunktion in Zeile 95 der Datei  ..\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php abgeändert:


/**
* Tests the alert method.
*
* @return  void
*
* @since   3.1
*/
public function testAlert()
{
// Initialise the alert script
JHtmlBootstrap::alert();

// Get the document instance
$document = JFactory::getDocument();

$this->assertArrayHasKey(
'/media/jui/js/bootstrap.min.js',
$document->_scripts,
'Verify that the alert method initialises Bootstrap as well'
);

$this->assertEquals(
$document->_script['text/javascript'],
"(function($){\n\t\t\t\t$('.alert').alert();\n\t\t\t\t})(jQuery);",
$document->_script['text/javascript']
);
}

Ausgegeben wurde mir in der Testdatei dann :

….

1) JHtmlBootstrapTest::testAlert
(function($){
$('.alert').alert();
})(jQuery);
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 '(function($){
  $('.alert').alert();
  })(jQuery);'

F:\xampp\htdocs\joomla-cms\tests\unit\suites\libraries\cms\html\JHtmlBootstrapTest.php:96
….


Das ist doch gleich, oder? Warum wird hier ein Fehler gemeldet?   


Ich habe noch nicht sehr viele Erfahrungen mit PHPUnit gesammelt. Habe ich hier einen Denkfehler?


Viele Grüße
Astrid


Offline zero24

  • Global Moderator
    • Joomla! als Hobby
Re: PHPUnit
« Antwort #1 am: 04.06.2015, 21:27:38 »
Hallo astrid,


ich habe leider keine direkten Erfahrungen mit phpunit.


Ich weiß aber zum Beispiel das phpunit bzw. die Unittests bei jeder Pull Request auf github ausgeführt werden.


In dem Script was dafür verantwortlich ist (bzw abgearbeitet wird) findet sich der Befehl


phpunit --configuration travisci-phpunit.xml


siehe: https://github.com/joomla/joomla-cms/blob/staging/.travis.yml


Kannst du mal probieren wenn du diese datei: https://github.com/joomla/joomla-cms/blob/staging/phpunit.xml.dist in phpunit.xml umbenennst und dann

phpunit --configuration phpunit.xml


probierst?


Auf welcher PHP Version etc bist du unterwegs? PHP 7 hat wird noch nicht voll unterstützt.


Hier ist die Travis Version der Unittests auf dem aktuell letzten commit in die staging branche: https://travis-ci.org/joomla/joomla-cms/jobs/65445308 und da funktioniert alles. (den unteren Teil kann man ignorieren das ist der Codestyle Part welcher von Travis noch zusätzlich durchgeführt wird)
Nichts auf der Welt ist so gerecht verteilt wie der Verstand. Denn jedermann ist überzeugt, daß er genug davon habe. (Rene Descartes, fr. Mathematiker u. Philosoph, 1596 - 1650)

Re: PHPUnit
« Antwort #2 am: 05.06.2015, 08:55:31 »
Hallo zero24,
vielen Dank für deine schnelle Antwort und die Tipps.

Ich habe die https://github.com/joomla/joomla-cms/blob/staging/phpunit.xml.dist mit meiner Konfiguration verglichen und die beiden sind gleich.

Diese Tests habe ich lokal auf XAMPP mit den Versionen:  PHP 5.5.19 und MySQL 5.6.21 installiert.

Ich habe UnitTests vor langer Zeit einmal in Java gelernt aber bisher nie praktisch eingesetzt. Ich werde mich hier nun erst einmal weitere einlesen.

Viele Grüße
Astrid

 

BloQcs design by Bloc
| SMF © 2011, Simple Machines
Joomla-Bugs.de is not affiliated with or endorsed by The Joomla! Project™. Use of the Joomla!® name, symbol, logo and related trademarks is permitted under a limited license granted by Open Source Matters, Inc.