Example #1
0
 public function testWriter()
 {
     // -------------------------------------------------------------------------------------------------------------
     // Generate the SQLite database.
     // -------------------------------------------------------------------------------------------------------------
     $config = $this->__generalConfiguration['application'];
     Writer::writer($config);
     // -------------------------------------------------------------------------------------------------------------
     // Open the SQLite database.
     // -------------------------------------------------------------------------------------------------------------
     $dbSqlitePath = $config[DocOption::DOC_PATH];
     $this->__pathSQLite = $dbSqlitePath;
     if (!file_exists($dbSqlitePath)) {
         throw new \Exception("Path to the SQLite database does not exist: {$dbSqlitePath}.");
     }
     print "Opening SQLite database:" . $dbSqlitePath;
     try {
         $this->__pdoSQLite = new \PDO("sqlite:{$dbSqlitePath}");
         $this->__pdoSQLite->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
         $this->__pdoSQLite->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         // ERRMODE_WARNING | ERRMODE_EXCEPTION | ERRMODE_SILENT
     } catch (\Exception $e) {
         throw new \Exception("Can not open the SQLite database \"{$dbSqlitePath}\" : " . $e->getMessage());
     }
     // -------------------------------------------------------------------------------------------------------------
     // Check all elements.
     // -------------------------------------------------------------------------------------------------------------
     $expectedFieldsList = [];
     $expectedTablesList = [];
     foreach ($this->__expectedLinkTablesFields as $_table => $_fields) {
         $expectedFieldsList = array_merge($_fields, $expectedFieldsList);
         $expectedTablesList[] = $_table;
     }
     $this->assertEquals(true, $this->__cmp($this->__getTables(), $expectedTablesList));
     $this->assertEquals(true, $this->__cmp($this->__getFields(), $expectedFieldsList));
     $this->assertEquals(true, $this->__cmp($this->__getTags(), [Tags::AUTHENTICATION, Tags::ADMIN]));
     $this->assertEquals(true, $this->__cmp($this->__getEntities(), [Entities::USER, Entities::USER_PROFILE]));
     $this->assertEquals(true, $this->__cmp($this->__getActions(), [Actions::SELECT, Actions::DELETE, Actions::UPDATE, Actions::AUTHENTICATE, Actions::CREATE, Actions::UPSERT]));
     $this->assertEquals(true, $this->__cmp($this->__getRequests(), ['User/Authenticate', 'User/Delete', 'User/Update', 'User/Insert', 'Profile/Get', 'User/Upsert', 'User/Select']));
     $this->assertEquals(true, $this->__cmp($this->__getProcedures(), ['User/Authenticate', 'User/Delete']));
     // -------------------------------------------------------------------------------------------------------------
     // Load the data from the SQLite database and compare it to the expected values.
     // -------------------------------------------------------------------------------------------------------------
     $linkTablesFields = $this->__getLinksTablesFields();
     $linkRequestsSelectedFields = $this->__getLinksRequestsSelectedFields();
     $linkRequestUpdatedFields = $this->__getLinksRequestsUpdatedFields();
     $linkRequestInsertedFields = $this->__getLinksRequestsInsertedFields();
     $linkRequestUpsertedFields = $this->__getLinksRequestsUpsertedFields();
     $linkRequestConditionFields = $this->__getLinksRequestsConditionFields();
     $linkRequestParameters = $this->__getLinksRequestsParameterValues();
     $linkRequestRepresentationFields = $this->__getLinksRequestsRepresentationFields();
     $linkRequestTags = $this->__getLinksRequestsTags();
     $linksRequestsEntitiesActions = $this->__getLinksRequestEntitiesActions();
     $listingRequestOutputValues = $this->__getListingRequestsOutputValues();
     $linkProcedureTags = $this->__getLinksProcedureTags();
     $linkProcedureRequests = $this->__getLinksProcedureRequests();
     $linkProcedureEntitiesActions = $this->__getLinksProcedureEntitiesActions();
     $linkProcedureInputFields = $this->__getLinksProcedureInputFields();
     $linkProcedureOutputFields = $this->__getLinksProcedureOutputFields();
     $listingProcedureInputParams = $this->__getListingProcedureInputParams();
     $listingProcedureOutputDataValues = $this->__getListingProcedureOutputDataValues();
     $listingProcedureOutputValues = $this->__getListingProcedureOutputValues();
     // -------------------------------------------------------------------------------------------------------------
     // Load data from the SQLite database.
     // -------------------------------------------------------------------------------------------------------------
     $flatter = function ($v) {
         return [$v['entity'], $v['action']];
     };
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkTablesFields), $linkTablesFields));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkRequestsSelectedFields), $linkRequestsSelectedFields));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkRequestsUpdatedFields), $linkRequestUpdatedFields));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkRequestsInsertedFields), $linkRequestInsertedFields));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkRequestsUpsertedFields), $linkRequestUpsertedFields));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkRequestsConditionFields), $linkRequestConditionFields));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedListingRequestParameters), $linkRequestParameters));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkRequestsRepresentationFields), $linkRequestRepresentationFields));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkRequestsTags), $linkRequestTags));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkRequestsEntitiesActions, $flatter), $linksRequestsEntitiesActions));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedListingRequestOutputValues), $listingRequestOutputValues));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkProceduresTags), $linkProcedureTags));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkProceduresRequests), $linkProcedureRequests));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkProceduresEntitiesActions, $flatter), $linkProcedureEntitiesActions));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkProceduresInputFields), $linkProcedureInputFields));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedLinkProceduresOutputFields), $linkProcedureOutputFields));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedListingProceduresInputParams), $listingProcedureInputParams));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedListingProceduresOutputDataValues), $listingProcedureOutputDataValues));
     $this->assertEquals(true, $this->__cmp($this->__expectedFlat($this->__expectedListingProceduresOutputValues), $listingProcedureOutputValues));
 }
Example #2
0
 /**
  * This method is called by the Symfony's console class.
  * It executes the (specific: MySql, PostgreSql...) CLI adapter.
  * @see Symfony\Component\Console\Command\Command
  * @param InputInterface $input Input interface.
  * @param OutputInterface $output Output interface.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Load the configuration from a file, if required.
     $configLoaderClass = $input->getOption(CliOption::CONFIG_LOADER_CLASS_NAME);
     $genericOptions = [];
     // Not required in PHP... but is sucks otherwise.
     if (!is_null($configLoaderClass)) {
         /** @var \dbeurive\Backend\Cli\InterfaceConfigLoader $loader */
         $loader = new $configLoaderClass();
         $genericOptions = $loader->load();
     } else {
         // The following options contains data used to use the API's entry points.
         $genericOptions = [DocOption::SCHEMA_PATH => $input->getOption(DocOption::SCHEMA_PATH), DocOption::DOC_PATH => $input->getOption(DocOption::DOC_PATH), EntryPointOption::SQL_BASE_NS => $input->getOption(EntryPointOption::SQL_BASE_NS), EntryPointOption::PROC_BASE_NS => $input->getOption(EntryPointOption::PROC_BASE_NS), EntryPointOption::SQL_REPO_PATH => $input->getOption(EntryPointOption::SQL_REPO_PATH), EntryPointOption::PROC_REPO_PATH => $input->getOption(EntryPointOption::PROC_REPO_PATH)];
     }
     // Check the configuration.
     //   1. The configuration for the specific CLI adapter (MySql...) that will be used to extract the database' structure.
     //   2. The configuration for the documentation's builder (Writer).
     $status = Writer::checkConfiguration($genericOptions);
     if (count($status) > 0) {
         CliWriter::echoError(implode("\n", $status));
         return false;
     }
     // Execute the doc builder.
     Writer::writer($genericOptions);
 }