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 theMyClassclass.$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 show warnings in PHPUnit?
- How to stop PHPUnit on failure?
- How to use PHPUnit assert to check an array?
- How to install PHPUnit with a PHAR file?
- How to run tests in parallel with PHPUnit?
- How to mock a method with different arguments in PHPUnit?
- How to run all PHPUnit tests?
- How to mock an interface in PHPUnit?
- How to increase memory limit in PHPUnit?
See more codes...