Author
|
Message
|
Marouane Mighri
|
Thursday 30 April 2009 8:47:13 am
try to launch unitests on my extension. I have some troubles when I test my functions. For example the following function has a dependency with eZDB class:
//function to test
class MyClass
{
function fetchByCustomer()
{
$db = eZDB::instance();
$query= 'SELECT * FROM table';
$rows = $db->arrayQuery($query);
return $rows;
}
}
//test function
class MyTest extends PHPUnit_TestCase
{
public function testFetchByCustomer()
{
$this->assertTrue(MyClass::fetchByCustomer());
}
}
To solve my problem, i have included my tests files in “plain_site” of EZ, to use EZ Autoload. It's work very well with eZMail Class. But I encounter troubles with eZDB Class. It returns me a white page. Would somebody have tips or quite simply an explanation to use the unitests suggested by EZ in his SVN version ? Thank you Environment:
EZ Publish version 4.1
PHPUnit 3.3.16
MySQL: 5.0.77 PHP Version => 5.2.9-1
Maecia
|
Ole Morten Halvorsen
|
Thursday 30 April 2009 9:04:08 am
Hi,
There's some documentation on how to write unit tests for eZ publish over at ezpedia.org: http://ezpedia.org/ez/ez_publish_test_system
Cheers, Ole
Senior Software Engineer - Vision with Technology
http://www.visionwt.com
http://www.omh.cc
http://www.twitter.com/omh
eZ Certified Developer
http://ez.no/certification/verify/358441
http://ez.no/certification/verify/272578
|
Marouane Mighri
|
Thursday 30 April 2009 9:41:29 am
Hi , Thanks for your answer. I already tested with and I have the following error message:
<i>
root/ez_marouane# php tests/runtests.php -D mysql:://user:password@host/DB_devmarouane PHPUnit 3.3.16 by Sebastian Bergmann. Fatal error: Call to a member function insertSchema() on a non-object in ez_marouane/tests/toolkit/ezptestdatabasehelper.php on line 120 </i>
Maecia
|
Russell Michell
|
Thursday 30 April 2009 3:10:37 pm
Hi Marouane: I'm sorry to "Hijack" your thread but I wanted to ask how you got started with unit-testing in ez? I mean, documentation for it is hard to come by - the info I found at ezpedia.org seems to assume a level of understanding not just of Unit Testing but Unit Testing with PHP - something I personally don't have (yet). Are you (or anyone reading this) well-versed enough to write a brief Article for ez.no? "Introduction to Unit Testing with eZ" ? :-) I have obtained PHPUnit and checked-out the ez 'tests' directory from SVN but I keep getting errors from PHPUnit when running runtests.php.
#> php tests/runtests.php -D mysql:://ezpublish-D:ezD@localhost/ez_DEV
InvalidArgumentException: in /usr/local/php/lib/php/PHPUnit/Framework/TestSuite.php on line 305
Call Stack:
0.0005 117144 1. {main}() /home/russellm/svn/web/ezpublish/trunk/duty/tests/runtests.php:0
0.3099 10388056 2. ezpTestRunner::main() /home/russellm/svn/web/ezpublish/trunk/duty/tests/runtests.php:54
0.3099 10388056 3. ezpTestRunner->runFromArguments() /home/russellm/svn/web/ezpublish/trunk/duty/tests/toolkit/ezptestrunner.php:23
0.3212 11011880 4. ezpTestRunner->prepareTests() /home/russellm/svn/web/ezpublish/trunk/duty/tests/toolkit/ezptestrunner.php:34
0.3213 11011920 5. ezpTestRunner::suite() /home/russellm/svn/web/ezpublish/trunk/duty/tests/toolkit/ezptestrunner.php:251
0.3213 11012040 6. eZTestSuite->__construct() /home/russellm/svn/web/ezpublish/trunk/duty/tests/toolkit/ezptestrunner.php:292
0.3213 11012232 7. PHPUnit_Framework_TestSuite->addTestSuite() /home/russellm/svn/web/ezpublish/trunk/duty/tests/suite.php:17
Might this be down to me using an older version of ez? (I have 4.0.1rc2, PHP5.2.9, MySQL 5.0.22 on Linux FC9) I would find a simple, step-by-step guide very helpful, as I would think others would too.
Thanks for reading, Russ
Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom
Believe nothing, consider everything.
|
Ole Morten Halvorsen
|
Friday 01 May 2009 2:16:21 am
@Marouane, @Russ: There's only supposed to be one ';' after mysql. Try re-running like this:
$ php tests/runtests.php -D mysql://user:password@host/db
Cheers, Ole
Senior Software Engineer - Vision with Technology
http://www.visionwt.com
http://www.omh.cc
http://www.twitter.com/omh
eZ Certified Developer
http://ez.no/certification/verify/358441
http://ez.no/certification/verify/272578
|
Russell Michell
|
Sunday 03 May 2009 4:18:56 pm
@Ole - thanks for your response. I still get the same error:
#> php tests/runtests.php -D mysql://my_user_name:my_user_password@localhost/my_DB_name
InvalidArgumentException: in /usr/local/php/lib/php/PHPUnit/Framework/TestSuite.php on line 305
I'm using PHPUnit 3.3 on Linux FC9 with the ez 'tests' directory from SVN trunk rev23517 but with ez version 4.0.1rc2. Am I required to upgrade my version of ez to match the tests downloaded via SVN in trunk? Are there no legacy 'tests' directories available for older versions of ez?
Thanks a lot, Russell
Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom
Believe nothing, consider everything.
|
Geoff Bentley
|
Monday 04 May 2009 2:22:25 am
Hi Russ, 4.0.1rc2 release is SVN rev22267, so you can checkout the tests at that rev for a matching version (although you'll lose the subsequent bug fixes). Cheers, Geoff
|
Paul Forsyth
|
Monday 04 May 2009 3:55:37 am
Hi Russ, Are you sure the test files are autoloaded correctly? The present trunk version includes an updated ezpgenerateautoloads.php file which accounts for the presence of the test directory. Also, i noticed that the ' mysql_create_db' command within lib/ezmydb/classes/ezmysqldb.php file has been replaced in 4.1 with a direct "CREATE DATABASE" call. Paul
eZ Systems
|
Marouane Mighri
|
Monday 04 May 2009 6:24:49 am
@Ole - thanks for your response.
@Russ At the beginning i tried to extend the unit tests of EZ. The trouble may be related to the files "share/db_data.dba" and "share/db_schema.dba" because i added my own tables. The tests use these files to fill the database. When I launch “runtests.php” I obtain this error message:
root@marouane# php tests/runtests.php -D mysql://login:password@localhost/wa_devmarouane
PHPUnit 3.3.16 by Sebastian Bergmann.
.....F....F........
Fatal error: Call to a member function attribute() on a non-object in .../marouane/tests/toolkit/extras/kernelwrapper/classes/node.php on line 34
the tests starts correctly but it stops after the creation of a node of id (62) (Folder)
After i tried to start directly from PHPUnits by writing my own files but it was necessary to load EZ classes like eZDB and eZMail… to be able to test my functions. Then i launched the tests in a “plain_site” except that each time i use the eZDB class i obtain a white page !
Maecia
|
Marouane Mighri
|
Monday 04 May 2009 10:39:19 am
by ignoring some lines in the file “tests/tests/kernel/suite.php”
$this->addTestSuite( 'eZContentObjectRegression' );
$this->addTestSuite( 'eZURLAliasMlTest' );
//$this->addTestSuite( 'eZURLAliasMlRegression' );
//$this->addTestSuite( 'eZURLTypeRegression' );
//$this->addTestSuite( 'eZXMLTextRegression' );
//$this->addTestSuite( 'eZApproveTypeRegression' );
//$this->addTestSuite( 'eZMultiPriceTypeRegression' );
//$this->addTestSuite( 'eZContentObjectStateTest' );
$this->addTestSuite( 'eZContentObjectStateGroupTest' );
I could launch the tests partially, but I have always the same error message:
root@marouane# php tests/runtests.php -D mysql://login:password@host/db
PHPUnit 3.3.16 by Sebastian Bergmann.
.....F....F................................................. 60 / 400
............................................................ 120 / 400
............................................................ 180 / 400
............................................................ 240 / 400
............................................................ 300 / 400
............................................................ 360 / 400
.....................SSSSS..............
Time: 21 seconds
There were 2 failures:
1) testGetChildren(eZURLAliasMlTest)
Failed asserting that <integer:0> matches expected value <integer:2>.
2) testChoosePrioritizedRow(eZURLAliasMlTest)
Failed asserting that <string:2> matches expected value <integer:4>.
FAILURES!
Tests: 400, Assertions: 453, Failures: 2, Skipped: 5.
bychanging value of “language” in function “testGetChildren” in file "tests/tests/kernel/classes/urlaliasml_test.php", the unitest works!
public function testGetChildren()
{
$action = "eznode:" . mt_rand();
-- $parent = eZURLAliasML::create( __FUNCTION__ . "Parent", $action, 1, 2 );
++ $parent = eZURLAliasML::create( __FUNCTION__ . "Parent", $action, 1, 1 );
$parent->store();
-- $child1 = eZURLAliasML::create( __FUNCTION__ . "Child1", $action, $parent->ID, 2 );
++ $child1 = eZURLAliasML::create( __FUNCTION__ . "Child1", $action, $parent->ID, 1 );
$child1->store();
-- $child2 = eZURLAliasML::create( __FUNCTION__ . "Child2", $action, $parent->ID, 2 );
++ $child2 = eZURLAliasML::create( __FUNCTION__ . "Child2", $action, $parent->ID, 1 );
$child2->store();
-- $child3 = eZURLAliasML::create( __FUNCTION__ . "Child3", $action, $parent->ID, 4 );
++ $child3 = eZURLAliasML::create( __FUNCTION__ . "Child3", $action, $parent->ID, 3 );
$child3->store();
$children = $parent->getChildren();
// Number of children should be 2 (child3 has different language and
// should not be included in getChildren()).
self::assertEquals( 2, count( $children ) );
self::assertEquals( (int) $child1->attribute( 'id' ), (int) $children[0]->attribute( 'id' ) );
self::assertEquals( (int) $child2->attribute( 'id' ), (int) $children[1]->attribute( 'id' ) );
}
Somebody would have some explanations for this ? Thanks
Maecia
|
Ole Morten Halvorsen
|
Monday 04 May 2009 2:03:26 pm
@Russ: As the documentation indicates (http://ezpedia.org/ez/ez_publish_test_system) you'll need at least a checkout of eZ Publish equal to or newer than rev 22408. As Paul mentioned, there's been some small but important changes made to eZ Publish itself to facilitate the test system, such as modifications to the autoload system.
Cheers, Ole
Senior Software Engineer - Vision with Technology
http://www.visionwt.com
http://www.omh.cc
http://www.twitter.com/omh
eZ Certified Developer
http://ez.no/certification/verify/358441
http://ez.no/certification/verify/272578
|
Russell Michell
|
Monday 11 May 2009 9:05:16 pm
@Geoff Thanks - trunk rev 22267 doesn't seem to have a 'tests' directory, at least not in the top-level where it is in HEAD anyway. Browsing the SVN releases dir for 4.0.1rc2 doesn't have one either. It appears 'tests' wasn't added until 4.1.0. @Ole - it seems as I suspected that it's best to do this for a later stable release and use the same 'tests' dir that comes with it. However - I just downloaded and attempted an install todo just this and couldn't get past the packages install/upload screen...(The "Remote repository URL is non existent: http://packages.ez.no/ezpublish/4.1/4.1.2/) Downloading the package (ezwebin) separately and trying to upload it, fails also. The screen refreshes but nothing else happens... @All: Whether or not I get UT going with some version of ez - all I was asking really was whether someone better versed in UT than I, might write a brief article on Unit Testing for Ez. As it goes, I doubt very much whether anyone uses ez "out of the box" without *some* modifications to it meaning that testing new code to work with ez core stuff becoming all the more important - especially for those building extensions for ez.
Many thanks all, Russell
Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom
Believe nothing, consider everything.
|
Paul Forsyth
|
Tuesday 12 May 2009 1:07:23 am
Hi Russ, AFAIK the unit test code became 'stable'ish in 4.1. The package links refer to an unreleased version (4.1.2), so either you could override the default location from settings/package.ini, or you could download the released 4.1.1, and add the 'tests' directory from the trunk. Another way of getting going quickly is to import the base sql files from:
kernel/sql/mysql/kernel_schema.sql kernel/sql/mysql/cleandata.sql into an empty database. This provides a real base installation of eZ, and is used by the testrunner for making sure a database is either loaded per test or per suite. This should get you going. Let me know if this works for you. Paul
eZ Systems
|
Russell Michell
|
Sunday 27 September 2009 2:28:51 pm
Thank you everyone for your pointers and instruction: I am now up and running with unit tests. I have upgraded to 4.1.3 and the instructions on ezpedia seem to have been updated very recently - both of which very possibly have helped too.
Many thanks all. Russell
Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom
Believe nothing, consider everything.
|
Russell Michell
|
Monday 05 October 2009 4:00:46 pm
Hi again everyone, I've been trying on and off to successfully generate stub tests for an extension of mine, by following the instructions on ezpedia. But I kept getting the following error:
Warning: Invalid argument supplied for foreach() in /path/to/ezpublish/sites/tests/toolkit/extras/scripts/create-test-from-class.php on line 78
So I traced the error back to an <b>extremely odd</b> assumption made in getClassName() in <b>ezptestrunner.php</b>:
static public function getClassName( $file )
{
...
$total = $size > 30 ? 30 : $size;
// check only the last 30 classes.
for ( $i = $size - 1; $i > $size - $total - 1; $i-- )
{
$rf = new ReflectionClass( $classes[$i] );
$len = strlen( $file );
if ( strcmp( $file, substr( $rf->getFileName(), -$len ) ) == 0 )
{
return $classes[$i];
}
}
...
What I think getClassName() does is to locate the class defined in the value of -s passed to <b>create-test-from-class.php</b> from the array returned by PHPs get_declared_classes(). However, while iterating through the array of classnames thus returned, getClassName() is only returning the last 30 classes. If I make ezptestrunner.php spit out <b>all</b> the classes returned by PHPs get_declared_classes(), then the one I'm after is in the first 100 or so of the total array. It's never going to be passed to getClass() in create-test-from-class.php becuase it's index is not in the last 30. Why does ezptestrunner.php do it this way? I have hacked my copy to return all it finds, I no longer receive the above error and my stub tests are generated (all 44 of them!) I guess there must be a reason for this, performance perhaps? Keen to hear your thoughts.
Cheers, Russell
Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom
Believe nothing, consider everything.
|
Andreas Adelsberger
|
Wednesday 03 March 2010 2:39:53 am
Hi I have the same problem as Russel. When I print out get_declared_classes I have about 250. So why is it limited to 30? Cheers Andi,
---------------------------------------
Styleflasher New Media OG
Websites. Games/Multimedia.
|