Re: Re: question regarding Reflection

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

 



On 11/1/05, Curt Zirzow <czirzow@xxxxxxxxx> wrote:
>
> 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.


Wow, this certainly helps when we actually run the unit tests and I didn't
think of this earlier so my next question has been already answered by you I
guess if I understand you.

My current problem is this: Below is some chunk of the scrip I am writing to
generate test code.

include_once "Company.php";

class TestGenerator {

public function TestGenerator() {

}

public function catchReflection() {

$classInfo = new ReflectionClass('Company');
// Below here I will be getting all the information about the class
"Company" and then I will be generating a test class CompanyTest which
resides in the file CompanyTest.php.
}
}

So in this script of mine I have included the Company.php above because the
statement $classInfo = new ReflectionClass('Company'); uses it. Now this is
just an example I have taken to see how my generator works. The user would
use the TestGenerator something like this:

php TestGenerator.php myClass

Now is there a way that in my script I can let PHP look for a file
myClass.php or for that matter any php file that has myClass so that I don't
have to include it, as it is totally upto the user which file its gonna pass
to the TestGenerator.php script to generate the test code and I cannot
statically include that in my file. I believe this time I have stated my
problem clearer, earlier I did not, I apologize.

Thank You

 Manish Marathe
SpikeSource, Inc.
http://developer.spikesource.com

[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