ggramlich / phpslim

Php Port of Robert C. Martin's Slim
http://ggramlich.github.com/phpslim
21 stars 6 forks source link

Custom Bootstrap loading before executing Fixtures #1

Closed ohoareau closed 14 years ago

ohoareau commented 14 years ago

I often try to provide specific entry points into my applications :

As a result of this, I need to "execute" a context-specific bootstrap (php file) before playing with classes and methods (or fixtures, unit tests...). This is a common mechanism that is already available in tools such as PHPUnit.

Is it possible to add such a feature in PHPSlim ? I mean to be able to "specify" a PHP file that will be executed at the very beginning before the first fixture is even loaded ?

At this time, I am currently using this kind of settings to "activate" this behaviour :

-- in fitnesse's root page :

!define TEST_RUNNER (/my/application/path/bootstraps/fitnesse.php)
!define COMMAND_PATTERN (php %m .)
!define TEST_SYSTEM (slim)

-- in bootstraps/fitnesse.php :

$_SERVER['PHP_ENV'] = 'fitnesse';

// ... sets include path by hand (if specific)
// ... adds autoloader by hand (if specific)
// ... loads configuration file depending on PHP_ENV env var
// ... loads specific test data (i.e. referential data only)
// ... do specific stuff required by frameworks...

$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
include 'phpslim.phar';

You can for example provide an extra parameter on the CLI interface of PhpSlim (optional) that will point to a php file that will automatically included before instantiating fixtures, no ? (there are several ways to do this of course, it is only an example);

Olivier H.

ggramlich commented 14 years ago

Hi Olivier,

I can provide that functionality by adding an optional parameter to the command pattern.

For my purposes, I was able to do all this (setting up more include paths, adding another autoloader, ...) by wrapping this into a setup fixture, but maybe there might be the need to register another autolader before the PhpSlim autoloader is registered?

I will take a look at it.

Gregor

ohoareau commented 14 years ago

Thanks for your answer ;)

Extra parameter will be great and more flexible IMHO.

Keep in touch,

Olivier H.

ohoareau commented 14 years ago

Closing this issue

ggramlich commented 14 years ago

You can now specify a bootstrap file with a -b option followed by the filename.

!define TEST_RUNNER (/path/to/phpslim.phar) !define PHP_BOOTSTRAP (/my/application/path/bootstraps/fitnesse.php) !define COMMAND_PATTERN (php %m -b ${PHP_BOOTSTRAP} .)