/** * Getting array of objects, witch params correspond with {params} * * @param $entityName - short entity class name (without full path) * @param array $param * * Param example - ['title' => 'article1'] * * @return array */ public function getBy($entityName, $param) { try { $this->dbHelper->validateParamArray($param); $tableName = $this->dbHelper->getUnderscoreName($entityName); $key = array_keys($param)[0]; $value = array_values($param)[0]; $query = "SELECT * FROM `{$tableName}` WHERE `{$key}` = ?"; $stmt = $this->pdo->prepare($query); $type = $this->dbHelper->getValueType($value); $stmt->bindParam(1, $value, $type); $stmt->execute(); return $stmt->fetchAll(); } catch (\Exception $e) { die($e->getMessage()); } }
/** * @expectedException Andrew45105\SFC\Exception\ParamArrayNotValidException */ public function testExceptionValidateParamArray() { $this->helper->validateParamArray(['title']); }