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 show warnings in PHPUnit?
- How to stop PHPUnit on failure?
- How to skip a PHPUnit test?
- What are PHPUnit required extensions
- How to run tests in parallel with PHPUnit?
- How to run PHPUnit in quiet mode?
- How to generate a JUnit report in PHPUnit?
- How to order tests with PHPUnit?
- How to mock a static method with PHPUnit?
- How to mock a method with different arguments in PHPUnit?
See more codes...