Ejemplo n.º 1
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     Repository::setDefaultRepositoryClassName(MySql::class);
     self::SetDefaultConnectionSettings();
     Log::DisableLogging();
     $unitTestingSolutionSchema = new UnitTestingSolutionSchema();
     $unitTestingSolutionSchema->checkModelSchemas();
     // Make sure the test model objects have the any other repository disconnected.
     Model::deleteRepositories();
 }
 public function testRelationships()
 {
     SolutionSchema::clearSchemas();
     SolutionSchema::registerSchema("MySchema", "Rhubarb\\Stem\\Tests\\Fixtures\\UnitTestingSolutionSchema");
     error_reporting(E_ALL);
     ini_set("display_errors", "on");
     $schema = new UnitTestingSolutionSchema();
     $schema->defineRelationships();
     $relationship = $schema->getRelationship("UnitTestUser", "Company");
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToOne", $relationship);
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToMany", $relationship->getOtherSide());
     $relationship = $schema->getRelationship("Company", "Users");
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToMany", $relationship);
     $relationship = $schema->getRelationship("Company", "Unknown");
     $this->assertNull($relationship);
     $relationship = $schema->getRelationship("Example", "ExampleRelationshipName");
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToOne", $relationship);
     $columnRelationships = SolutionSchema::getAllOneToOneRelationshipsForModelBySourceColumnName("UnitTestUser");
     $this->assertArrayHasKey("CompanyID", $columnRelationships);
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToOne", $columnRelationships["CompanyID"]);
     $company = new Company();
     $company->CompanyName = "GCD";
     $company->save();
     $user = new User();
     $user->getRepository()->clearObjectCache();
     $user->Forename = "a";
     $user->save();
     $company->Users->Append($user);
     $b = $user = new User();
     $user->Forename = "b";
     $user->save();
     $company->Users->Append($user);
     // Just to make sure this doesn't get in our relationship!
     $user = new User();
     $user->Forename = "c";
     $user->save();
     $company = new Company($company->CompanyID);
     $this->assertCount(2, $company->Users);
     $this->assertEquals("a", $company->Users[0]->Forename);
     $this->assertEquals("b", $company->Users[1]->Forename);
     $company = $b->Company;
     $this->assertEquals("GCD", $company->CompanyName);
 }