Discussion:
Cannot redeclare function, process isolation
Felix Hall
2010-07-14 08:44:24 UTC
Permalink
Hi all,

I'm writing a test suite for a legacy system, in which some function
names are not unique.
When I run the suite, containing test cases for both versions of the
function, I get the following error:
RuntimeException: Fatal error: Cannot redeclare my_function()
(previously declared in /path/to/code/web/functions/a_file.php:183) in
/path/to/code/web/functions/another_file.php on line 77

No surprises there, but I thought that the --process-isolation or
@runInSeparateProcess would solve this, but apparently it doesn't. I'm
currently "solving" the problem by renaming the function not under test
to something else, making sure there's always just one function declared
with the name.

Sadly I'm not allowed to refactor the code, otherwise I'd solve it that
way ;)

I wonder if there's another way of doing this, other than renaming the
functions all the time?



Additionally, I get another error when I run the whole suite
process-isolated:
RuntimeException: ALERT - canary mismatch on efree() - heap overflow
detected (attacker 'REMOTE_ADDR not set', file 'unknown')

I've figured out that this has something to do with the Suhosin-patch
defending me against overflows and remote code execution, but I wonder
why this appears when I run the suite process-isolated and not
single-threaded?

Thankful for any help!
Regards
Felix Hall
Dobroslav Kolev
2010-07-14 15:25:43 UTC
Permalink
Hi Felix

Are the conflicting functions defined in some set of files all of which you need to have your code library to work. It can you include them separately in different tests?

Dobri
Post by Felix Hall
Hi all,
I'm writing a test suite for a legacy system, in which some function
names are not unique.
When I run the suite, containing test cases for both versions of the
RuntimeException: Fatal error: Cannot redeclare my_function()
(previously declared in /path/to/code/web/functions/a_file.php:183) in
/path/to/code/web/functions/another_file.php on line 77
No surprises there, but I thought that the --process-isolation or
@runInSeparateProcess would solve this, but apparently it doesn't. I'm
currently "solving" the problem by renaming the function not under test
to something else, making sure there's always just one function declared
with the name.
Sadly I'm not allowed to refactor the code, otherwise I'd solve it that
way ;)
I wonder if there's another way of doing this, other than renaming the
functions all the time?
Additionally, I get another error when I run the whole suite
RuntimeException: ALERT - canary mismatch on efree() - heap overflow
detected (attacker 'REMOTE_ADDR not set', file 'unknown')
I've figured out that this has something to do with the Suhosin-patch
defending me against overflows and remote code execution, but I wonder
why this appears when I run the suite process-isolated and not
single-threaded?
Thankful for any help!
Regards
Felix Hall
Felix Hall
2010-07-15 08:53:29 UTC
Permalink
Hi,

Thanks for replying so fast!
The conflicting functions does not have to be in my code library for the
same test, but I'd like them to be in the same test suite.
I do require_once in each test for the function currently under test.

Felix
Post by Dobroslav Kolev
Hi Felix
Are the conflicting functions defined in some set of files all of which you need to have your code library to work. It can you include them separately in different tests?
Dobri
Post by Felix Hall
Hi all,
I'm writing a test suite for a legacy system, in which some function
names are not unique.
When I run the suite, containing test cases for both versions of the
RuntimeException: Fatal error: Cannot redeclare my_function()
(previously declared in /path/to/code/web/functions/a_file.php:183) in
/path/to/code/web/functions/another_file.php on line 77
No surprises there, but I thought that the --process-isolation or
@runInSeparateProcess would solve this, but apparently it doesn't. I'm
currently "solving" the problem by renaming the function not under test
to something else, making sure there's always just one function declared
with the name.
Sadly I'm not allowed to refactor the code, otherwise I'd solve it that
way ;)
I wonder if there's another way of doing this, other than renaming the
functions all the time?
Additionally, I get another error when I run the whole suite
RuntimeException: ALERT - canary mismatch on efree() - heap overflow
detected (attacker 'REMOTE_ADDR not set', file 'unknown')
I've figured out that this has something to do with the Suhosin-patch
defending me against overflows and remote code execution, but I wonder
why this appears when I run the suite process-isolated and not
single-threaded?
Thankful for any help!
Regards
Felix Hall
Ian Young
2010-07-14 16:14:58 UTC
Permalink
Process isolation ought to solve this problem - I've used it before for
exactly this purpose. Are you including all the bad files inside the
test methods themselves? I believe each child process inherits the PHP
env of the parent, so if you've pulled one of the guilty functions in
before the individual tests run, that could be the problem.

Ian
Post by Felix Hall
Hi all,
I'm writing a test suite for a legacy system, in which some function
names are not unique.
When I run the suite, containing test cases for both versions of the
RuntimeException: Fatal error: Cannot redeclare my_function()
(previously declared in /path/to/code/web/functions/a_file.php:183) in
/path/to/code/web/functions/another_file.php on line 77
No surprises there, but I thought that the --process-isolation or
@runInSeparateProcess would solve this, but apparently it doesn't. I'm
currently "solving" the problem by renaming the function not under test
to something else, making sure there's always just one function declared
with the name.
Sadly I'm not allowed to refactor the code, otherwise I'd solve it that
way ;)
I wonder if there's another way of doing this, other than renaming the
functions all the time?
Additionally, I get another error when I run the whole suite
RuntimeException: ALERT - canary mismatch on efree() - heap overflow
detected (attacker 'REMOTE_ADDR not set', file 'unknown')
I've figured out that this has something to do with the Suhosin-patch
defending me against overflows and remote code execution, but I wonder
why this appears when I run the suite process-isolated and not
single-threaded?
Thankful for any help!
Regards
Felix Hall
Felix Hall
2010-07-15 09:00:09 UTC
Permalink
Hi, and thanks for replying.

So this means that everything that is included outside a test method is
considered global to the test suite, if each test is run process
isolated? That would indeed explain my problem. Thanks!
How about the setUp and setUpBeforeClass? Do you know if the child
processes are spawned before these are called, so that any include can
be done there and still be local to that process?

Felix
Post by Ian Young
Process isolation ought to solve this problem - I've used it before for
exactly this purpose. Are you including all the bad files inside the
test methods themselves? I believe each child process inherits the PHP
env of the parent, so if you've pulled one of the guilty functions in
before the individual tests run, that could be the problem.
Ian
Post by Felix Hall
Hi all,
I'm writing a test suite for a legacy system, in which some function
names are not unique.
When I run the suite, containing test cases for both versions of the
RuntimeException: Fatal error: Cannot redeclare my_function()
(previously declared in /path/to/code/web/functions/a_file.php:183) in
/path/to/code/web/functions/another_file.php on line 77
No surprises there, but I thought that the --process-isolation or
@runInSeparateProcess would solve this, but apparently it doesn't. I'm
currently "solving" the problem by renaming the function not under test
to something else, making sure there's always just one function declared
with the name.
Sadly I'm not allowed to refactor the code, otherwise I'd solve it that
way ;)
I wonder if there's another way of doing this, other than renaming the
functions all the time?
Additionally, I get another error when I run the whole suite
RuntimeException: ALERT - canary mismatch on efree() - heap overflow
detected (attacker 'REMOTE_ADDR not set', file 'unknown')
I've figured out that this has something to do with the Suhosin-patch
defending me against overflows and remote code execution, but I wonder
why this appears when I run the suite process-isolated and not
single-threaded?
Thankful for any help!
Regards
Felix Hall
Ian Young
2010-07-15 17:23:25 UTC
Permalink
Yep, my understanding is that at least setUp is isolated, and I have
successfully used that to repeatedly include files I needed.

Ian
Post by Felix Hall
Hi, and thanks for replying.
So this means that everything that is included outside a test method is
considered global to the test suite, if each test is run process
isolated? That would indeed explain my problem. Thanks!
How about the setUp and setUpBeforeClass? Do you know if the child
processes are spawned before these are called, so that any include can
be done there and still be local to that process?
Felix
Post by Ian Young
Process isolation ought to solve this problem - I've used it before
for exactly this purpose. Are you including all the bad files inside
the test methods themselves? I believe each child process inherits the
PHP env of the parent, so if you've pulled one of the guilty functions
in before the individual tests run, that could be the problem.
Ian
Post by Felix Hall
Hi all,
I'm writing a test suite for a legacy system, in which some function
names are not unique.
When I run the suite, containing test cases for both versions of the
RuntimeException: Fatal error: Cannot redeclare my_function()
(previously declared in /path/to/code/web/functions/a_file.php:183) in
/path/to/code/web/functions/another_file.php on line 77
No surprises there, but I thought that the --process-isolation or
@runInSeparateProcess would solve this, but apparently it doesn't. I'm
currently "solving" the problem by renaming the function not under test
to something else, making sure there's always just one function declared
with the name.
Sadly I'm not allowed to refactor the code, otherwise I'd solve it that
way ;)
I wonder if there's another way of doing this, other than renaming the
functions all the time?
Additionally, I get another error when I run the whole suite
RuntimeException: ALERT - canary mismatch on efree() - heap overflow
detected (attacker 'REMOTE_ADDR not set', file 'unknown')
I've figured out that this has something to do with the Suhosin-patch
defending me against overflows and remote code execution, but I wonder
why this appears when I run the suite process-isolated and not
single-threaded?
Thankful for any help!
Regards
Felix Hall
David Harkness
2010-07-15 18:30:04 UTC
Permalink
Post by Ian Young
Yep, my understanding is that at least setUp is isolated, and I have
successfully used that to repeatedly include files I needed.
Ah, that's a good point. PHPUnit instantiates the TestCase for every test
ahead of time, so you may get success by putting the require inside setUp().
I'm not sure how process isolation affects PHPUnit's instantiation policy,
but I would bet $5 that it instantiates the class in the root process and
again in the child process. It most definitely has to include the test case
file in the root process, and if you do the require in the global area for
the file, you'll get name collisions.

Silvério Santos
2010-07-14 16:41:29 UTC
Permalink
Post by Felix Hall
Hi all,
I'm writing a test suite for a legacy system, in which some function
names are not unique.
When I run the suite, containing test cases for both versions of the
RuntimeException: Fatal error: Cannot redeclare my_function()
(previously declared in /path/to/code/web/functions/a_file.php:183) in
/path/to/code/web/functions/another_file.php on line 77
No surprises there, but I thought that the --process-isolation or
@runInSeparateProcess would solve this, but apparently it doesn't. I'm
currently "solving" the problem by renaming the function not under
test to something else, making sure there's always just one function
declared with the name.
Sadly I'm not allowed to refactor the code, otherwise I'd solve it
that way ;)
I wonder if there's another way of doing this, other than renaming the
functions all the time?
How do you include the files containing the functions? If you use
include/require, then try replacing that with include_once/require_once.
Maybe that helps.

Regards
Silvério
David Harkness
2010-07-14 16:49:25 UTC
Permalink
Post by Silvério Santos
How do you include the files containing the functions? If you use
include/require, then try replacing that with include_once/require_once.
The problem isn't that the same file is being included twice, it's that two
different functions that have the same name in two different files are being
included.
Loading...