Exemplo n.º 1
0
 /**
  * @covers Respect\Validation\Rules\SymbolicLink::validate
  */
 public function testShouldValidateObjects()
 {
     $rule = new SymbolicLink();
     $object = $this->getMock('SplFileInfo', array('isLink'), array('somelink.lnk'));
     $object->expects($this->once())->method('isLink')->will($this->returnValue(true));
     $this->assertTrue($rule->validate($object));
 }
 /**
  * Get the SymbolicLink instance from a FileSystemObject instance or the path a string from a symbolic link.
  * If the filesystem object is an existing file or directory, $default will be returned.
  * The symbolic link or link path has to be valid.
  *
  * @param FilesystemObject|string $link Filesystem object instance or the path of a symbolic link as a string.
  * @param mixed|null $default [optional] Default value returned if the symbolic link couldn't be instantiated,
  * possibly because the $file param was invalid.
  *
  * @return SymbolicLink|mixed The link as a SymbolicLink instance.
  * Or the $default param value if the link couldn't be cast to a SymbolicLink instance.
  */
 public static function asSymbolicLink($link, $default = null)
 {
     // Create a new symbolic link instance when $link is a string, or when $link is a FileSystemObject instance
     // but not a SymbolicLink
     if (is_string($link) || $link instanceof FilesystemObject && !$link instanceof SymbolicLink) {
         $link = new SymbolicLink($link);
     }
     // The $link must be a file instance, if not, return the default
     if (!$link instanceof SymbolicLink) {
         return $default;
     }
     // Make sure the symbolic link is valid, if not, return the $default value
     if (!$link->isValid()) {
         return $default;
     }
     // Return the symbolic link
     return $link;
 }