Page 1 of 1

When I run my unit tests I get "errors on line 0"?

Posted: Thu Dec 10, 2009 4:15 pm
by josh
Basically I get errors like

PHP Fatal error: call to a member function blah() on a non-object in whateverTest.php on line 0

Whats up with this?

Re: When I run my unit tests I get "errors on line 0"?

Posted: Thu Dec 10, 2009 4:49 pm
by pickle
The only time I've seen errors like this is when there was a PHP compilation error.

Re: When I run my unit tests I get "errors on line 0"?

Posted: Thu Dec 10, 2009 5:22 pm
by requinix
Either post code (like what you were testing) or be more specific in the error message. Both would be nice.

Re: When I run my unit tests I get "errors on line 0"?

Posted: Thu Dec 10, 2009 5:28 pm
by AbraCadaver
josh wrote:Basically I get errors like

PHP Fatal error: call to a member function blah() on a non-object in whateverTest.php on line 0

Whats up with this?
What exactly is the code on line 0?

Re: When I run my unit tests I get "errors on line 0"?

Posted: Thu Dec 10, 2009 5:38 pm
by josh
Something along the lines of $foo->blah(). I closed the command line window and fixed the error already and forget. It happens all the time though (what would constitute a compile error?)

Re: When I run my unit tests I get "errors on line 0"?

Posted: Thu Dec 10, 2009 5:41 pm
by AbraCadaver
josh wrote:Something along the lines of $foo->blah(). I closed the command line window and fixed the error already and forget. It happens all the time though (what would constitute a compile error?)
Holy crap, you have a line 0? I was joking... :oops:

Re: When I run my unit tests I get "errors on line 0"?

Posted: Thu Dec 10, 2009 9:04 pm
by josh
AH I didn't know you meant literally, now that I get it its very funny :-D,
I thought you were asking what code was on the line it *thought* was line 0. Yeah it must be the global variable on line -1 causing it :drunk:

Re: When I run my unit tests I get "errors on line 0"?

Posted: Fri Dec 11, 2009 3:13 am
by josh
Ok here's some more, from a different server :banghead:

Code: Select all

 
# php dbrefactor.php
PHP Warning:  PHP Startup: PDO: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=0
PHP    compiled with module API=20060613, debug=0, thread-safety=0
These options need to match
 in Unknown on line 0
PHP Warning:  PHP Startup: pdo_mysql: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=0
PHP    compiled with module API=20060613, debug=0, thread-safety=0
These options need to match
 in Unknown on line 0
PHP Fatal error:  Class 'Shuffler_DB_Refactor' not found in /var/www/vafconform/application/Code/Db/Refactor.php on line 3
 
I can't figure out why that last class isn't being loaded either so it must be related.


I ask phpinfo about PDO and here is what I get:

Code: Select all

 
# php -i | grep pdo
PHP Warning:  PHP Startup: PDO: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=0
PHP    compiled with module API=20060613, debug=0, thread-safety=0
These options need to match
 in Unknown on line 0
PHP Warning:  PHP Startup: pdo_mysql: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=0
PHP    compiled with module API=20060613, debug=0, thread-safety=0
These options need to match
 in Unknown on line 0
Configure Command =>  './configure'  '--with-mysql' '--with-mysqli' '--enable-mysqli' '--enable-pdo' '--with-pdo-mysql' '--without-pdo-sqlite' '--without-sqlite' '--with-apxs2=/usr/sbin/apxs' '--with-gd' '--with-mcrypt' '--with-curl' '--with-jpeg-dir=/usr/lib/' '--enable-mbstring'
pdo_mysql
 
And when I run it in the browser I get

Code: Select all

 
 
PDO
PDO support enabled
PDO drivers     mysql

Re: When I run my unit tests I get "errors on line 0"?

Posted: Fri Dec 11, 2009 3:40 pm
by josh
Looks like I had some pecl modules in php.ini leftover, and when I compiled and overwrote yum's PHP I forgot to remove these from php.ini

Re: When I run my unit tests I get "errors on line 0"?

Posted: Sat Dec 12, 2009 8:14 pm
by josh
Ok the problem started happening again:

Code: Select all

 
function testSyncVoteCount()
    {
        $change = new Change;
        $vote = $this->getVote( true );
        $change->vote( $vote );
        $ballot->setVoteCount( 10000 ); // here is where the error is, $ballot is a non object
        $ballot->synchVoteCount();
        $this->assertSame( 1, $ballot->getVoteCount(), 'After placing V, then setting vote count manually out of bounds, synch method will reset the vote count to 1' );
    }
The error I get Is:

Code: Select all

 
 Vote_BalletTest
 ....PHP Fatal error:  Call to a member function setVoteCount() on a non-object in E:\dev\vafconform\application\Code\Vote\BallotTest.php on line 0
 
Fatal error: Call to a member function setVoteCount() on a non-object in E:\dev\vafconform\application\Code\Vote\BallotTest.php on line 0
 
I feel like I'm programming on the stone ages because I have to find execution errors by hand.

And check this out

..PHP Fatal error: Call to undefined method Vote::getChange() in E:\dev\vafconform\application\Code\Vote\MapperTest.php on line 29
PHP Stack trace:
PHP 1. {main}() C:\wamp\bin\php\php5.3.0\phpunit.php:0
PHP 2. PHPUnit_TextUI_Command::main() C:\wamp\bin\php\php5.3.0\phpunit.php:52
PHP 3. PHPUnit_TextUI_Command->run() C:\wamp\bin\php\php5.3.0\PHPUnit\TextUI\Command.php:147
PHP 4. PHPUnit_TextUI_TestRunner->doRun() C:\wamp\bin\php\php5.3.0\PHPUnit\TextUI\Command.php:214
PHP 5. PHPUnit_Framework_TestSuite->run() C:\wamp\bin\php\php5.3.0\PHPUnit\TextUI\TestRunner.php:350
PHP 6. PHPUnit_Framework_TestSuite->run() C:\wamp\bin\php\php5.3.0\PHPUnit\Framework\TestSuite.php:675
PHP 7. PHPUnit_Framework_TestSuite->runTest() C:\wamp\bin\php\php5.3.0\PHPUnit\Framework\TestSuite.php:732
PHP 8. PHPUnit_Framework_TestCase->run() C:\wamp\bin\php\php5.3.0\PHPUnit\Framework\TestSuite.php:756
PHP 9. PHPUnit_Framework_TestResult->run() C:\wamp\bin\php\php5.3.0\PHPUnit\Framework\TestCase.php:653
PHP 10. PHPUnit_Framework_TestCase->runBare() C:\wamp\bin\php\php5.3.0\PHPUnit\Framework\TestResult.php:687
PHP 11. PHPUnit_Framework_TestCase->runTest() C:\wamp\bin\php\php5.3.0\PHPUnit\Framework\TestCase.php:706
PHP 12. ReflectionMethod->invokeArgs() C:\wamp\bin\php\php5.3.0\PHPUnit\Framework\TestCase.php:822
PHP 13. Vote_MapperTest->testChange() E:\dev\vafconform\application\Code\Vote\MapperTest.php:0

I guess its due to PHPUnit's use of reflection?

Re: When I run my unit tests I get "errors on line 0"?

Posted: Sat Dec 12, 2009 9:52 pm
by John Cartwright

Code: Select all

 
 Vote_BalletTest
 ....PHP Fatal error:  Call to a member function setVoteCount() on a non-object in E:\dev\vafconform\application\Code\Vote\BallotTest.php on line 0
 
Fatal error: Call to a member function setVoteCount() on a non-object in E:\dev\vafconform\application\Code\Vote\BallotTest.php on line 0
 
99% of the time I get an error like this is because the member function did not return an instance in a fluid interface.

Re: When I run my unit tests I get "errors on line 0"?

Posted: Sat Dec 12, 2009 10:03 pm
by Weirdan
John Cartwright wrote:99% of the time I get an error like this is because the member function did not return an instance in a fluid interface.
But not on line 0 I bet.

From my experience mangled backtrace usually originates from using eval(), reflection, call_user_func_*. Also I've seen funny filenames when I piped php code to php interpreter's stdin.

Re: When I run my unit tests I get "errors on line 0"?

Posted: Sat Dec 12, 2009 11:40 pm
by josh
I narrowed it down. If I put

Code: Select all

$foo = null;
$foo->bar();
It calls it line 204 (actual)

If I put

Code: Select all

$foo->bar();
(undeclared variable) I get line 0. PHP Bug? Its happening as part of the core FATAL errors, not just exceptions. I am able to replicate it on several different machines running 5.3.0, but not 5.2.x, I guess I will need to upgrade to 5.3.1 but wamp doesn't add support yet? Anyone happen to be running 5.3.0 or 5.3.1 and can post their results? It happens just by pasting either of those examples into a blank file and running them on the CLI.

In fact If I put just $foo->bar() in an empty file and execute it I get 3 errors instead of 2 errors? wtf?

Code: Select all

 
# php test.php
PHP Notice:  Undefined variable: foo in /var/www/test.php on line 2
PHP Stack trace:
PHP   1. {main}() /var/www/test.php:0
 
Notice: Undefined variable: foo in /var/www/test.php on line 2
 
Call Stack:
    0.0002     618592   1. {main}() /var/www/test.php:0
 
PHP Fatal error:  Call to a member function bar() on a non-object in /var/www/test.php on line 2
PHP Stack trace:
PHP   1. {main}() /var/www/test.php:0
 
Fatal error: Call to a member function bar() on a non-object in /var/www/test.php on line 2
 
Call Stack:
    0.0002     618592   1. {main}() /var/www/test.php:0
 
If I download 5.3.1 CLI, and create a test file test.php, I can execute it no problem ( and can't replicate the line 0 thing)

When I run my tests under php 5.3.1 it hangs for like 5 minutes and I get mysql_connect error code 2002 A connection attempt failed because the connected party did not ( trying to connect via tcp://localhost:3306) in whatever.php line 151

^^^ Actual error message except the whatever.php part. Failed because the connected party did not what?

Then it hangs another 5 minutes and the same garbage comes onto my screen. Then PHPUnit shows it finally starts to run the first test but that is a database aware test and it hangs some more. My 12 second test suite is taking an hour.

Re: When I run my unit tests I get "errors on line 0"?

Posted: Wed Dec 16, 2009 3:59 pm
by Weirdan
I don't have this problem on 5.3.0:

Code: Select all

 
weirdan@virtual-debian:/home/sam/trunk$ php -v
PHP 5.3.0 (cli) (built: Aug 29 2009 17:22:23) (DEBUG)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
weirdan@virtual-debian:/home/sam/trunk$ php -derror_reporting=E_ALL q.php
 
Notice: Undefined variable: foo in /home/sam/trunk/q.php on line 2
 
Fatal error: Call to a member function bar() on a non-object in /home/sam/trunk/q.php on line 2
weirdan@virtual-debian:/home/sam/trunk$