[Catalyst] faking $c->user in tests

Ash Berlin ash_cpan at firemirror.com
Sat Jan 13 18:28:52 GMT 2007


Daniel McBrearty wrote:
> in test scripts I am able to (for instance) mess with the config my doing
> 
> my $config = MyApp->config;
> $config->{some_val} = 'test value';
> 
> 
> given that I am happy that my Authentication code is well tested in
> some other test script, is there a way to somehow bypass it, forcing
> calls to $c->user_exists and $c->user in the module I'm testing to
> return values which I directly control in the test script?
> 
> thanks
> 
> Daniel
> 
> 

Slightly hacky but something like:

{
   no warnings 'redefine'; # Not sure if this will be needed in this case
   *MyApp::user = sub { return bless {id=>'foo'}, MyApp::UserClass };
}

Might work. Or it might blow up in your face cos you looked at it funny 
- YMMV.

-ash



More information about the Catalyst mailing list