Example #1
0
 /**
  * Constructs a new DSN
  * @param string $dsn String of the database source name
  * @return null
  * @throws zibo\ZiboException when the provided DSN is not a string
  * @throws zibo\library\database\exception\DatabaseException when the provided DSN is empty or invalid
  */
 public function __construct($dsn)
 {
     if (!String::isString($dsn, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided dsn string is empty');
     }
     $validator = new DsnValidator();
     if (!$validator->isValid($dsn)) {
         throw new DatabaseException('Invalid dsn string provided: ' . $dsn);
     }
     $this->parseDsn($dsn);
 }
 /**
  * @dataProvider providerIsValid
  */
 public function testIsValid($expected, $test)
 {
     $validator = new DsnValidator();
     $result = $validator->isValid($test);
     $this->assertEquals($expected, $result);
     if (!$expected) {
         $resultErrors = $validator->getErrors();
         $regex = Reflection::getProperty($validator, 'regex');
         $expectedParameters = array('value' => $test, 'regex' => $regex);
         $expectedErrors = array(new ValidationError(DsnValidator::CODE, DsnValidator::MESSAGE, $expectedParameters));
         $this->assertEquals($expectedErrors, $resultErrors);
     }
 }