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
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 .
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.
#3) PHPUnitIt is an open source testing tool used for PHP code. It is the most widely used framework for unit testing.
For checking if file is not empty you can use this phpunit method:
$this->assertStringNotEqualsFile('/tmp/file', '');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With