<commit_before><?php
use LazyRecord\ConfigLoader;
use CLIFramework\Logger;

class SchemaGeneratorTest extends PHPUnit_Framework_TestCase
{
    public function createSchemaGenerator() {
        $g = new \LazyRecord\Schema\SchemaGenerator(ConfigLoader::getInstance(), Logger::getInstance());
        $g->forceUpdate = true;
        return $g;
    }

    public function schemaProvider() {
        $g = $this->createSchemaGenerator();
        $schemas = array();
        $schemas[] = [ $g, new \TestApp\Model\UserSchema ];
        $schemas[] = [ $g, new \AuthorBooks\Model\AddressSchema ];
        $schemas[] = [ $g, new \AuthorBooks\Model\BookSchema ];
        $schemas[] = [ $g, new \TestApp\Model\IDNumberSchema ];
        $schemas[] = [ $g, new \TestApp\Model\NameSchema ];
        return $schemas;
    }


    /**
     * @dataProvider schemaProvider
     */
    public function testBaseCollectionClassGeneration($g, $schema)
    {
        if ( $result = $g->generateBaseCollectionClass($schema) ) {
            list($class, $file) = $result;
            ok($class);
            ok($file);
            path_ok($file);
            $this->syntaxTest($file);
        }
    }

    /**
     * @dataProvider schemaProvider
     */
    public function testCollectionClassGeneration($g, $schema)
    {
        if ( $result = $g->generateCollectionClass($schema) ) {
            list($class, $file) = $result;
            ok($class);
            ok($file);
            path_ok($file);
            $this->syntaxTest($file);
        }
    }

    public function syntaxTest($file) {
        $this->expectOutputRegex('/^No syntax errors detected/' );
        system("php -l $file");
    }


    /**
     * @dataProvider schemaProvider
     */
    public function testGenerateMethod($g, $schema) 
    {
        if ( $classMap = $g->generate(array($schema)) ) {
            ok($classMap);
            foreach( $classMap as $class => $file ) {
                ok($class);
                ok($file);
                path_ok($file,$file);
                // $this->syntaxTest($file);
                require_once $file;
            }
        }

        $pk = $schema->findPrimaryKey();
        ok($pk, "Find primary key from " . get_class($schema) );

        $model = $schema->newModel();
        ok($model);

        $collection = $schema->newCollection();
        ok($collection);
    }

    /**
     * @dataProvider schemaProvider
     */
    public function testSchemaProxyGeneration($g, $schema)
    {
        if ( $result = $g->generateSchemaProxyClass($schema) ) {
            list($class, $file) = $result;
            ok($class);
            ok($file);
            path_ok($file);
            $this->syntaxTest($file);
        }
    }
}
<commit_msg>Fix tests<commit_after><?php
use LazyRecord\ConfigLoader;
use CLIFramework\Logger;

class SchemaGeneratorTest extends PHPUnit_Framework_TestCase
{
    public function createSchemaGenerator() {
        $g = new \LazyRecord\Schema\SchemaGenerator(ConfigLoader::getInstance(), Logger::getInstance());
        $g->forceUpdate = true;
        return $g;
    }

    public function schemaProvider() {
        $g = $this->createSchemaGenerator();
        $schemas = array();
        $schemas[] = [ $g, new \TestApp\Model\UserSchema ];
        $schemas[] = [ $g, new \AuthorBooks\Model\AddressSchema ];
        $schemas[] = [ $g, new \AuthorBooks\Model\BookSchema ];
        $schemas[] = [ $g, new \TestApp\Model\IDNumberSchema ];
        $schemas[] = [ $g, new \TestApp\Model\NameSchema ];
        return $schemas;
    }


    /**
     * @dataProvider schemaProvider
     */
    public function testCollectionClassGeneration($g, $schema)
    {
        if ( $result = $g->generateCollectionClass($schema) ) {
            list($class, $file) = $result;
            ok($class);
            ok($file);
            path_ok($file);
            $this->syntaxTest($file);
        }
    }

    public function syntaxTest($file) {
        $this->expectOutputRegex('/^No syntax errors detected/' );
        system("php -l $file");
    }


    /**
     * @dataProvider schemaProvider
     */
    public function testGenerateMethod($g, $schema) 
    {
        if ( $classMap = $g->generate(array($schema)) ) {
            foreach( $classMap as $class => $file ) {
                ok($class);
                ok($file);
                path_ok($file,$file);
                // $this->syntaxTest($file);
                require_once $file;
            }
        }

        $pk = $schema->findPrimaryKey();
        $this->assertNotNull($pk, "Find primary key from " . get_class($schema) );

        $model = $schema->newModel();
        $this->assertNotNull($model);

        $collection = $schema->newCollection();
        $this->assertNotNull($collection);
    }
}

{'fraction_non_alphanumeric': 0.14981195152528207, 'fraction_numerical': 0.0, 'mean_word_length': 2.0412960609911055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '3825865', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1325, 'n_words': 252}