First of all, I'm new in PHPUnit testing and PHP, sorry if I'm missing something too obvious.
Ok, now, for my question: I'm using a Virtual File System called VfsStream to test the function unlink( )
. For some reason in my testing this error occurred:
[bianca@cr-22ncg22 tests-phpunit]$ phpunit
PHPUnit 4.6.10 by Sebastian Bergmann and contributors.
Configuration read from /var/www/html/tests-phpunit/phpunit.xml
E
Time: 27 ms, Memory: 4.50Mb
There was 1 error:
1) test\UnlinkTest\UnlinkTest::testUnlink
Object of class App\Libraries\Unlink could not be converted to string
/var/www/html/tests-phpunit/test/UnlinkTest.php:21
/home/bianca/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:153
/home/bianca/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:105
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
I know is something with my Unlink class and what it's returning, but I don't know what is.
The class I'm testing:
class Unlink {
public function unlinkFile($file) {
if (!unlink($file)) {
echo ("Error deleting $file");
}
else {
echo ("Deleted $file");
}
return unlink($file);
}
}
?>
The class where my tests are:
use org\bovigo\vfs\vfsStream;
use App\Libraries\Unlink;
class UnlinkTest extends \PHPUnit_Framework_TestCase {
public function setUp() {
$root = vfsStream::setup('home');
$removeFile = new Unlink();
}
public function tearDown() {
$root = null;
}
public function testUnlink() {
$root = vfsStream::setup('home');
$removeFile = new Unlink();
vfsStream::newFile('test.txt', 0744)->at($root)->setContent("The new contents of the file");
$this->$removeFile->unlinkFile(vfsStream::url('home/test.txt'));
$this->assertFalse(var_dump(file_exists(vfsStream::url('home/test.txt'))));
}
}
?>
Anybody can help me to fix it?