|
From: Nicolas T. <nic...@gm...> - 2009-12-14 17:17:51
|
Hi,
I've got a fatal error while building a test.
************* The failing test case
<?php
class A {
function world($b, $val) {
}
}
Mock::generate('A');
class B {
function hello($val) {
$this->getA()->world($this, $val);
}
function getA() {
return new A();
}
}
Mock::generatePartial('B', 'B_TestVersion', array('getA'));
class ATest extends UnitTestCase {
function test() {
$a = new MockA();
$b = new B_TestVersion();
$b->setReturnReference('getA', $a);
$a->expect('world', array($b, 66));
$b->hello(66);
}
}
?>
*********** The call stack
[...]
7 0.0913 4406284 SimpleTestCase->run( object(CodendiHtmlReporter)[37]
) ../test_case.php:595
8 0.0920 4407688 SimpleExceptionTrappingInvoker->invoke( string(4)
) ../test_case.php:143
9 0.0921 4407824 SimpleInvokerDecorator->invoke( string(4)
) ../exceptions.php:43
10 0.0921 4407824 SimpleErrorTrappingInvoker->invoke( string(4)
) ../invoker.php:126
11 0.0921 4408352 SimpleInvokerDecorator->invoke( string(4) ) ../errors.php:49
12 0.0921 4408352 SimpleInvoker->invoke( string(4) ) ../invoker.php:126
13 0.0921 4408404 ATest->test( ) ../invoker.php:68
14 0.0929 4421520 B->hello( object(MockA)[45], long ) ../ATest.php:28
15 0.0930 4421952 MockA->world( object(B_TestVersion)[49],
object(MockA)[45] ) ../ATest.php:11
16 0.0930 4421952 SimpleMock->_invoke( string(5), array(2)
) ../mock_objects.php(1255) : eval()'d code:157
17 0.0930 4421952 SimpleMock->_checkExpectations( string(5), array(2),
long ) ../mock_objects.php:1061
18 0.0931 4421952 SimpleTestCase->assert(
object(ParametersExpectation)[57], array(2), string(25)
) ../mock_objects.php:1105
19 0.0931 4421952 ParametersExpectation->test( array(2) ) ../test_case.php:309
20 0.0931 4421952 ParametersExpectation->_testParameter(
object(B_TestVersion)[49], object(B_TestVersion)[49]
) ../mock_objects.php:65
21 0.0932 4422620 IdenticalExpectation->test(
object(B_TestVersion)[49] ) ../mock_objects.php:82
22 0.0932 4422620 SimpleTestCompatibility->isIdentical(
object(B_TestVersion)[49], object(B_TestVersion)[49]
) ../expectation.php:520
23 0.0932 4422620 SimpleTestCompatibility->_isIdenticalType(
object(B_TestVersion)[49], object(B_TestVersion)[49]
) ../compatibility.php:42
24 0.0933 4422620 SimpleTestCompatibility->_isArrayOfIdenticalTypes(
array(2), array(2) ) ../compatibility.php:68
25 0.0933 4422680 SimpleTestCompatibility->_isIdenticalType(
object(SimpleMock)[50], object(SimpleMock)[50]
) ../compatibility.php:94
26 0.0933 4423388 SimpleTestCompatibility->_isArrayOfIdenticalTypes(
array(9), array(9) ) ../compatibility.php:68
27 0.0934 4423520 SimpleTestCompatibility->_isIdenticalType(
object(SimpleCallSchedule)[51], object(SimpleCallSchedule)[51]
) ../compatibility.php:94
28 0.0934 4423640 SimpleTestCompatibility->_isArrayOfIdenticalTypes(
array(3), array(3) ) ../compatibility.php:68
29 0.0934 4423752 SimpleTestCompatibility->_isIdenticalType( array(1),
array(1) ) ../compatibility.php:94
30 0.0935 4423752 SimpleTestCompatibility->_isArrayOfIdenticalTypes(
array(1), array(1) ) ../compatibility.php:71
[...] and so on, and so on...
*********** Variables in local scope
$context Undefined
$filename =
string '/tests/include/simpletest/compatibility.php' (length=109)
$label Undefined
$line =
int 92
$mask =
null
$message =
string 'Non-static method SimpleTestCompatibility::_isIdenticalType()
should not be called statically, assuming $this from incompatible
context' (length=135)
$queue Undefined
$severity =
int 2048
***************************
My workaround for this is to put a wildcard in the expectation:
$a->expect('world', array('*', 66));
However I don't like it so much.
My ST version is 1.0.1
Has this bug been already covered in the upcoming 1.1 ?
Thanks,
Nicolas
|
|
From: Marcus B. <ma...@la...> - 2009-12-14 22:22:32
|
Hi...
Nicolas Terray wrote:
> My workaround for this is to put a wildcard in the expectation:
I tried this workaround...
$a->expect('world', array(new ReferenceExpectation($b), 66));
...but no dice. Now I have two bugs instead of one.
This is going to be a tricky one to fix. It does do a loop check as it
carries out an identity expectation, but the loop is called by itself
appearing in it's own expectation. That's exceptionally tricky.
This one does work, but is possibly not stringent enough.
$a->expect('world', array(new EqualExpectation($b), 66));
What you actually want (if you want to check that the object is passed
to itself) is...
$a->expect('world', array(new SameExpectation($b), 66));
...but this one isn't implemented :(.
> My ST version is 1.0.1
> Has this bug been already covered in the upcoming 1.1 ?
No. That's the one I'm testing against.
I'll note it as a bug report and see what I can do in later versions. As
a workaround I'll implement SameExpectation for the coming release.
>
> Thanks,
> Nicolas
yours, Marcus
|
|
From: Nicolas T. <nic...@gm...> - 2009-12-15 09:58:39
|
2009/12/14 Marcus Baker <ma...@la...>:
> $a->expect('world', array(new ReferenceExpectation($b), 66));
[...]
> $a->expect('world', array(new SameExpectation($b), 66));
>
What would be the differences between "Reference" and "Same" concepts ?
Thanks,
Nicolas
|
|
From: Marcus B. <ma...@wo...> - 2009-12-15 11:01:49
|
Hi... Nicolas Terray wrote: > What would be the differences between "Reference" and "Same" concepts ? Same corresponds to the === operator. Reference corresponds to the PHP4 concept of the & operator. Currently it's a blend as it will pass if either: 1) Values $a and $b really are the same ($b = &$a). 2) Object ids match even though they are not the same reference. Same will check value for number 1, but has teh same bahaviour for as SimpleTests reference checking for 2. This was to allow people to migrate old code like this... $my = &new MyObject(); $my2 = &$my; $this->assertReference($my, $my2); ...to... $my = new MyObject(); $my2 = $my; $this->assertReference($my, $my2); ...in PHP5 without breaking all their tests. > > Thanks, > Nicolas yours, Marcus |