/**
  * @dataProvider providerIsValid
  */
 public function testIsValid($expected, $value)
 {
     $validator = new WebsiteValidator();
     $result = $validator->isValid($value);
     $this->assertEquals($expected, $result, $value);
     if (!$expected) {
         $regex = Reflection::getProperty($validator, 'regex');
         $expectedParameters = array('value' => $value, 'regex' => $regex);
         $expectedError = new ValidationError(WebsiteValidator::CODE, WebsiteValidator::MESSAGE, $expectedParameters);
         $resultErrors = $validator->getErrors();
         $this->assertEquals(array($expectedError), $resultErrors);
     }
 }
Exemplo n.º 2
0
 /**
  * Constructs a new XML-RPC client
  * @param string $url URL where the XML-RPC server is listening to
  * @return null
  * @throws zibo\library\xmlrpc\exception When the provided url is empty or invalid
  */
 public function __construct($url)
 {
     if (String::isEmpty($url)) {
         throw new XmlRpcException('Empty url provided');
     }
     $websiteValidator = new WebsiteValidator();
     if (!$websiteValidator->isValid($url)) {
         throw new XmlRpcException('Invalid url provided: ' . $url);
     }
     $urlParts = parse_url($url);
     if (strtolower($urlParts['scheme']) !== 'http') {
         throw new XmlRpcException("The scheme {$urlParts['scheme']} is not supported");
     }
     $this->host = $urlParts['host'];
     $this->port = isset($urlParts['port']) ? $urlParts['port'] : 80;
     $this->path = isset($urlParts['path']) ? $urlParts['path'] : '/';
     if (isset($urlParts['query'])) {
         $this->path .= '?' . $urlParts['query'];
     }
 }