<commit_before><?php

require_once (__DIR__."/../../module_system/system/class_testbase.php");

class class_test_orm_schemamanagerTest extends class_testbase {


    public function testSchemamanager() {
        $objDb = class_carrier::getInstance()->getObjDB();

        $objManager = new class_orm_schemamanager();

        $arrTables = $objDb->getTables();
        $this->assertTrue(!in_array(_dbprefix_."ormtest", $arrTables));

        $objManager->createTable("orm_schematest_testclass");
        class_carrier::getInstance()->flushCache(class_carrier::INT_CACHE_TYPE_DBTABLES);

        $arrTables = $objDb->getTables();
        $this->assertTrue(in_array(_dbprefix_."ormtest", $arrTables));

        //fetch table informations
        $arrTable = $objDb->getColumnsOfTable(_dbprefix_."ormtest");

        $arrColumnNamesToDatatype = array();
        array_walk($arrTable, function($arrValue) use (&$arrColumnNamesToDatatype) {
            $arrColumnNamesToDatatype[$arrValue["columnName"]] = $arrValue["columnType"];
        });

        $arrColumnNames = array_map(function($arrValue) {
            return $arrValue["columnName"];
        }, $arrTable);


        $this->assertTrue(in_array("content_id", $arrColumnNames));
        $this->assertTrue(in_array("col1", $arrColumnNames));
        $this->assertTrue(in_array("col2", $arrColumnNames));
        $this->assertTrue(in_array("col3", $arrColumnNames));

        //$this->assertEquals(uniStrtolower($arrColumnNamesToDatatype["content_id"]), uniStrtolower(uniStrReplace(" ", "", $objDb->getDatatype(class_db_datatypes::STR_TYPE_CHAR20))));
        //$this->assertEquals(uniStrtolower($arrColumnNamesToDatatype["col1"]), uniStrtolower(uniStrReplace(" ", "", $objDb->getDatatype(class_db_datatypes::STR_TYPE_CHAR254))));
        //$this->assertEquals(uniStrtolower($arrColumnNamesToDatatype["col2"]), uniStrtolower(uniStrReplace(" ", "", $objDb->getDatatype(class_db_datatypes::STR_TYPE_TEXT))));
        //$this->assertEquals(uniStrtolower($arrColumnNamesToDatatype["col3"]), uniStrtolower(uniStrReplace(" ", "", $objDb->getDatatype(class_db_datatypes::STR_TYPE_LONG))));

        $objDb->_pQuery("DROP TABLE "._dbprefix_."ormtest", array());
        class_carrier::getInstance()->flushCache(class_carrier::INT_CACHE_TYPE_DBTABLES);
    }

    public function testTargetTableException1() {
        $objManager = new class_orm_schemamanager();

        $objEx = null;
        try {
            $objManager->createTable("orm_schematest_testclass_targettable1");
        }
        catch(class_orm_exception $objException) {
            $objEx = $objException;
        }

        $this->assertNotNull($objEx);
        $this->assertTrue(uniStrpos($objEx->getMessage(), "provides no target-table!") !== false);
    }

    public function testTargetTableException2() {
        $objManager = new class_orm_schemamanager();

        $objEx = null;
        try {
            $objManager->createTable("orm_schematest_testclass_targettable2");
        }
        catch(class_orm_exception $objException) {
            $objEx = $objException;
        }

        $this->assertNotNull($objEx);
        $this->assertTrue(uniStrpos($objEx->getMessage(), "is not in table.primaryColumn format") !== false);
    }

    public function testDataTypeException() {
        $objManager = new class_orm_schemamanager();

        $objEx = null;
        try {
            $objManager->createTable("orm_schematest_testclass_datatype");
        }
        catch(class_orm_exception $objException) {
            $objEx = $objException;
        }

        $this->assertNotNull($objEx);
        $this->assertTrue(uniStrpos($objEx->getMessage(), " is unknown (") !== false);
    }

    public function testTableColumnSyntaxException() {
        $objManager = new class_orm_schemamanager();

        $objEx = null;
        try {
            $objManager->createTable("orm_schematest_testclass_tablecolumn");
        }
        catch(class_orm_exception $objException) {
            $objEx = $objException;
        }

        $this->assertNotNull($objEx);
        $this->assertTrue(uniStrpos($objEx->getMessage(), "Syntax for tableColumn annotation at property") !== false);
    }

}

/**
 * Class orm_schematest_testclass
 *
 * @targetTable ormtest.content_id
 */
class orm_schematest_testclass {

    /**
     * @var string
     * @tableColumn ormtest.col1
     */
    private $strCol1 = "";

    /**
     * @var string
     * @tableColumn ormtest.col2
     * @tableColumnDatatype text
     */
    private $strCol2 = "";

    /**
     * @var int
     * @tableColumn ormtest.col3
     * @tableColumnDatatype long
     */
    private $longCol3 = 0;
}

/**
 * Class orm_schematest_testclass
 *
 * @targetTable ormtest.content_id
 */
class orm_schematest_testclass_datatype {

    /**
     * @var int
     * @tableColumn ormtest.col3
     * @tableColumnDatatype extralong
     */
    private $longCol3 = 0;
}

/**
 * Class orm_schematest_testclass
 *
 * @targetTable ormtest.content_id
 * @targetTable ormtest2.content_id
 */
class orm_schematest_testclass_tablecolumn {

    /**
     * @var int
     * @tableColumn ormtestcol3
     * @tableColumnDatatype long
     */
    private $longCol3 = 0;
}


/**
 * Class orm_schematest_testclass
 *
 */
class orm_schematest_testclass_targettable1 {


}

/**
 * Class orm_schematest_testclass
 * @targetTable ormtest
 */
class orm_schematest_testclass_targettable2 {


}

<commit_msg>BUG: module_system | orm test -> moved some table drops to tearDown<commit_after><?php

require_once (__DIR__."/../../module_system/system/class_testbase.php");

class class_test_orm_schemamanagerTest extends class_testbase {


    protected function tearDown() {
        $objDb = class_carrier::getInstance()->getObjDB();
        $objDb->_pQuery("DROP TABLE "._dbprefix_."ormtest", array());
        class_carrier::getInstance()->flushCache(class_carrier::INT_CACHE_TYPE_DBTABLES);
        parent::tearDown(); //
    }


    public function testSchemamanager() {
        $objDb = class_carrier::getInstance()->getObjDB();

        $objManager = new class_orm_schemamanager();

        $arrTables = $objDb->getTables();
        $this->assertTrue(!in_array(_dbprefix_."ormtest", $arrTables));

        $objManager->createTable("orm_schematest_testclass");
        class_carrier::getInstance()->flushCache(class_carrier::INT_CACHE_TYPE_DBTABLES);

        $arrTables = $objDb->getTables();
        $this->assertTrue(in_array(_dbprefix_."ormtest", $arrTables));

        //fetch table informations
        $arrTable = $objDb->getColumnsOfTable(_dbprefix_."ormtest");

        $arrColumnNamesToDatatype = array();
        array_walk($arrTable, function($arrValue) use (&$arrColumnNamesToDatatype) {
            $arrColumnNamesToDatatype[$arrValue["columnName"]] = $arrValue["columnType"];
        });

        $arrColumnNames = array_map(function($arrValue) {
            return $arrValue["columnName"];
        }, $arrTable);


        $this->assertTrue(in_array("content_id", $arrColumnNames));
        $this->assertTrue(in_array("col1", $arrColumnNames));
        $this->assertTrue(in_array("col2", $arrColumnNames));
        $this->assertTrue(in_array("col3", $arrColumnNames));

    }

    public function testTargetTableException1() {
        $objManager = new class_orm_schemamanager();

        $objEx = null;
        try {
            $objManager->createTable("orm_schematest_testclass_targettable1");
        }
        catch(class_orm_exception $objException) {
            $objEx = $objException;
        }

        $this->assertNotNull($objEx);
        $this->assertTrue(uniStrpos($objEx->getMessage(), "provides no target-table!") !== false);
    }

    public function testTargetTableException2() {
        $objManager = new class_orm_schemamanager();

        $objEx = null;
        try {
            $objManager->createTable("orm_schematest_testclass_targettable2");
        }
        catch(class_orm_exception $objException) {
            $objEx = $objException;
        }

        $this->assertNotNull($objEx);
        $this->assertTrue(uniStrpos($objEx->getMessage(), "is not in table.primaryColumn format") !== false);
    }

    public function testDataTypeException() {
        $objManager = new class_orm_schemamanager();

        $objEx = null;
        try {
            $objManager->createTable("orm_schematest_testclass_datatype");
        }
        catch(class_orm_exception $objException) {
            $objEx = $objException;
        }

        $this->assertNotNull($objEx);
        $this->assertTrue(uniStrpos($objEx->getMessage(), " is unknown (") !== false);
    }

    public function testTableColumnSyntaxException() {
        $objManager = new class_orm_schemamanager();

        $objEx = null;
        try {
            $objManager->createTable("orm_schematest_testclass_tablecolumn");
        }
        catch(class_orm_exception $objException) {
            $objEx = $objException;
        }

        $this->assertNotNull($objEx);
        $this->assertTrue(uniStrpos($objEx->getMessage(), "Syntax for tableColumn annotation at property") !== false);
    }

}

/**
 * Class orm_schematest_testclass
 *
 * @targetTable ormtest.content_id
 */
class orm_schematest_testclass {

    /**
     * @var string
     * @tableColumn ormtest.col1
     */
    private $strCol1 = "";

    /**
     * @var string
     * @tableColumn ormtest.col2
     * @tableColumnDatatype text
     */
    private $strCol2 = "";

    /**
     * @var int
     * @tableColumn ormtest.col3
     * @tableColumnDatatype long
     */
    private $longCol3 = 0;
}

/**
 * Class orm_schematest_testclass
 *
 * @targetTable ormtest.content_id
 */
class orm_schematest_testclass_datatype {

    /**
     * @var int
     * @tableColumn ormtest.col3
     * @tableColumnDatatype extralong
     */
    private $longCol3 = 0;
}

/**
 * Class orm_schematest_testclass
 *
 * @targetTable ormtest.content_id
 * @targetTable ormtest2.content_id
 */
class orm_schematest_testclass_tablecolumn {

    /**
     * @var int
     * @tableColumn ormtestcol3
     * @tableColumnDatatype long
     */
    private $longCol3 = 0;
}


/**
 * Class orm_schematest_testclass
 *
 */
class orm_schematest_testclass_targettable1 {


}

/**
 * Class orm_schematest_testclass
 * @targetTable ormtest
 */
class orm_schematest_testclass_targettable2 {


}


{'fraction_non_alphanumeric': 0.1329345938645572, 'fraction_numerical': 0.0052093382211074665, 'mean_word_length': 3.1352213801356204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2974316', 'n_tokens_mistral': 3253, 'n_tokens_neox': 3182, 'n_words': 449}