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 run tests in parallel with PHPUnit?
- How to log with PHPUnit?
- How to assert that key exists in an array using PHPUnit?
- How to clear the PHPUnit cache?
- How to increase memory limit in PHPUnit?
- How to load fixtures with PHPUnit?
- How to mock a private method in PHPUnit?
- How to disable deprecation notices in PHPUnit?
- How to use the PHPUnit cache?
See more codes...