/** * @staticvar int $nesting * @param Cogen\Reflection\ReflectionMethod $method * @param string $instanceVariable * @param Cogen\Code $code * @param bool $return * @return Cogen\ClassUnit\ParamsCall */ public function generateTestMethodCall(ReflectionMethod $method, $instanceVariable, Code $code, $return = false) { static $nesting = 0, $cache = array(); $call = new ParamsCall($method, $code); $call->setInstanceVariable($instanceVariable); if (!$return) { $code->append($call); } $nesting++; if ($nesting >= $this->getDesiredNesting()) { $nesting--; return $call; } $mock = array(); /** foreach($method->detectPropertyMocks() as $className => $methodNames) { $varName = ReflectionClass::getForClass($className)->getInstanceVariable(); $mock[] = "$varName = \$this->getMockBuilder('$className')->disableOriginalConstructor()->getMock();"; foreach ($methodNames as $methodName) { $refl = new ReflectionMethod($className, $methodName); $mock[] = "{$varName}->expects(\$this->any())->method('$methodName')->will( \$this->returnCallback(function({$refl->getParametersString()}) { return null; }));"; } } var_dump($mock); //die("Stopped at " . __FILE__ . ':' . __LINE__); */ if ($method->hasValidReturnType()) { $returnTypeReflection = $method->getReturnTypeReflection(); $resultVariable = $call->getResultVariable(); if ($method->isArrayReturn()) { $lines = array(); $lines[] = "foreach({$resultVariable}Collection as {$resultVariable}Item) {"; $lines[] = "\t/** @var {$resultVariable}Item {$method->getReturnType()} */"; $lines[] = "\t//\$this->assertEquals(...);"; $lines[] = "}"; $code->assert($lines); } foreach ($returnTypeReflection->getPublicProperties() as $property) { /* @var $property ReflectionProperty */ $expectedName = '$expected' . ucfirst($property->getName()); $code->expect("{$expectedName} = null;"); $code->assert("\$this->assertEquals({$expectedName}, {$resultVariable}->{$property->getName()});"); } $this->generateGetters($resultVariable, $returnTypeReflection, $code); } if (1 == $nesting) { $this->generateGetters($instanceVariable, $this->class, $code); } $nesting--; return $call; }
public function getProperties($filter = -1, $_ = null) { if (!empty($this->properties)) { return $this->properties; } $origReflection = new \ReflectionMethod('ReflectionClass', 'getProperties'); foreach ($origReflection->invoke($this) as $property) { /* @var $property ReflectionProperty */ $this->properties[$property->getName()] = new ReflectionProperty($this->getName(), $property->getName()); } return $this->properties; }