Skip to content

Commit

Permalink
FileMutator: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 7, 2018
1 parent 38c23f4 commit 430a515
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Framework/FileMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand All @@ -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);
}


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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);
}


Expand Down
148 changes: 148 additions & 0 deletions tests/Framework/FileMutator.errors.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

use Tester\Assert;

require __DIR__ . '/../bootstrap.php';

Tester\Environment::setup();

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 430a515

Please sign in to comment.