Esempio n. 1
0
 /**
  * @test
  */
 public function throwsUpInvalidVersion()
 {
     $this->plugin->expects($this->once())->method('getProvidedVersions')->will($this->returnValue(array('sooxer')));
     $version = Version::get('tooxer');
     $this->setExpectedException('Xi\\Filelib\\InvalidVersionException');
     $this->plugin->ensureValidVersion($version);
 }
 /**
  * @param Version $version
  * @return Version
  * @throws InvalidVersionException
  */
 public function ensureValidVersion(Version $version)
 {
     $version = parent::ensureValidVersion($version);
     $unknownParams = array_map(function ($param) {
         return '\'' . $param . '\'';
     }, array_diff(array_keys($version->getParams()), call_user_func($this->allowedParamsGetter)));
     if (count($unknownParams)) {
         throw new InvalidVersionException(sprintf("Unknown version parameters: %s", implode(', ', $unknownParams)));
     }
     $unknownModifiers = array_map(function ($param) {
         return '\'' . $param . '\'';
     }, array_diff($version->getModifiers(), call_user_func($this->allowedModifiersGetter)));
     if (count($unknownModifiers)) {
         throw new InvalidVersionException(sprintf("Unknown version modifiers: %s", implode(', ', $unknownModifiers)));
     }
     $newParams = array_merge(call_user_func($this->defaultParamsGetter), $version->getParams());
     $version = new Version($version->getVersion(), $newParams, $version->getModifiers());
     $isValid = call_user_func_array($this->versionValidityChecker, array($version));
     if (!$isValid) {
         throw new InvalidVersionException(sprintf("Invalid version '%s'", $version->toString()));
     }
     return $version;
 }
Esempio n. 3
0
 /**
  * @param Version $version
  * @return Version
  * @throws InvalidVersionException
  */
 public function ensureValidVersion(Version $version)
 {
     $version = parent::ensureValidVersion($version);
     if (count($version->getParams())) {
         throw new InvalidVersionException("Version has parameters");
     }
     if (count($version->getModifiers())) {
         throw new InvalidVersionException("Version has modifiers");
     }
     return $version;
 }