yeluolei / hessianphp

Automatically exported from code.google.com/p/hessianphp
MIT License
0 stars 1 forks source link

Unit test fail on a custom server - possible problem in PHP_INT_MAX / integer datatype #13

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Starting hessianphp unit tests on my server did fail by 2 tests - I am not 
actually sure, what causes the problem, but it seems so be the integer datatype 
handling 
2. The problem may be, that on my machine 8 bytes are used for integer and 
thereby the constant PHP_INT_MAX is set to 2^64-1

What is the expected output? What do you see instead?
The unit tests should work without failures. Instead 2 failures are raised:

Fail: Hessian2Tests -> testDateToString -> Equal expectation fails at character 
3 with [2005-12-27 08:39:48] and [2006-11-14 11:16:44] at [... base_test.php 
line 274]

Fail: Hessian2Tests -> testStringToLong -> Equal expectation fails because 
[Float: 980440.064] differs from [Integer: 5124567855432488] by 
5.12456785445E+15 at [... base_test.php line 105]

What version of the product are you using? On what operating system?
Version 2.0.3

Please provide any additional information below.

I installed the actual version of hessianphp and started the unit tests, which 
threw the above errors.

After some hours of debugging I found the problem for the first error 
(testDateToString): When packing unsigned integers and unpacking them again, 
the result will be a signed integer (see http://ch2.php.net/unpack). This issue 
was handeled in line 152 of HessianUtils::timestampFromBytes64 (if $res < 0), 
but it doesn't seem to work on my machine. I did not understand how the code 
handeled this but I created an own solution to convert the signed int values to 
unsigned int and it seems to work. 

I created a patch for this that I attach here. It would be nice if you could 
check this solution and if it is good, apply it to the current version.

For the second failure I couldn't yet find a solution, but I can't really 
imagine that the unit test does work somewhere else, as this is a 
string-to-long conversion and in the handler-function of the server the 
parameter is cast using 'floatval' (HessianTest->testStringToLong) which should 
return a float - not a long.

Original issue reported on code.google.com by ole...@gmx.net on 21 Feb 2011 at 4:46

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,
I've reviewed the problem and I suspect it has something to do with the 
PHP_INT_MAX constant, are you working on a 64 bit version of PHP? 
The patch you propose actually messes up the results on my end, hehe, so I am 
trying a different approach. Since the PHP_INT_MAX constant is platform 
dependent and it might change, I hardcoded the value for 32 bit integers in the 
HessianUtils class so it behaves the same regardless of the platform. Please 
try the newest version to see if the issue is resolved. I think in the future, 
a 64 bit detection will have to be incorporated as it might make things easier. 
Thank you.

Original comment by vegeta...@gmail.com on 9 Jul 2011 at 6:40