public function testDefaultRepositoryCanBeChanged() { Repository::setDefaultRepositoryClassName("\\Rhubarb\\Stem\\Repositories\\MySql\\MySql"); $repository = Repository::getNewDefaultRepository(new Example()); $this->assertInstanceOf("\\Rhubarb\\Stem\\Repositories\\MySql\\MySql", $repository); // Also check that non extant repositories throw an exception. $this->setExpectedException("\\Rhubarb\\Stem\\Exceptions\\ModelException"); Repository::setDefaultRepositoryClassName("\\Rhubarb\\Stem\\Repositories\\Fictional\\Fictional"); // Reset to the normal so we don't upset other unit tests. Repository::setDefaultRepositoryClassName("\\Rhubarb\\Stem\\Repositories\\Offline\\Offline"); }
public function testSchemaIsModified() { // Note this test relies on the previous test to leave tblExample behind. $schema = new MySqlModelSchema("tblExample"); $schema->addColumn(new AutoIncrement("ID")); $schema->addColumn(new String("Name", 40, "StrangeDefault")); $schema->addColumn(new MySqlEnum("Type", "A", ["A", "B", "C"])); $schema->addColumn(new MySqlEnum("Type", "B", ["A", "B", "C", "D"])); $schema->addColumn(new String("Town", 60, null)); $schema->addIndex(new Index("ID", Index::PRIMARY)); $schema->checkSchema(Repository::getNewDefaultRepository(new Example())); $newSchema = MySqlComparisonSchema::fromTable("tblExample"); $columns = $newSchema->columns; $this->assertCount(4, $columns); $this->assertEquals("`Town` varchar(60) DEFAULT NULL", $columns["Town"]); $this->assertEquals("`Type` enum('A','B','C','D') NOT NULL DEFAULT 'B'", $columns["Type"]); }
/** * Creates the repository appropriate for this object type. * * To be overridden when necessary. * * @throws \Rhubarb\Stem\Exceptions\ModelException * @return \Rhubarb\Stem\Repositories\Repository */ protected function createRepository() { return Repository::getNewDefaultRepository($this); }