Exemplo n.º 1
0
 protected function _executeTestsRenamed($di)
 {
     $personers = Personers::query()->where("status='I'")->execute();
     $this->assertTrue(is_object($personers));
     $this->assertEquals(get_class($personers), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $personers = Personers::query()->conditions("status='I'")->execute();
     $this->assertTrue(is_object($personers));
     $this->assertEquals(get_class($personers), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $personers = Personers::query()->where("status='A'")->orderBy("navnes")->execute();
     $this->assertTrue(is_object($personers));
     $this->assertEquals(get_class($personers), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $somePersoner = $personers->getFirst();
     $this->assertTrue(is_object($somePersoner));
     $this->assertEquals(get_class($somePersoner), 'Personers');
     $personers = Personers::query()->where("status='A'")->orderBy("navnes")->limit(100)->execute();
     $this->assertTrue(is_object($personers));
     $this->assertEquals(get_class($personers), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $somePersoner = $personers->getFirst();
     $this->assertTrue(is_object($somePersoner));
     $this->assertEquals(get_class($somePersoner), 'Personers');
     $personers = Personers::query()->where("status=?1")->bind(array(1 => "A"))->orderBy("navnes")->limit(100)->execute();
     $this->assertTrue(is_object($personers));
     $this->assertEquals(get_class($personers), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $somePersoner = $personers->getFirst();
     $this->assertTrue(is_object($somePersoner));
     $this->assertEquals(get_class($somePersoner), 'Personers');
     $personers = Personers::query()->where("status=:status:")->bind(array("status" => "A"))->orderBy("navnes")->limit(100)->execute();
     $this->assertTrue(is_object($personers));
     $this->assertEquals(get_class($personers), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
     $somePersoner = $personers->getFirst();
     $this->assertTrue(is_object($somePersoner));
     $this->assertEquals(get_class($somePersoner), 'Personers');
 }
Exemplo n.º 2
0
 protected function _executeTestsRenamed($di)
 {
     $this->_prepareDb($di->getShared('db'));
     $params = array();
     $this->assertTrue(Personers::count($params) > 0);
     $params = array("status = 'I'");
     $this->assertTrue(Personers::count($params) > 0);
     $params = "status='I'";
     $this->assertTrue(Personers::count($params) > 0);
     $params = array("conditions" => "status='I'");
     $this->assertTrue(Personers::count($params) > 0);
     //Find first
     $personer = Personers::findFirst();
     $this->assertTrue(is_object($personer));
     $this->assertEquals(get_class($personer), 'Personers');
     $this->assertTrue(isset($personer->navnes));
     $this->assertTrue(isset($personer->status));
     $personer = Personers::findFirst("status = 'I'");
     $this->assertTrue(is_object($personer));
     $this->assertTrue(isset($personer->navnes));
     $this->assertTrue(isset($personer->status));
     $personer = Personers::findFirst(array("status='I'"));
     $this->assertTrue(is_object($personer));
     $this->assertTrue(isset($personer->navnes));
     $this->assertTrue(isset($personer->status));
     $params = array("conditions" => "status='I'");
     $personer = Personers::findFirst($params);
     $this->assertTrue(is_object($personer));
     $this->assertTrue(isset($personer->navnes));
     $this->assertTrue(isset($personer->status));
     $params = array("conditions" => "status='A'", "order" => "navnes");
     $personer = Personers::findFirst($params);
     $this->assertTrue(is_object($personer));
     $this->assertTrue(isset($personer->navnes));
     $this->assertTrue(isset($personer->status));
     $params = array("status='A'", "order" => "navnes DESC", "limit" => 30);
     $personer = Personers::findFirst($params);
     $this->assertTrue(is_object($personer));
     $this->assertTrue(isset($personer->navnes));
     $this->assertTrue(isset($personer->status));
     $params = array("status=?1", "bind" => array(1 => 'A'), "order" => "navnes DESC", "limit" => 30);
     $personer = Personers::findFirst($params);
     $this->assertTrue(is_object($personer));
     $this->assertTrue(isset($personer->navnes));
     $this->assertTrue(isset($personer->status));
     $params = array("status=:status:", "bind" => array("status" => 'A'), "order" => "navnes DESC", "limit" => 30);
     $personer = Personers::findFirst($params);
     $this->assertTrue(is_object($personer));
     $this->assertTrue(isset($personer->navnes));
     $this->assertTrue(isset($personer->status));
     $robotter = Robotters::findFirst(1);
     $this->assertEquals(get_class($robotter), 'Robotters');
     //Find tests
     $personers = Personers::find();
     $this->assertTrue(count($personers) > 0);
     $personers = Personers::find("status='I'");
     $this->assertTrue(count($personers) > 0);
     $personers = Personers::find(array("status='I'"));
     $this->assertTrue(count($personers) > 0);
     $personers = Personers::find(array("status='I'", "order" => "navnes"));
     $this->assertTrue(count($personers) > 0);
     $params = array("status='I'", "order" => "navnes", "limit" => 100);
     $personers = Personers::find($params);
     $this->assertTrue(count($personers) > 0);
     $params = array("status=?1", "bind" => array(1 => "A"), "order" => "navnes", "limit" => 100);
     $personers = Personers::find($params);
     $this->assertTrue(count($personers) > 0);
     $params = array("status=:status:", "bind" => array('status' => "A"), "order" => "navnes", "limit" => 100);
     $personers = Personers::find($params);
     $this->assertTrue(count($personers) > 0);
     //Traverse the cursor
     $number = 0;
     $personers = Personers::find(array("conditions" => "status='A'", "order" => "navnes", "limit" => 20));
     foreach ($personers as $personer) {
         $number++;
     }
     $this->assertEquals($number, 20);
     $personer = new Personers($di);
     $personer->borgerId = 'CELL' . mt_rand(0, 999999);
     $this->assertFalse($personer->save());
     //Messages
     $this->assertEquals(count($personer->getMessages()), 4);
     $messages = array(0 => ModelMessage::__set_state(array('_type' => 'PresenceOf', '_message' => 'slagBorgerId is required', '_field' => 'slagBorgerId')), 1 => ModelMessage::__set_state(array('_type' => 'PresenceOf', '_message' => 'navnes is required', '_field' => 'navnes')), 2 => ModelMessage::__set_state(array('_type' => 'PresenceOf', '_message' => 'kredit is required', '_field' => 'kredit')), 3 => ModelMessage::__set_state(array('_type' => 'PresenceOf', '_message' => 'status is required', '_field' => 'status')));
     $this->assertEquals($personer->getMessages(), $messages);
     //Save
     $personer = new Personers($di);
     $personer->borgerId = 'CELL' . mt_rand(0, 999999);
     $personer->slagBorgerId = 1;
     $personer->navnes = 'LOST';
     $personer->telefon = '1';
     $personer->kredit = 20000;
     $personer->status = 'A';
     $this->assertTrue($personer->save());
     $personer = new Personers($di);
     $personer->borgerId = 'CELL' . mt_rand(0, 999999);
     $personer->slagBorgerId = 1;
     $personer->navnes = 'LOST LOST';
     $personer->telefon = '2';
     $personer->kredit = 0;
     $personer->status = 'X';
     $this->assertTrue($personer->save());
     //Check correct save
     $personer = Personers::findFirst(array("status='X'"));
     $this->assertNotEquals($personer, false);
     $this->assertEquals($personer->navnes, 'LOST LOST');
     $this->assertEquals($personer->status, 'X');
     //Update
     $personer->kredit = 150000;
     $personer->telefon = '123';
     $this->assertTrue($personer->update());
     //Checking correct update
     $personer = Personers::findFirst(array("status='X'"));
     $this->assertNotEquals($personer, false);
     $this->assertEquals($personer->kredit, 150000);
     $this->assertEquals($personer->telefon, '123');
     //Update
     $this->assertTrue($personer->update(array('navnes' => 'LOST UPDATE', 'telefon' => '2121')));
     //Checking correct update
     $personer = Personers::findFirst(array("status='X'"));
     $this->assertNotEquals($personer, false);
     $this->assertEquals($personer->navnes, 'LOST UPDATE');
     $this->assertEquals($personer->telefon, '2121');
     //Create
     $personer = new Personers($di);
     $personer->borgerId = 'CELL' . mt_rand(0, 999999);
     $personer->slagBorgerId = 1;
     $personer->navnes = 'LOST CREATE';
     $personer->telefon = '2';
     $personer->kredit = 21000;
     $personer->status = 'A';
     $this->assertTrue($personer->save());
     $personer = new Personers($di);
     $this->assertTrue($personer->create(array('borgerId' => 'CELL' . mt_rand(0, 999999), 'slagBorgerId' => 1, 'navnes' => 'LOST CREATE', 'telefon' => '1', 'kredit' => 21000, 'status' => 'A')));
     //Deleting
     $before = Personers::count();
     $this->assertTrue($personer->delete());
     $this->assertEquals($before - 1, Personers::count());
     //Assign
     $personer = new Personers();
     $personer->assign(array('slagBorgerId' => 1, 'navnes' => 'LOST CREATE', 'telefon' => '1', 'kredit' => 21000, 'status' => 'A'));
     $expected = array('borgerId' => NULL, 'slagBorgerId' => 1, 'navnes' => 'LOST CREATE', 'telefon' => '1', 'adresse' => NULL, 'elektroniskPost' => NULL, 'fodtDato' => NULL, 'fodebyId' => NULL, 'skabtPa' => NULL, 'kredit' => 21000, 'status' => 'A');
     $this->assertEquals($personer->toArray(), $expected);
     //Refresh
     $personer = Personers::findFirst();
     $personerData = $personer->toArray();
     $personer->assign(array('slagBorgerId' => 1, 'navnes' => 'LOST CREATE', 'telefon' => '1', 'kredit' => 21000, 'status' => 'A'));
     $personer->refresh();
     $this->assertEquals($personerData, $personer->toArray());
 }
Exemplo n.º 3
0
 protected function _executeTestsRenamed($di)
 {
     $number = 0;
     $robots = Robotters::find();
     foreach ($robots as $robot) {
         $this->assertTrue(is_object($robot));
         $this->assertEquals(get_class($robot), 'Robotters');
         $number++;
     }
     $robots->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_RECORDS);
     foreach ($robots as $robot) {
         $this->assertTrue(is_object($robot));
         $this->assertEquals(get_class($robot), 'Robotters');
         $number++;
     }
     $robots->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_ARRAYS);
     foreach ($robots as $robot) {
         $this->assertTrue(is_array($robot));
         $this->assertEquals(count($robot), 4);
         $number++;
     }
     $robots->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_OBJECTS);
     foreach ($robots as $robot) {
         $this->assertTrue(is_object($robot));
         $this->assertEquals(get_class($robot), 'stdClass');
         $number++;
     }
     $this->assertEquals($number, 12);
     $number = 0;
     $people = Personers::find(array('limit' => 33));
     foreach ($people as $person) {
         $this->assertTrue(is_object($person));
         $this->assertEquals(get_class($person), 'Personers');
         $number++;
     }
     $people->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_RECORDS);
     foreach ($people as $person) {
         $this->assertTrue(is_object($person));
         $this->assertEquals(get_class($person), 'Personers');
         $number++;
     }
     $people->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_ARRAYS);
     foreach ($people as $person) {
         $this->assertTrue(is_array($person));
         $this->assertTrue(isset($person['navnes']));
         $number++;
     }
     $people->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_OBJECTS);
     foreach ($people as $person) {
         $this->assertTrue(is_object($person));
         $this->assertEquals(get_class($person), 'stdClass');
         $this->assertTrue(isset($person->navnes));
         $number++;
     }
     $this->assertEquals($number, 33 * 4);
 }