Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Inject mock objects with Pheasant::mock() #4

Closed
wants to merge 1 commit into from
Closed

Inject mock objects with Pheasant::mock() #4

wants to merge 1 commit into from

Conversation

lox
Copy link
Owner

@lox lox commented Jun 12, 2012

Pheasant domain objects are created by constructing them, so injecting mocks requires some magic with classloaders. Provided the class isn't already loaded, Pheasant::mock() allows for the a closure to be used to instantiate objects.

<?php

use \Mockery as M;

Pheasant::mock('\Animals\Llama', function() {
   $mock = M::mock('\Animals\Llama');
   $mock->shouldReceive('shear')->with('lightly')->once();
   $mock->shouldReceive('save')->once();
   return $mock;
});

$object = new \Animals\Llama();
$object->shear('lightly');
$object->save();

M::close();

@lox
Copy link
Owner Author

lox commented Jun 12, 2012

@rbone thoughts?

@rbone
Copy link
Collaborator

rbone commented Jun 13, 2012

The design looks pretty good, the only thing that's missing at the moment is __callStatic support on the MockProxy. I reckon that's actually the most important magic method of all of them, as it's the static calls to domain objects that are the most problematic to test, most other cases can just inject dependencies directly.

@rbone
Copy link
Collaborator

rbone commented Aug 24, 2017

Closing this as well as I don't expect it to advance any further. Feel free to reopen if I'm wrong.

@rbone rbone closed this Aug 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants