Tuesday, 15 July 2014

php - Mocking a custom class with Mockery in Laravel 4 -



php - Mocking a custom class with Mockery in Laravel 4 -

using laravel 4.2, i've got custom class testyclass in /app/libraries.

using mockery , phpunit, attempting mock class, mock doesn't seem register.

when run test, mockery\exception\invalidcountexception: method testymethod() mockery_0_testyclass should called 1 times called 0 times.

my controller testing runs testyclass::testymethod();, , log::info within of testymethod() runs correctly.

what missing register mock of custom class in laravel 4.2?

$mock = mockery::mock('testyclass'); $mock->shouldreceive('testymethod')->once();

testyclass:

class testyclass { public static function testymethod() { log::info('----=-=-=-=--=in heyhey!@!!=-=-=-=-=-=-=-12312312312312341'); homecoming true; } }

this code:

$mock = mockery::mock('testyclass');

creates new class extends testyclass, adding behaviour necessary mock etc, creates , instance of , returns it, $mock instance of mockery_0_testyclass

you're telling mockery expect instance receive phone call testymethod, you're making static phone call testyclass class method. can mockery, it's not good, wouldn't recommend doing , you'll want run tests process isolation.

$mock = mockery::mock('alias:testyclass');

php unit-testing laravel phpunit mockery

No comments:

Post a Comment