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 skip a PHPUnit test?
- How to run tests in parallel with PHPUnit?
- How to use hooks in PHPUnit?
- What are PHPUnit required extensions
- How to use the PHPUnit Framework TestCase?
- How to run PHPUnit in quiet mode?
- How to show warnings in PHPUnit?
- How to load fixtures with PHPUnit?
- How to use a listener with PHPUnit?
- How to stop PHPUnit on failure?
See more codes...