Beispiel #1
0
 public function testDumpEchoEmptyQS()
 {
     $name = "Rob Halford";
     Person::objects()->filter("name", "=", $name)->delete();
     ob_start();
     Person::objects()->filter("name", "=", $name)->dump();
     $actual = ob_get_clean();
     $this->assertSame("", $actual);
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 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());
 }
Beispiel #4
0
 function testQuerySet()
 {
     $condition = "lower(name) = ?";
     $arguments = array('foo');
     $qs = Person::objects()->filter($condition, $arguments);
     $filter1 = $qs->getFilter();
     $expected = "\\Phormium\\Filter\\CompositeFilter";
     $this->assertInstanceOf($expected, $filter1);
     $this->assertSame('AND', $filter1->getOperation());
     $filters = $filter1->getFilters();
     $this->assertCount(1, $filters);
     $filter2 = $filters[0];
     $expected = "\\Phormium\\Filter\\RawFilter";
     $this->assertInstanceOf($expected, $filter2);
     $this->assertSame($condition, $filter2->condition);
     $this->assertSame($arguments, $filter2->arguments);
 }
Beispiel #5
0
 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);
 }
Beispiel #6
0
 public function testGetMeta()
 {
     // Just to improve code coverage
     $meta1 = Person::getMeta();
     $meta2 = Person::objects()->getMeta();
     $this->assertSame($meta1, $meta2);
 }
Beispiel #7
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Offset must be an integer or null.
  */
 public function testLimitedFetchWrongOffset2()
 {
     Person::objects()->limit(1, "a");
 }
Beispiel #8
0
 public function testPreparedExecuteTransaction()
 {
     $person = new Person();
     $person->name = 'Janick Gers';
     $person->income = 100;
     $person->insert();
     $id = $person->id;
     $conn = DB::getConnection('testdb');
     DB::begin();
     $conn->preparedExecute("UPDATE person SET income = ?", array(200));
     DB::rollback();
     $this->assertEquals(100, Person::get($id)->income);
     DB::begin();
     $conn->preparedExecute("UPDATE person SET income = ?", array(200));
     DB::commit();
     $this->assertEquals(200, Person::get($id)->income);
 }
 public static function setUpBeforeClass()
 {
     DB::configure(PHORMIUM_CONFIG_FILE);
     self::$person = Person::fromArray(['name' => 'Udo Dirkschneider']);
     self::$person->save();
 }