您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertFileIsWritable
发布时间:2021-10-02 21:26:40编辑:雪饮阅读()
assertFileIsWritable断言用来断言一个文件它是个文件并且可写。
FileIsWritableTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class FileIsWritableTest extends TestCase
{
public function testFailure(): void
{
$this->assertFileIsWritable('/path/to/file');
}
public function testSuccess(): void
{
$this->assertFileIsWritable('/usr/local/file_w');
}
}
use PHPUnit\Framework\TestCase;
final class FileIsWritableTest extends TestCase
{
public function testFailure(): void
{
$this->assertFileIsWritable('/path/to/file');
}
public function testSuccess(): void
{
$this->assertFileIsWritable('/usr/local/file_w');
}
}
先看我们的一个可写的文件:
[root@localhost ~]# ls -l /usr/local/file_w
-rwxrwxrwx 1 root root 0 Oct 2 09:22 /usr/local/file_w
然后我们看看运行结果:
[root@localhost ~]# /usr/local/php734/bin/php /usr/local/phpunit-9.5.8.phar /usr/local/organizing/tests/FileIsWritableTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 00:00.001, Memory: 18.00 MB
There was 1 failure:
1) FileIsWritableTest::testFailure
Failed asserting that file "/path/to/file" exists.
/usr/local/organizing/tests/FileIsWritableTest.php:8
FAILURES!
Tests: 2, Assertions: 3, Failures: 1.
没有什么问题的。
关键字词:phpunit,assertFileIsWritable