Beispiel #1
0
 /**
  * Test that the generated mock has the same doc mocked class
  */
 public function testGenerateMaintainsPhpDoc()
 {
     $newClassName = __CLASS__ . '_TestClass25';
     $mockedClass = 'PhakeTest_MockedClass';
     $this->classGen->generate($newClassName, $mockedClass, $this->infoRegistry);
     $rflClass = new ReflectionClass($newClassName);
     $this->assertFalse($rflClass->getMethod("foo")->getDocComment());
     $this->assertEquals("/**\n     * @return void\n     */", $rflClass->getMethod("fooWithComment")->getDocComment());
 }
Beispiel #2
0
 /**
  * Creates a new mock class than can be stubbed and verified.
  *
  * @param string                         $mockedClass   - The name of the class to mock
  * @param Phake_ClassGenerator_MockClass $mockGenerator - The generator used to construct mock classes
  * @param Phake_CallRecorder_Recorder    $callRecorder
  * @param Phake_Stubber_IAnswer          $defaultAnswer
  * @param array                          $constructorArgs
  *
  * @throws InvalidArgumentException
  * @return mixed
  */
 public function mock($mockedClass, Phake_ClassGenerator_MockClass $mockGenerator, Phake_CallRecorder_Recorder $callRecorder, Phake_Stubber_IAnswer $defaultAnswer, array $constructorArgs = null)
 {
     if (!class_exists($mockedClass, true) && !interface_exists($mockedClass, true)) {
         throw new InvalidArgumentException("The class / interface [{$mockedClass}] does not exist. Check the spelling and make sure it is loadable.");
     }
     if (!isset($this->cachedClasses[$mockedClass])) {
         $newClassName = $this->generateUniqueClassName($mockedClass);
         $mockGenerator->generate($newClassName, $mockedClass, $this->infoRegistry);
         $this->cachedClasses[$mockedClass] = $newClassName;
     }
     return $mockGenerator->instantiate($this->cachedClasses[$mockedClass], $callRecorder, new Phake_Stubber_StubMapper(), $defaultAnswer, $constructorArgs);
 }
Beispiel #3
0
 public function testDestructMocked()
 {
     $newClassName = __CLASS__ . '_TestClass' . uniqid();
     $mockedClass = 'PhakeTest_DestructorClass';
     $this->classGen->generate($newClassName, $mockedClass);
     /** @var $recorder Phake_CallRecorder_Recorder */
     $recorder = $this->getMock('Phake_CallRecorder_Recorder');
     $mapper = new Phake_Stubber_StubMapper();
     $answer = new Phake_Stubber_Answers_ParentDelegate();
     $mock = $this->classGen->instantiate($newClassName, $recorder, $mapper, $answer);
     unset($mock);
 }