/**
  * @dataProvider resourceProvider
  */
 public function testRessources(SplFileInfo $testDirectory)
 {
     // 1. Cleanup generated
     $filesystem = new Filesystem();
     if ($filesystem->exists($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated')) {
         $filesystem->remove($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     }
     $filesystem->mkdir($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     // 2. Generate
     $OpenApi = JaneOpenApi::build();
     $files = $OpenApi->generate($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'swagger.json', 'Joli\\Jane\\OpenApi\\Tests\\Expected', $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     $OpenApi->printFiles($files, $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     // 3. Compare
     $expectedFinder = new Finder();
     $expectedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'expected');
     $generatedFinder = new Finder();
     $generatedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     $generatedData = [];
     $this->assertEquals(count($expectedFinder), count($generatedFinder));
     foreach ($generatedFinder as $generatedFile) {
         $generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath();
     }
     foreach ($expectedFinder as $expectedFile) {
         $this->assertArrayHasKey($expectedFile->getRelativePathname(), $generatedData);
         if ($expectedFile->isFile()) {
             $this->assertEquals(file_get_contents($expectedFile->getRealPath()), file_get_contents($generatedData[$expectedFile->getRelativePathname()]));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $openApiSchemaFile = $input->getArgument('openapi-file');
     $namespace = $input->getArgument('namespace');
     $generateDirectory = $input->getArgument('directory');
     $janeOpenApi = JaneOpenApi::build();
     $files = $janeOpenApi->generate($openApiSchemaFile, $namespace, $generateDirectory);
     $janeOpenApi->printFiles($files, $generateDirectory);
     foreach ($files as $file) {
         $output->writeln(sprintf("Generate %s", $file->getFilename()));
     }
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $options = [];
     if ($input->hasOption('config-file')) {
         $configFile = $input->getOption('config-file');
         if (!file_exists($configFile)) {
             throw new \RuntimeException(sprintf('Config file %s does not exist', $configFile));
         }
         $options = (require $configFile);
         if (!is_array($options)) {
             throw new \RuntimeException(sprintf('Invalid config file specified or invalid return type in file %s', $configFile));
         }
     } else {
         if ($input->hasArgument('openapi-file') && null !== $input->getArgument('openapi-file')) {
             $options['openapi-file'] = $input->getArgument('openapi-file');
         }
         if ($input->hasArgument('namespace') && null !== $input->getArgument('namespace')) {
             $options['namespace'] = $input->getArgument('namespace');
         }
         if ($input->hasArgument('directory') && null !== $input->getArgument('directory')) {
             $options['directory'] = $input->getArgument('directory');
         }
         if ($input->hasOption('date-format') && null !== $input->getOption('date-format')) {
             $options['date-format'] = $input->getOption('date-format');
         }
         if ($input->hasOption('no-reference') && null !== $input->getOption('no-reference')) {
             $options['reference'] = $input->getOption('reference');
         }
     }
     $options = $this->resolveConfiguration($options);
     $janeOpenApi = JaneOpenApi::build($options);
     $files = $janeOpenApi->generate($options['openapi-file'], $options['namespace'], $options['directory']);
     $janeOpenApi->printFiles($files, $options['directory']);
     foreach ($files as $file) {
         $output->writeln(sprintf("Generate %s", $file->getFilename()));
     }
 }