Created
December 17, 2010 17:44
-
-
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you explain me why "$this" is needed as a parameter on line 7? Which content it passes trough?