Exemplo n.º 1
0
 public function testUnguessableRelation()
 {
     $pid = self::$person->id;
     // Asset is similar to contact, but has a non-guessable foreign key name
     // (owner_id)
     $a1 = Asset::fromArray(['owner_id' => $pid, "value" => "Asset #1"]);
     $a2 = Asset::fromArray(['owner_id' => $pid, "value" => "Asset #2"]);
     $a3 = Asset::fromArray(['owner_id' => $pid, "value" => "Asset #3"]);
     $a1->save();
     $a2->save();
     $a3->save();
     $assets = self::$person->hasChildren("Phormium\\Tests\\Models\\Asset", "owner_id");
     $this->assertInstanceOf("Phormium\\QuerySet", $assets);
     $actual = $assets->fetch();
     $expected = [$a1, $a2, $a3];
     $this->assertEquals($expected, $actual);
     $p1 = $a1->hasParent("Phormium\\Tests\\Models\\Person", "owner_id")->single();
     $p2 = $a2->hasParent("Phormium\\Tests\\Models\\Person", "owner_id")->single();
     $p3 = $a3->hasParent("Phormium\\Tests\\Models\\Person", "owner_id")->single();
     $this->assertEquals(self::$person, $p1);
     $this->assertEquals(self::$person, $p2);
     $this->assertEquals(self::$person, $p3);
 }
Exemplo n.º 2
0
 public function testAll()
 {
     Contact::objects()->delete();
     Asset::objects()->delete();
     Person::objects()->delete();
     $actual = Person::all();
     $this->assertInternalType('array', $actual);
     $this->assertEmpty($actual);
     Person::fromArray(array('name' => "Freddy Mercury"))->insert();
     Person::fromArray(array('name' => "Brian May"))->insert();
     Person::fromArray(array('name' => "Roger Taylor"))->insert();
     $actual = Person::all();
     $this->assertInternalType('array', $actual);
     $this->assertCount(3, $actual);
 }