/** * Функция безопасности переменных * @param ActiveRecord $model * @param $property * @throws Exception * @return mixed */ private function sanitize(ActiveRecord $model, $property) { if (!isset($model->{$property})) { return null; } switch ($model->getMap()[$property]) { case 'int': $value = (int) $model->{$property}; break; case 'float': $value = (double) $model->{$property}; break; case 'string': $value = Db::escape($model->{$property}); break; default: $value = null; break; } return $value; }
/** * @covers Veles\DataBase\Db::escape */ public function testEscape() { $expected = 'string'; $adapter = $this->getMockBuilder('\\Veles\\DataBase\\Adapters\\PdoAdapter')->setMethods(['escape'])->getMock(); $adapter->expects($this->once())->method('escape')->with($expected)->willReturn($adapter); Db::setAdapter($adapter); Db::escape($expected); }