public function testGenerate() { $twigProphecy = $this->prophesize('Twig_Environment'); $classes = $this->getClasses(); foreach ($classes as $class) { $twigProphecy->render('class.php.twig', Argument::that($this->getContextMatcher($class)))->willReturn()->shouldBeCalled(); } $twigProphecy->render('class.php.twig', Argument::type('array'))->willReturn(); $twig = $twigProphecy->reveal(); $cardinalitiesExtractorProphecy = $this->prophesize('ApiPlatform\\SchemaGenerator\\CardinalitiesExtractor'); $cardinalities = $this->getCardinalities(); $cardinalitiesExtractorProphecy->extract()->willReturn($cardinalities)->shouldBeCalled(); $cardinalitiesExtractor = $cardinalitiesExtractorProphecy->reveal(); $goodRelationsBridgeProphecy = $this->prophesize('ApiPlatform\\SchemaGenerator\\GoodRelationsBridge'); $goodRelationsBridge = $goodRelationsBridgeProphecy->reveal(); $typesGenerator = new TypesGenerator($twig, new NullLogger(), $this->getGraphs(), $cardinalitiesExtractor, $goodRelationsBridge); $typesGenerator->generate($this->getConfig()); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $configArgument = $input->getArgument('config'); if ($configArgument) { $parser = new Parser(); $config = $parser->parse(file_get_contents($configArgument)); unset($parser); } else { $config = []; } $processor = new Processor(); $configuration = new TypesGeneratorConfiguration(); $processedConfiguration = $processor->processConfiguration($configuration, [$config]); $processedConfiguration['output'] = realpath($input->getArgument('output')); if (!$processedConfiguration['output']) { throw new \RuntimeException('The specified output is invalid'); } $graphs = []; foreach ($processedConfiguration['rdfa'] as $rdfa) { $graph = new \EasyRdf_Graph(); if ('http://' === substr($rdfa['uri'], 0, 7) || 'https://' === substr($rdfa['uri'], 0, 8)) { $graph->load($rdfa['uri'], $rdfa['format']); } else { $graph->parseFile($rdfa['uri'], $rdfa['format']); } $graphs[] = $graph; } $relations = []; foreach ($processedConfiguration['relations'] as $relation) { $relations[] = new \SimpleXMLElement($relation, 0, true); } $goodRelationsBridge = new GoodRelationsBridge($relations); $cardinalitiesExtractor = new CardinalitiesExtractor($graphs, $goodRelationsBridge); $ucfirstFilter = new \Twig_SimpleFilter('ucfirst', 'ucfirst'); $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../templates/'); $twig = new \Twig_Environment($loader, ['autoescape' => false, 'debug' => $processedConfiguration['debug']]); $twig->addFilter($ucfirstFilter); if ($processedConfiguration['debug']) { $twig->addExtension(new \Twig_Extension_Debug()); } $logger = new ConsoleLogger($output); $entitiesGenerator = new TypesGenerator($twig, $logger, $graphs, $cardinalitiesExtractor, $goodRelationsBridge); $entitiesGenerator->generate($processedConfiguration); }