When I run my unit tests I get "errors on line 0"?
Moderator: General Moderators
When I run my unit tests I get "errors on line 0"?
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?
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"?
The only time I've seen errors like this is when there was a PHP compilation error.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: When I run my unit tests I get "errors on line 0"?
Either post code (like what you were testing) or be more specific in the error message. Both would be nice.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: When I run my unit tests I get "errors on line 0"?
What exactly is the code on line 0?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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: When I run my unit tests I get "errors on line 0"?
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?)
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: When I run my unit tests I get "errors on line 0"?
Holy crap, you have a line 0? I was joking...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?)
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: When I run my unit tests I get "errors on line 0"?
AH I didn't know you meant literally, now that I get it its very funny
,
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
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
Re: When I run my unit tests I get "errors on line 0"?
Ok here's some more, from a different server
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:
And when I run it in the browser I get
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 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
Code: Select all
PDO
PDO support enabled
PDO drivers mysqlRe: When I run my unit tests I get "errors on line 0"?
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"?
Ok the problem started happening again:
The error I get Is:
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?
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' );
}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
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?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: When I run my unit tests I get "errors on line 0"?
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
Re: When I run my unit tests I get "errors on line 0"?
But not on line 0 I bet.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.
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"?
I narrowed it down. If I put
It calls it line 204 (actual)
If I put
(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?
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.
Code: Select all
$foo = null;
$foo->bar();If I put
Code: Select all
$foo->bar();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
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"?
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$