Inheritance: extends PHPUnit_Framework_TestCase
示例#1
0
 /** @return MockObject */
 private function buildMock(array $args)
 {
     $mockBuilder = $this->testCase->getMockBuilder($this->className);
     $mockBuilder->setMethods(array_merge($this->extractMethods(), array('this', 'mock')));
     if ($args) {
         $mockBuilder->setConstructorArgs($args);
     } else {
         $mockBuilder->disableOriginalConstructor();
     }
     $mock = $mockBuilder->getMock();
     $reflection = new \ReflectionClass($this->className);
     foreach ($this->items as $item) {
         $this->addMethodExpectation($reflection, $mock, $item);
     }
     $mock->expects(TestCase::any())->method('this')->will(TestCase::returnValue(new Reflection($mock)));
     $mock->expects(TestCase::any())->method('mock')->will(TestCase::returnValue(new MockAdjuster($mock, $reflection)));
     foreach ($this->properties as $key => $value) {
         $mock->this()->{$key} = $value;
     }
     return $mock;
 }
示例#2
0
文件: Base.php 项目: ptrofimov/xpmock
 /** @return array */
 protected function parseMockMethodArgs($method, array $args)
 {
     $expects = TestCase::any();
     $with = null;
     $will = TestCase::returnValue(null);
     if (count($args) == 1) {
         if ($args[0] instanceof InvokedRecorder || $args[0] instanceof InvokedAtIndex) {
             $expects = $args[0];
         } else {
             $will = $args[0];
         }
     } elseif (count($args) == 2) {
         if ($args[1] instanceof InvokedRecorder || $args[1] instanceof InvokedAtIndex) {
             if (is_array($args[0])) {
                 list($with, $expects) = $args;
             } else {
                 list($will, $expects) = $args;
             }
         } elseif (is_array($args[0])) {
             list($with, $will) = $args;
         } else {
             throw new \InvalidArgumentException();
         }
     } elseif (count($args) == 3) {
         if (is_array($args[0]) && ($args[2] instanceof InvokedRecorder || $args[2] instanceof InvokedAtIndex)) {
             list($with, $will, $expects) = $args;
         } else {
             throw new \InvalidArgumentException();
         }
     }
     if ($will instanceof \Exception) {
         $will = PhpUnitTestCase::throwException($will);
     } elseif (!$will instanceof Stub && !$will instanceof \Closure && !is_null($will)) {
         $will = PhpUnitTestCase::returnValue($will);
     }
     return array('method' => $method, 'expects' => $expects, 'with' => $with, 'will' => $will);
 }