List Info

Thread: expectError doesn't fail if error not found




expectError doesn't fail if error not found
user name
2007-05-23 12:17:24
Hello,

I'm using PHP 5.1.6 on Debian with SimpleTest 1.0.1beta.

If I call expectError, and then an error is not raised, then
the test
case does not fail.

Here is the example:

        class TestTester extends UnitTestCase {
                function testErrors() {
                        $this->expectError("Error
1");
                        trigger_error("Error 1");
                        $this->expectError("Error
2");
                }
        }

Expected behavior: Test case fails
Actual behavior: Test case passes

I tried this with the latest version from CVS, and it still
didn't work.

Thanks,
Dave

------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Simpletest-support mailing list
Simpletest-supportlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simp
letest-support

Re: expectError doesn't fail if error not found
country flaguser name
France
2007-05-29 14:37:08
I'm not sure there's anything I can do about this : the
assertion is 
actually done with the "trigger_error" (not the
"expectError"). A custom 
error handler will take charge of the error, match it
against its queue 
and then either give a pass or a fail.

At the end of your test, you error queue isn't empty but no
errors are 
thrown : SimpleTest has no mechanism to check if there are
errors still 
  expected.

So you'd have to add a custom "tearDown" method,
here's something that 
could do the trick...

class TestTester extends UnitTestCase {
	function tearDown() {
		$context = &SimpleTest::getContext();
		$queue = &$context->get('SimpleErrorQueue');
		$this->assertEqual($queue, array(), "error queue
not empty");
		
	}
	
	function testErrors() {
		$this->expectError("Error 1");
		trigger_error("Error 1");
		$this->expectError("Error 2");
	}
}

Hope it helps,

Yours,
	Perrick


David Besen wrote:
> Hello,
> 
> I'm using PHP 5.1.6 on Debian with SimpleTest
1.0.1beta.
> 
> If I call expectError, and then an error is not raised,
then the test
> case does not fail.
> 
> Here is the example:
> 
>         class TestTester extends UnitTestCase {
>                 function testErrors() {
>                        
$this->expectError("Error 1");
>                         trigger_error("Error
1");
>                        
$this->expectError("Error 2");
>                 }
>         }
> 
> Expected behavior: Test case fails
> Actual behavior: Test case passes
> 
> I tried this with the latest version from CVS, and it
still didn't work.
> 
> Thanks,
> Dave
> 
>
------------------------------------------------------------
-------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2
express and take
> control of your XML. No limits. Just data. Click to get
it now.
> http://sourcefor
ge.net/powerbar/db2/
> _______________________________________________
> Simpletest-support mailing list
> Simpletest-supportlists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/simp
letest-support
> 
> 

------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Simpletest-support mailing list
Simpletest-supportlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simp
letest-support

Re: expectError doesn't fail if error not found
country flaguser name
France
2007-05-29 15:09:44
Re-reading the documentation, I find the following phrase
"If any 
unchecked errors are left at the end of a test method then
an exception 
will be reported in the test." Does it mean it's
actually a bug ?

	Perrick


Perrick Penet wrote:
> I'm not sure there's anything I can do about this : the
assertion is 
> actually done with the "trigger_error" (not
the "expectError"). A custom 
> error handler will take charge of the error, match it
against its queue 
> and then either give a pass or a fail.
> 
> At the end of your test, you error queue isn't empty
but no errors are 
> thrown : SimpleTest has no mechanism to check if there
are errors still 
>   expected.
> 
> So you'd have to add a custom "tearDown"
method, here's something that 
> could do the trick...
> 
> class TestTester extends UnitTestCase {
> 	function tearDown() {
> 		$context = &SimpleTest::getContext();
> 		$queue = &$context->get('SimpleErrorQueue');
> 		$this->assertEqual($queue, array(), "error
queue not empty");
> 		
> 	}
> 	
> 	function testErrors() {
> 		$this->expectError("Error 1");
> 		trigger_error("Error 1");
> 		$this->expectError("Error 2");
> 	}
> }
> 
> Hope it helps,
> 
> Yours,
> 	Perrick
> 
> 
> David Besen wrote:
>> Hello,
>>
>> I'm using PHP 5.1.6 on Debian with SimpleTest
1.0.1beta.
>>
>> If I call expectError, and then an error is not
raised, then the test
>> case does not fail.
>>
>> Here is the example:
>>
>>         class TestTester extends UnitTestCase {
>>                 function testErrors() {
>>                        
$this->expectError("Error 1");
>>                         trigger_error("Error
1");
>>                        
$this->expectError("Error 2");
>>                 }
>>         }
>>
>> Expected behavior: Test case fails
>> Actual behavior: Test case passes
>>
>> I tried this with the latest version from CVS, and
it still didn't work.
>>
>> Thanks,
>> Dave
>>
>>
------------------------------------------------------------
-------------
>> This SF.net email is sponsored by DB2 Express
>> Download DB2 Express C - the FREE version of DB2
express and take
>> control of your XML. No limits. Just data. Click to
get it now.
>> http://sourcefor
ge.net/powerbar/db2/
>> _______________________________________________
>> Simpletest-support mailing list
>> Simpletest-supportlists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/simp
letest-support
>>
>>
> 
>
------------------------------------------------------------
-------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2
express and take
> control of your XML. No limits. Just data. Click to get
it now.
> http://sourcefor
ge.net/powerbar/db2/
> _______________________________________________
> Simpletest-support mailing list
> Simpletest-supportlists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/simp
letest-support
> 
> 

------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Simpletest-support mailing list
Simpletest-supportlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simp
letest-support

Re: expectError doesn't fail if error not found
country flaguser name
United States
2007-05-30 09:40:04
Hi David...

David Besen wrote:
> I'm using PHP 5.1.6 on Debian with SimpleTest
1.0.1beta.
>
> If I call expectError, and then an error is not raised,
then the test
> case does not fail.
>
> Here is the example:
>
>         class TestTester extends UnitTestCase {
>                 function testErrors() {
>                        
$this->expectError("Error 1");
>                         trigger_error("Error
1");
>                        
$this->expectError("Error 2");
>                 }
>         }
>
> Expected behavior: Test case fails
> Actual behavior: Test case passes
>
> I tried this with the latest version from CVS, and it
still didn't work.

Can you update your working copy and try this again.  I
tracked down the 
issue yesterday and added a fix.  I also added your test
case to 
SimpleTest to verify that it's working.  test/unit_tests.php
should 
still pass (with more passing tests now) and your test case
above should 
fail.  Look at the final test cases in test/errors_test.php
to see how I 
tested a false positive.

On another note, would one of the other devs look at code
that I 
committed yesterday?  I'm looking for a review on it to see
if anyone 
else sees a better way of handling it.

-Travis

------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Simpletest-support mailing list
Simpletest-supportlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simp
letest-support

Re: expectError doesn't fail if error not found
country flaguser name
France
2007-05-31 14:29:34
Hi there,


Travis Swicegood wrote:

> On another note, would one of the other devs look at
code that I 
> committed yesterday?  I'm looking for a review on it to
see if anyone 
> else sees a better way of handling it.

Looks good enough to me. I guess it just needs the comments
now 

Yours,
	Perrick


------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Simpletest-support mailing list
Simpletest-supportlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simp
letest-support

Re: expectError doesn't fail if error not found
user name
2007-05-31 14:39:52
Yup, that seems to have fixed it.  Thanks!

Dave

------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Simpletest-support mailing list
Simpletest-supportlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simp
letest-support

Re: expectError doesn't fail if error not found
country flaguser name
United Kingdom
2007-06-03 15:04:02
Hi...

David Besen wrote:
> If I call expectError, and then an error is not raised,
then the test
> case does not fail.

Ouch! OK, I'm looking in to this.

> Thanks,
> Dave

yours, Marcus
-- 
Marcus Baker
marcuslastcraft.com

------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Simpletest-support mailing list
Simpletest-supportlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simp
letest-support

Re: expectError doesn't fail if error not found
country flaguser name
United Kingdom
2007-06-03 20:55:58
Hi...

Marcus Baker wrote:
> Ouch! OK, I'm looking in to this.

I should check the dates on mails :(. I am still dealing
with a big
e-mail failure about a month ago. Sorry for any confusion.

> yours, Marcus

yours, Marcus
-- 
Marcus Baker
marcuslastcraft.com

------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Simpletest-support mailing list
Simpletest-supportlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simp
letest-support

[1-8]

about | contact  Other archives ( Real Estate discussion Medical topics )