Skip to content

Instantly share code, notes, and snippets.

@fabiosussetto
Created December 17, 2010 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiosussetto/745348 to your computer and use it in GitHub Desktop.
Save fabiosussetto/745348 to your computer and use it in GitHub Desktop.
With SimpleTest, when creating a partial mock, the real object constructor is NOT called. This make impossible to mock model in tests, because things like Behaviors, etc. will not be initialized. I (probably) solved with this:
Mock::generatePartial('Article','MockArticle', array('testCall'));
// then inside the test case class:
public function startTest($method) {
parent::startTest($method);
$this->Article = new MockArticle($this);
$this->Article->alias = 'Article';
$reflectionMethod = new ReflectionMethod('Article', '__construct');
$reflectionMethod->invoke($this->Article);
}
@rafavalerio
Copy link

Can you explain me why "$this" is needed as a parameter on line 7? Which content it passes trough?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment