Permalink
Browse files

FileMutator: fixes

  • Loading branch information...
dg committed Jun 7, 2018
1 parent 38c23f4 commit 819b97fbcd1f72e628104c95128cf5e90f75fcad
Showing with 154 additions and 7 deletions.
  1. +8 βˆ’7 src/Framework/FileMutator.php
  2. +146 βˆ’0 tests/Framework/FileMutator.errors.phpt
@@ -60,7 +60,7 @@ public function dir_rewinddir()
public function mkdir($path, $mode, $options)
{
return $this->native('mkdir', $mode, false, $this->context);
return $this->native('mkdir', $path, $mode, false, $this->context);
}
@@ -72,7 +72,7 @@ public function rename($pathFrom, $pathTo)
public function rmdir($path, $options)
{
return $this->native('rmdir', $this->context);
return $this->native('rmdir', $path, $this->context);
}
@@ -110,6 +110,7 @@ public function stream_metadata($path, $option, $value)
{
switch ($option) {
case STREAM_META_TOUCH:
$value += [null, null];
return $this->native('touch', $path, $value[0], $value[1]);
case STREAM_META_OWNER_NAME:
case STREAM_META_OWNER:
@@ -156,7 +157,7 @@ public function stream_read($count)
public function stream_seek($offset, $whence = SEEK_SET)
{
return fseek($this->handle, $offset, $whence);
return fseek($this->handle, $offset, $whence) === 0;
}
@@ -197,10 +198,10 @@ public function unlink($path)
public function url_stat($path, $flags)
{
return $this->native(
$flags & STREAM_URL_STAT_LINK ? 'lstat' : 'stat',
$path
);
$func = $flags & STREAM_URL_STAT_LINK ? 'lstat' : 'stat';
return $flags & STREAM_URL_STAT_QUIET
? @$this->native($func, $path)
: $this->native($func, $path);
}
@@ -0,0 +1,146 @@
<?php
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
Tester\Environment::bypassFinals();
Assert::error(function () {
chmod('unknown', 0777);
}, E_WARNING);
Assert::error(function () {
copy('unknown', 'unknown2');
}, [E_WARNING, E_WARNING, E_WARNING]);
Assert::false(file_exists('unknown'));
Assert::error(function () {
file_get_contents('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
file_put_contents(__DIR__, 'content');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
file('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
fileatime('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
filectime('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
filegroup('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
fileinode('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
filemtime('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
fileowner('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
fileperms('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
filesize('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
filetype('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
fopen('unknown', 'r');
}, [E_WARNING, E_WARNING]);
Assert::same([], glob('unknown'));
Assert::false(is_dir('unknown'));
Assert::false(is_executable('unknown'));
Assert::false(is_file('unknown'));
Assert::false(is_link('unknown'));
Assert::false(is_readable('unknown'));
Assert::false(is_writable('unknown'));
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
Assert::error(function () {
chgrp('unknown', 'group');
}, E_WARNING);
Assert::error(function () {
chown('unknown', 'user');
}, E_WARNING);
Assert::error(function () {
lchgrp('unknown', 'group');
}, E_WARNING);
Assert::error(function () {
lchown('unknown', 'user');
}, E_WARNING);
}
Assert::error(function () {
link('unknown', 'unknown2');
}, E_WARNING);
Assert::error(function () {
linkinfo('unknown');
}, E_WARNING);
Assert::error(function () {
lstat('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
mkdir(__DIR__);
}, E_WARNING);
Assert::error(function () {
parse_ini_file('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
readfile('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
readlink('unknown');
}, E_WARNING);
Assert::false(realpath('unknown'));
Assert::error(function () {
rename('unknown', 'unknown2');
}, E_WARNING);
Assert::error(function () {
rmdir('unknown');
}, E_WARNING);
Assert::error(function () {
stat('unknown');
}, [E_WARNING, E_WARNING]);
Assert::error(function () {
unlink('unknown');
}, E_WARNING);
Assert::same(-1, fseek(fopen(__FILE__, 'r'), -1));
// not tested: symlink(), touch()

0 comments on commit 819b97f

Please sign in to comment.