2009年5月8日星期五

Re: [fw-mvc] Clarification of recommended tests directory structure

On Fri, May 8, 2009 at 9:08 AM, Ralph Schindler
<ralph.schindler@zend.com> wrote:
>
>
> Adam Jensen wrote:
>>
>> Hello!
>>
>> I would like to get started writing some unit tests for the
>> application I'm working on, but I'm having a little bit of trouble
>> figuring out just what goes where and why.  The default tests
>> directory structure as defined by Zend_Tool is as follows:
>>
>> tests
>> |--phpunit.xml
>> |--application
>> |   |-bootstrap.php
>> |--library
>> |   |-bootstrap.php
>>
>> (Pardon the ASCII art.)
>>
>> Now, I can certainly see the benefit of separating tests out in this
>> manner, but I'm a bit confused about what goes into each of the
>> provided files (as provided by Zend_Tool, they are empty…at least as
>> of a few days ago).  I know that phpunit.xml should conform to the
>
> The code that belongs inside these files is something I will be working out
> with Matthew in the near future to round out.  I will add an issue to the
> issue tracker to facilitate development of this feature.
>
>> usual syntax
>> (http://www.phpunit.de/manual/current/en/appendixes.configuration.html),
>> and that its root element can include a bootstrap path as follows:
>
> That is correct, this allows you to execute phpunit from the top level
> directory and be able to run your tests with a common configuration.
>
>> <phpunit bootstrap="application/bootstrap.php">
>>  ...
>> </phpunit>
>>
>> But that only addresses one of the bootstrap files in the default
>> structure.  Presumably if I ran my tests from within the "tests"
>> directory, I'd want to run both my "applications" tests and my
>> "library" tests, right?  If that's the case, why not have a
>> bootstrap.php in the root "tests" directory that covers both suites?
>> Or maybe there should be a separate phpunit.xml file in each of the
>> subdirectories of "tests", pointing at a different bootstrap file?
>
> You got it mostly right.  the bootstrap.php here is the phpunit specific
> bootstrap.  Generally speaking, application code and library code usually
> have different API requirements.  For example, application code is part of a
> larger infrastructure, controllers (and thus controller tests) are part of
> the Zend_Controller infrastructure, views part of the
> Zend_Controller/Zend_View infrastructure.
>
> As a result, they generally will extend a Zend_Test interface and/or base
> test class.  But the biggest single difference is that the placement of
> files and directories is subject to the application structure.  This means
> that there is not a logical one-to-one class name mapping such as you see
> with library code (like the PEAR naming convention).
>

Interesting…so, for instance, one reason to have separate bootstraps
is that, when testing library code, there isn't any reason to register
all the extra autoloaders you get with module-level bootstrapping
(which kind of applies to the application folder, though it doesn't
require the modules resource).

Actually, that makes me think that maybe these bootstrap.php files
have more in common with public/index.php …they'll set up the
environment and use Zend_Application to bootstrap exactly what they
need, but otherwise don't do much? That would be consistent with
bootstrap.php files I've set up for unit testing in the past, though
much, much, much cleaner. :)

In any case, I'm really looking forward to what you guys come up with;
thanks for your quick reply!

>
>> I can certainly get it working via either of those solutions, but I
>> wanted to see if anyone could provide more details on why the default
>> structure is what it is…I've read through the proposal
>>
>> (http://framework.zend.com/wiki/display/ZFPROP/Zend+Framework+Default+Project+Structure+-+Wil+Sinclair)
>> and there are some hints at the very end…but I'm still not sure I know
>> what I'm doing :)
>
> Once I get my recent features of Zend_Tool out the door, me and matthew will
> explore this (as he is the primary author of both Zend_Application and
> Zend_Test, the two components that heavily influence what goes in these
> files).
>
> -ralph
>

没有评论: