Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to assert file is not empty in PHPUnit?

I am writing a unit a test for a method which is supposed to be able to locate a file and write to it. PHPUnit has methods to compare two files, whether it exists or not, however I am not able to find any method to check if the file is non empty, or even better is there a method if file size and updated timestamp can be asserted ?

P.S. I know how to do this using php in-built filesize function. I Just want to know if it is possible in PHPUnit

like image 474
Manquer Avatar asked Nov 08 '13 22:11

Manquer


People also ask

What is assert in PHPUnit?

The assertion methods are declared static and can be invoked from any context using PHPUnit\Framework\Assert::assertTrue() , for instance, or using $this->assertTrue() or self::assertTrue() , for instance, in a class that extends PHPUnit\Framework\TestCase .

Is PHPUnit a framework?

PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. The currently supported versions are PHPUnit 9 and PHPUnit 8.

Is PHPUnit open source?

#3) PHPUnitIt is an open source testing tool used for PHP code. It is the most widely used framework for unit testing.


1 Answers

For checking if file is not empty you can use this phpunit method:

$this->assertStringNotEqualsFile('/tmp/file', '');
like image 153
Bas van Dorst Avatar answered Sep 28 '22 21:09

Bas van Dorst