protected function setUp()
 {
     $this->originalRefClass = $refClass = new \ReflectionClass(self::STUB_CLASS);
     $fileName = $refClass->getFileName();
     $fileNode = ReflectionEngine::parseFile($fileName);
     $reflectionFile = new ReflectionFile($fileName, $fileNode);
     $parsedClass = $reflectionFile->getFileNamespace($refClass->getNamespaceName())->getClass($refClass->getName());
     $this->parsedRefClass = $parsedClass;
 }
 protected function setUp()
 {
     $fileName = stream_resolve_include_path(__DIR__ . self::STUB_FILE);
     $fileNode = ReflectionEngine::parseFile($fileName);
     $reflectionFile = new ReflectionFile($fileName, $fileNode);
     $parsedFileNamespace = $reflectionFile->getFileNamespace('Go\\ParserReflection\\Stub');
     $this->parsedRefFileNamespace = $parsedFileNamespace;
     include_once $fileName;
 }
Exemplo n.º 3
0
 protected function setUp()
 {
     $container = $this->getMock(AspectContainer::class);
     $reader = $this->getMock(Reader::class);
     $loader = $this->getMock(AspectLoader::class, [], array($container, $reader));
     $this->adviceMatcher = new AdviceMatcher($loader, $container);
     $reflectionFile = new ReflectionFile(__FILE__);
     $this->reflectionClass = $reflectionFile->getFileNamespace(__NAMESPACE__)->getClass(__CLASS__);
 }
 /**
  * @dataProvider listOfDefaultGetters
  *
  * @param string $getterName Name of the getter to call
  */
 public function testGetDefaultValueThrowsAnException($getterName)
 {
     $originalException = null;
     $parsedException = null;
     try {
         $originalRefParameter = new \ReflectionParameter('Go\\ParserReflection\\Stub\\miscParameters', 'arrayParam');
         $originalRefParameter->{$getterName}();
     } catch (\ReflectionException $e) {
         $originalException = $e;
     }
     try {
         $parsedNamespace = $this->parsedRefFile->getFileNamespace('Go\\ParserReflection\\Stub');
         $parsedFunction = $parsedNamespace->getFunction('miscParameters');
         $parsedRefParameters = $parsedFunction->getParameters();
         $parsedRefParameter = $parsedRefParameters[0];
         $parsedRefParameter->{$getterName}();
     } catch (\ReflectionException $e) {
         $parsedException = $e;
     }
     $this->assertInstanceOf(\ReflectionException::class, $originalException);
     $this->assertInstanceOf(\ReflectionException::class, $parsedException);
     $this->assertSame($originalException->getMessage(), $parsedException->getMessage());
 }
Exemplo n.º 5
0
 private function buildClass($replacement)
 {
     $type = $this->splitNsandClass($replacement['originalFullyQualifiedType']);
     $class = new ClassGenerator();
     $class->setName($type['class']);
     $class->setNamespaceName($type['ns']);
     $class->setExtendedClass('\\Brads\\Ppm\\Proxy');
     $properties = [];
     $methods = [];
     $implementedInterfaces = [];
     foreach ($versions as $version => $info) {
         foreach ($info['files'] as $file) {
             echo "Parsing: " . $this->vendorDir . '/' . $package . '/' . $version . '/' . $file . "\n";
             $parsedFile = new ReflectionFile($this->vendorDir . '/' . $package . '/' . $version . '/' . $file);
             $parsedClass = $parsedFile->getFileNamespace($info['toNs'])->getClass($info['toNs'] . '\\' . $type['class']);
             if ($parsedClass->getInterfaceNames() != null) {
                 $implementedInterfaces = array_merge($implementedInterfaces, $parsedClass->getInterfaceNames());
             }
             foreach ($parsedClass->getMethods() as $method) {
                 if ($method->isPublic()) {
                     $generatedMethod = new MethodGenerator();
                     $generatedMethod->setName($method->name);
                     $generatedMethod->setBody('echo "Hello world!";');
                     $generatedMethod->setAbstract($method->isAbstract());
                     $generatedMethod->setFinal($method->isFinal());
                     $generatedMethod->setStatic($method->isStatic());
                     $generatedMethod->setVisibility(MethodGenerator::VISIBILITY_PUBLIC);
                     foreach ($method->getParameters() as $param) {
                         $generatedParam = new ParameterGenerator();
                         $generatedParam->setName($param->name);
                         if ($param->hasType()) {
                             $generatedParam->setType($param->getType());
                         }
                         //$generatedParam->setDefaultValue($param->getDefaultValue());
                         $generatedParam->setPosition($param->getPosition());
                         $generatedParam->setVariadic($param->isVariadic());
                         $generatedParam->setPassedByReference($param->isPassedByReference());
                         $generatedMethod->setParameter($generatedParam);
                     }
                     $existingMethod = Linq::from($methods)->firstOrDefault(null, function (MethodGenerator $v) use($method) {
                         return $v->getName() == $method->name;
                     });
                     if ($existingMethod != null) {
                         $existingParams = $existingMethod->getParameters();
                         foreach ($generatedMethod->getParameters() as $newParam) {
                             $existingParam = Linq::from($existingParams)->firstOrDefault(function (ParameterGenerator $v) {
                                 return $v->getName() == $newParam->getName();
                             });
                             if ($existingParam == null) {
                                 $existingMethod->setParameter($newParam);
                             }
                         }
                     } else {
                         $methods[] = $generatedMethod;
                     }
                 }
             }
             foreach ($parsedClass->getProperties() as $prop) {
                 //$properties[] = PropertyGenerator::fromReflection($prop);
             }
         }
     }
     $class->setImplementedInterfaces($implementedInterfaces);
     $class->addMethods($methods);
     $class->addProperties($properties);
     return (new FileGenerator(['classes' => [$class]]))->generate();
 }
 /**
  * Tests specific features of PHP5.6 and newer, for example, array constants, etc
  */
 public function testGettersPHP56()
 {
     if (PHP_VERSION_ID < 50600) {
         $this->markTestSkipped("Can not test new features on old version of PHP");
     }
     $fileName = stream_resolve_include_path(__DIR__ . self::STUB_FILE56);
     $fileNode = ReflectionEngine::parseFile($fileName);
     $reflectionFile = new ReflectionFile($fileName, $fileNode);
     include_once $fileName;
     $parsedFileNamespace = $reflectionFile->getFileNamespace('Go\\ParserReflection\\Stub');
     foreach ($parsedFileNamespace->getClasses() as $parsedRefClass) {
         $this->performGeneralMethodComparison($parsedRefClass);
     }
 }