Re: question regarding Reflection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 01 Nov 2005 14:31:12 -0800, Manish Marathe wrote:

> ...
> My question is to use the Reflection API, I need to import the original
> class for which I am generating tests. For example to generate a tests for
> class Company which is in Company.php:
> 
> include_once('company.php');
> 
> $c = new ReflectionClass('Company');
> 
> If I have to generate test for many classes at once, it would be foolish
> to have them included in my file on the runtime. Am I understanding it
> correctly ?

Yes you are understanding correctly.  You can avoid this issue by using
the pcntl[1] tools available in php (assuming this is a *nix environment.)
A simple usage would be something like:

<?php

$pid = pcntl_fork();
if ($pid == -1) {

  die('could not fork');

} else if ($pid) {

  // we are the parent
  pcntl_wait($status); //Protect against Zombie children

  echo 'Class is defined: ';
  var_dump(class_exists('foobar', false));

} else {

  // we are the child
  // create a class to see if the parent sees it
 class foobar { }

  // do your Unit testing..

}

The parent process would just iterate through all the class files
you need to include and fork a child.  Then you can include the file in
the child process run your unit test and then exit.

I use this method for any sort of long lasting script that causes a lot of
memory or resource usage.

[1] http://php.net/pcntl
 
HTH,

Curt.
-- 
http://news.zirzow.dyndns.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux