public function testASpecificRecordCanBeFetched()
 {
     $object = DbQuerries::selectSpecificRecord("cars", ['id' => 1]);
     $this->assertEquals(1, count($object));
 }
Пример #2
0
 /** 
  * A method to find a record by other field name which is not ID
  *
  * @param array data The associative array of field name value pair
  * @return object An instance of the model
  * @throws Exception if an integer is passed as argument
  * @throws Exception if the record does not exist in the table
  */
 public static function findNotByID($data)
 {
     try {
         if (is_int($data)) {
             throw new \Exception("findNotByID only accepts non-integer argument!");
         } else {
             $result = DbQuerries::selectSpecificRecord(static::$table, $data);
             if (empty($result)) {
                 throw new \Exception("Record does not exist!!");
             } else {
                 $model = new static();
                 $instance = self::instanceOfModel($result[0], $model);
                 return $instance;
             }
         }
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
 }