/** * @dataProvider schemaProvider */ 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 $jane = Jane::build(); $jane->generate($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'schema.json', 'Test', 'Joli\\Jane\\Tests\\Expected', $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) { $jsonSchemaFilepath = $input->getArgument('json-schema-file'); $rootClassname = $input->getArgument('root-class'); $namespace = $input->getArgument('namespace'); $generateDirectory = $input->getArgument('directory'); $jane = \Joli\Jane\Jane::build(); $files = $jane->generate($jsonSchemaFilepath, $rootClassname, $namespace, $generateDirectory); foreach ($files as $file) { $output->writeln(sprintf("Generated %s", $file)); } }
/** * {@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('json-schema-file') && null !== $input->getArgument('json-schema-file')) { $options['json-schema-file'] = $input->getArgument('json-schema-file'); } if ($input->hasArgument('root-class') && null !== $input->getArgument('root-class')) { $options['root-class'] = $input->getArgument('root-class'); } if ($input->hasArgument('directory') && null !== $input->getArgument('directory')) { $options['directory'] = $input->getArgument('directory'); } if ($input->hasArgument('namespace') && null !== $input->getArgument('namespace')) { $options['namespace'] = $input->getArgument('namespace'); } 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('no-reference'); } } $options = $this->resolveConfiguration($options); $jane = \Joli\Jane\Jane::build($options); $files = $jane->generate($options['json-schema-file'], $options['root-class'], $options['namespace'], $options['directory']); foreach ($files as $file) { $output->writeln(sprintf("Generated %s", $file)); } }
public function setUp() { $this->jane = Jane::build(); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; $jane = \Joli\Jane\Jane::build(); $jane->generate(__DIR__ . '/../swagger-spec.json', 'Swagger', 'Joli\\Jane\\Swagger', __DIR__ . '/../generated');