phpunitHow to use PHPUnit assert to check void?
PHPUnit provides an assertNull()
method to check if a value is null
. This method can be used to check if a void method returns null
.
<?php
class MyClass
{
public function voidMethod()
{
// do something
}
}
$myClass = new MyClass();
$this->assertNull($myClass->voidMethod());
The code above will check if the voidMethod()
returns null
.
$myClass = new MyClass();
- creates an instance of theMyClass
class.$this->assertNull($myClass->voidMethod());
- calls theassertNull()
method to check if thevoidMethod()
returnsnull
.
Helpful links
More of Phpunit
- How to show warnings in PHPUnit?
- How to generate a coverage report with PHPUnit?
- How to check if a JSON contains a value in PHPUnit?
- How to stop PHPUnit on failure?
- How to skip a PHPUnit test?
- How to mock a method with different arguments in PHPUnit?
- What are PHPUnit required extensions
- How to install PHPUnit with a PHAR file?
- How to run tests in parallel with PHPUnit?
- How to order tests with PHPUnit?
See more codes...