public function testPreparedQuery() { $name = uniqid(); $p = Person::fromArray(compact('name')); $p->insert(); $actual = $this->connection->preparedQuery("SELECT * FROM person WHERE name like ?", array($name)); $expected = array(array('id' => $p->id, 'name' => $name, 'email' => NULL, 'birthday' => NULL, 'created' => NULL, 'income' => NULL)); $this->assertSame($expected, $actual); }
public function testCaseInsensitiveLike() { $qs = Person::objects()->filter('name', 'ilike', 'pero'); $qs->delete(); $this->assertFalse($qs->exists()); Person::fromArray(array('name' => "PERO"))->insert(); Person::fromArray(array('name' => "pero"))->insert(); Person::fromArray(array('name' => "Pero"))->insert(); Person::fromArray(array('name' => "pERO"))->insert(); $this->assertSame(4, $qs->count()); $this->assertCount(4, $qs->fetch()); }
public function testDumpEcho() { $name = "Rob Halford"; Person::objects()->filter("name", "=", $name)->delete(); $person1 = Person::fromArray(array("name" => $name, "income" => 100)); $person2 = Person::fromArray(array("name" => $name, "income" => 200)); $person3 = Person::fromArray(array("name" => $name, "income" => 300)); $person1->save(); $id1 = $person1->id; $person2->save(); $id2 = $person2->id; $person3->save(); $id3 = $person3->id; ob_start(); Person::objects()->filter("name", "=", $name)->dump(); $actual = ob_get_clean(); $lines = explode(PHP_EOL, $actual); $this->assertRegExp("/^\\s*id\\s+name\\s+email\\s+birthday\\s+created\\s+income\\s*\$/", $lines[0]); $this->assertRegExp("/^=+\$/", $lines[1]); $this->assertRegExp("/^\\s*{$id1}\\s+Rob Halford\\s+100(.00)?\\s*\$/", $lines[2]); $this->assertRegExp("/^\\s*{$id2}\\s+Rob Halford\\s+200(.00)?\\s*\$/", $lines[3]); $this->assertRegExp("/^\\s*{$id3}\\s+Rob Halford\\s+300(.00)?\\s*\$/", $lines[4]); }
public function testDump() { $p = Person::fromArray(array('id' => 10, 'name' => "Tom Lehrer", 'email' => "*****@*****.**", 'birthday' => "1928-04-09", 'income' => 1000)); ob_start(); $p->dump(); $actual = ob_get_clean(); $expected = implode("\n", array('Phormium\\Tests\\Models\\Person (testdb.person)', '============================================', 'id: 10 (PK)', 'name: "Tom Lehrer"', 'email: "*****@*****.**"', 'birthday: "1928-04-09"', 'created: NULL', 'income: 1000')); $expected .= "\n\n"; $this->assertSame($expected, $actual); }
public function testLimitedFetch() { // Create some sample data $uniq = uniqid('limit'); $persons = array(Person::fromArray(array('name' => "{$uniq}_1")), Person::fromArray(array('name' => "{$uniq}_2")), Person::fromArray(array('name' => "{$uniq}_3")), Person::fromArray(array('name' => "{$uniq}_4")), Person::fromArray(array('name' => "{$uniq}_5"))); foreach ($persons as $person) { $person->save(); } $qs = Person::objects()->filter('name', 'like', "{$uniq}%")->orderBy('name'); $this->assertEquals(array_slice($persons, 0, 2), $qs->limit(2)->fetch()); $this->assertEquals(array_slice($persons, 0, 2), $qs->limit(2, 0)->fetch()); $this->assertEquals(array_slice($persons, 1, 2), $qs->limit(2, 1)->fetch()); $this->assertEquals(array_slice($persons, 2, 2), $qs->limit(2, 2)->fetch()); $this->assertEquals(array_slice($persons, 3, 2), $qs->limit(2, 3)->fetch()); $this->assertEquals(array_slice($persons, 0, 1), $qs->limit(1)->fetch()); $this->assertEquals(array_slice($persons, 0, 1), $qs->limit(1, 0)->fetch()); $this->assertEquals(array_slice($persons, 1, 1), $qs->limit(1, 1)->fetch()); $this->assertEquals(array_slice($persons, 2, 1), $qs->limit(1, 2)->fetch()); $this->assertEquals(array_slice($persons, 3, 1), $qs->limit(1, 3)->fetch()); $this->assertEquals(array_slice($persons, 4, 1), $qs->limit(1, 4)->fetch()); }
public static function setUpBeforeClass() { DB::configure(PHORMIUM_CONFIG_FILE); self::$person = Person::fromArray(['name' => 'Udo Dirkschneider']); self::$person->save(); }