/**
  * @dataProvider provideDownload
  */
 public function testDownload($source, $regexp, $nbDownloads)
 {
     $wsdlCacheDir = vfsStream::setup('wsdl');
     $wsdlCacheUrl = $wsdlCacheDir->url('wsdl');
     Cache::setEnabled(Cache::ENABLED);
     Cache::setDirectory($wsdlCacheUrl);
     $cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#');
     $wsdlDownloader = new WsdlDownloader(new Curl(array('proxy_host' => false)));
     $this->assertCount(0, $wsdlCacheDir->getChildren());
     $cacheFileName = $wsdlDownloader->download($source);
     $this->assertCount($nbDownloads, $wsdlCacheDir->getChildren());
     $this->assertRegExp('#' . sprintf($regexp, $cacheDirForRegExp) . '#', file_get_contents($cacheFileName));
 }
 public function testDownload()
 {
     $this->startPhpWebserver();
     $curl = new Curl();
     $wd = new WsdlDownloader($curl);
     $cacheDir = ini_get('soap.wsdl_cache_dir');
     if (!is_dir($cacheDir)) {
         $cacheDir = sys_get_temp_dir();
         $cacheDirForRegExp = preg_quote($cacheDir);
     }
     $tests = array('localWithAbsolutePath' => array('source' => __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures/xsdinclude/xsdinctest_absolute.xml', 'assertRegExp' => '~.*' . $cacheDirForRegExp . '\\\\wsdl_.*\\.cache.*~'), 'localWithRelativePath' => array('source' => __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures/xsdinclude/xsdinctest_relative.xml', 'assertRegExp' => '~.*\\.\\./type_include\\.xsd.*~'), 'remoteWithAbsolutePath' => array('source' => 'http://localhost:8000/xsdinclude/xsdinctest_absolute.xml', 'assertRegExp' => '~.*' . $cacheDirForRegExp . '\\\\wsdl_.*\\.cache.*~'), 'remoteWithAbsolutePath' => array('source' => 'http://localhost:8000/xsdinclude/xsdinctest_relative.xml', 'assertRegExp' => '~.*' . $cacheDirForRegExp . '\\\\wsdl_.*\\.cache.*~'));
     foreach ($tests as $name => $values) {
         $cacheFileName = $wd->download($values['source']);
         $result = file_get_contents($cacheFileName);
         $this->assertRegExp($values['assertRegExp'], $result, $name);
         unlink($cacheFileName);
     }
     $this->stopPhpWebserver();
 }
 /**
  * Downloads WSDL files with cURL. Uses all SoapClient options for
  * authentication. Uses the WSDL_CACHE_* constants and the 'soap.wsdl_*'
  * ini settings. Does only file caching as SoapClient only supports a file
  * name parameter.
  *
  * @param string               $wsdl    WSDL file
  * @param array(string=>mixed) $options Options array
  *
  * @return string
  */
 private function loadWsdl($wsdl, array $options)
 {
     // option to resolve wsdl/xsd includes
     $resolveRemoteIncludes = true;
     if (isset($options['resolve_wsdl_remote_includes'])) {
         $resolveRemoteIncludes = $options['resolve_wsdl_remote_includes'];
     }
     // option to enable cache
     $wsdlCache = WSDL_CACHE_DISK;
     if (isset($options['cache_wsdl'])) {
         $wsdlCache = $options['cache_wsdl'];
     }
     $wsdlDownloader = new WsdlDownloader($this->curl, $resolveRemoteIncludes, $wsdlCache);
     try {
         $cacheFileName = $wsdlDownloader->download($wsdl);
     } catch (\RuntimeException $e) {
         throw new \SoapFault('WSDL', "SOAP-ERROR: Parsing WSDL: Couldn't load from '" . $wsdl . "' : failed to load external entity \"" . $wsdl . "\"");
     }
     return $cacheFileName;
 }