function testFlickrPeopleGetPublicPhotos() { $outputDirectory = __DIR__ . '/../../var/src'; $apiGenerator = new APIGenerator($outputDirectory, []); $testServiceFilename = __DIR__ . '/../fixtures/testService.php'; $service = (require_once $testServiceFilename); if (is_array($service) == false) { $this->fail("Failed to include `{$testServiceFilename}` cannot process test."); } $apiGenerator->parseAndAddService($service); $operations = $apiGenerator->getOperations(); $this->assertArrayHasKey('overrideURL', $operations); $overrideOperation = $operations['overrideURL']; $this->assertEquals('https://example.com/overrideURL', $overrideOperation->getURL()); }
/** * Add the constructor method for the operation */ private function addConstructorMethod() { $requiredParameters = $this->operationDefinition->getRequiredParams(); $methodGenerator = new MethodGenerator('__construct'); $defaultParams = $this->operationDefinition->getDefaultParams(); $body = ''; if (count($defaultParams)) { $body = '$defaultParams = [' . PHP_EOL; foreach ($defaultParams as $param) { $body .= sprintf(" '%s' => '%s',", $param->getName(), $param->getDefault()); $body .= PHP_EOL; } $body .= '];' . PHP_EOL; $body .= '$this->setParams($defaultParams);' . PHP_EOL; } $constructorParams = []; $constructorParams[] = new ParameterGenerator('api', $this->apiGenerator->getFQCN()); $body .= '$this->api = $api;' . PHP_EOL; foreach ($requiredParameters as $param) { $normalizedParamName = normalizeParamName($param->getName()); $constructorParams[] = new ParameterGenerator($normalizedParamName, $param->getType()); $body .= sprintf("\$this->parameters['%s'] = \$%s;" . PHP_EOL, $param->getName(), $normalizedParamName); } $methodGenerator->setParameters($constructorParams); $methodGenerator->setBody($body); $this->classGenerator->addMethodFromGenerator($methodGenerator); }