LazyRecord\Testing\ModelTestCase::setUp PHP Method

setUp() public method

public setUp ( )
    public function setUp()
    {
        if ($this->onlyDriver !== null && $this->getDataSource() != $this->onlyDriver) {
            return $this->markTestSkipped("{$this->onlyDriver} only");
        }
        $this->prepareConnection();
        // Ensure that we use the correct default data source ID
        $this->assertEquals($this->getDataSource(), $this->config->getDefaultDataSourceId());
        $this->assertInstanceOf('SQLBuilder\\Driver\\BaseDriver', $this->queryDriver, 'QueryDriver object OK');
        // Rebuild means rebuild the database for new tests
        $annnotations = $this->getAnnotations();
        $rebuild = true;
        $basedata = true;
        if (isset($annnotations['method']['rebuild'][0]) && $annnotations['method']['rebuild'][0] == 'false') {
            $rebuild = false;
        }
        if (isset($annnotations['method']['basedata'][0]) && $annnotations['method']['basedata'][0] == 'false') {
            $basedata = false;
        }
        $schemas = ClassUtils::schema_classes_to_objects($this->getModels());
        if (false === $this->schemaHasBeenBuilt) {
            $g = new SchemaGenerator($this->config);
            $g->setForceUpdate(true);
            $g->generate($schemas);
            $this->schemaHasBeenBuilt = true;
        }
        if ($rebuild === false) {
            $tableParser = TableParser::create($this->conn, $this->queryDriver, $this->config);
            $tables = $tableParser->getTables();
            $schemas = array_filter($schemas, function ($schema) use($tables) {
                return !in_array($schema->getTable(), $tables);
            });
        }
        $this->sqlBuilder = SqlBuilder::create($this->queryDriver, array('rebuild' => $rebuild));
        $this->bootstrap = new Bootstrap($this->conn, $this->sqlBuilder, $this->logger);
        $this->bootstrap->build($schemas);
        if ($rebuild && $basedata) {
            $seeder = new SeedBuilder($this->logger);
            $seeder->build(new SchemaCollection($schemas));
            $seeder->buildConfigSeeds($this->config);
        }
    }

Usage Example

Example #1
0
 public function setUp()
 {
     parent::setUp();
     $records = new ProductCollection();
     $records->delete();
     $records = new ProductImageCollection();
     $records->delete();
 }
All Usage Examples Of LazyRecord\Testing\ModelTestCase::setUp