<commit_before><?php
/*
 * Fusio
 * A web-application to create dynamically RESTful APIs
 *
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace Fusio\Database;

use Fusio\Base;
use Fusio\DbTestCase;

/**
 * InstallerTest
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://www.gnu.org/licenses/agpl-3.0
 * @link    http://fusio-project.org
 */
class InstallerTest extends DbTestCase
{
    /**
     * Checks whether we have an database version
     */
    public function testVersion()
    {
        $this->assertInstanceOf('Fusio\Database\VersionInterface', Installer::getVersion(Base::getVersion()), 'No database version class was provided');
    }

    /**
     * Checks whether this version is in the upgrade path
     */
    public function testUpgradePath()
    {
        $installer = new Installer($this->connection);
        $path      = $installer->getUpgradePath();

        $this->assertEquals(Base::getVersion(), current($path), 'The current version must be in the upgrade path');
    }
}<commit_msg>add installer test case<commit_after><?php
/*
 * Fusio
 * A web-application to create dynamically RESTful APIs
 *
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace Fusio\Database;

use Fusio\Base;
use Fusio\DbTestCase;

/**
 * InstallerTest
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://www.gnu.org/licenses/agpl-3.0
 * @link    http://fusio-project.org
 */
class InstallerTest extends DbTestCase
{
    /**
     * Checks whether we have an database version
     */
    public function testVersion()
    {
        $this->assertInstanceOf('Fusio\Database\VersionInterface', Installer::getVersion(Base::getVersion()), 'No database version class was provided');
    }

    /**
     * Checks whether this version is in the upgrade path
     */
    public function testUpgradePath()
    {
        $installer = new Installer($this->connection);
        $path      = $installer->getUpgradePath();

        $this->assertEquals(Base::getVersion(), current($path), 'The current version must be in the upgrade path');
    }

    /**
     * Run the installation script to check whether an installation works 
     * without errors
     */
    public function testInstall()
    {
        // create a copy of the current schema
        $sm       = $this->connection->getSchemaManager();
        $toSchema = $sm->createSchema();

        $this->removeAllTables();

        // execute the installer
        $installer = new Installer($this->connection);
        $installer->install(Base::getVersion());

        // @TODO make checks to verify that the installation works

        $this->removeAllTables();

        // restore the schema
        $fromSchema = $sm->createSchema();
        $queries    = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());

        foreach ($queries as $sql) {
            $this->connection->executeUpdate($sql);
        }
    }

    protected function removeAllTables()
    {
        $sm         = $this->connection->getSchemaManager();
        $fromSchema = $sm->createSchema();
        $toSchema   = clone $fromSchema;

        foreach ($fromSchema->getTables() as $table) {
            $toSchema->dropTable($table->getName());
        }

        $queries = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());

        foreach ($queries as $sql) {
            $this->connection->executeUpdate($sql);
        }
    }
}

{'fraction_non_alphanumeric': 0.11240474174428451, 'fraction_numerical': 0.0029635901778154107, 'mean_word_length': 2.95066889632107, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1871090', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1261, 'n_words': 437}