public function testGuessableRelation() { $pid = self::$person->id; // Contacts are linked to person via a guessable foreign key name // (person_id) $c1 = Contact::fromArray(['person_id' => $pid, "value" => "Contact #1"]); $c2 = Contact::fromArray(['person_id' => $pid, "value" => "Contact #2"]); $c3 = Contact::fromArray(['person_id' => $pid, "value" => "Contact #3"]); $c1->save(); $c2->save(); $c3->save(); $contacts = self::$person->hasChildren("Phormium\\Tests\\Models\\Contact"); $this->assertInstanceOf("Phormium\\QuerySet", $contacts); $actual = $contacts->fetch(); $expected = [$c1, $c2, $c3]; $this->assertEquals($expected, $actual); $p1 = $c1->hasParent("Phormium\\Tests\\Models\\Person")->single(); $p2 = $c2->hasParent("Phormium\\Tests\\Models\\Person")->single(); $p3 = $c3->hasParent("Phormium\\Tests\\Models\\Person")->single(); $this->assertEquals(self::$person, $p1); $this->assertEquals(self::$person, $p2); $this->assertEquals(self::$person, $p3); }
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); }