phpunitHow to use named arguments in PHPUnit?
Named arguments are used to pass parameters to a function in PHPUnit. They are used to make the code more readable and easier to maintain.
Example
<?php
class MyTest extends \PHPUnit\Framework\TestCase
{
public function testNamedArguments()
{
$this->assertEquals(
'Hello World',
myFunction('Hello', 'World')
);
}
}
function myFunction($first, $second)
{
return $first . ' ' . $second;
}
Output example
Hello World
Code explanation
-
$this->assertEquals('Hello World', myFunction('Hello', 'World'));
- This line is used to call themyFunction
function with two named arguments,'Hello'
and'World'
. -
function myFunction($first, $second)
- This line is used to define themyFunction
function with two parameters,$first
and$second
.
Helpful links
More of Phpunit
- How to skip a PHPUnit test?
- How to mock a method with different arguments in PHPUnit?
- How to run tests in parallel with PHPUnit?
- How to run all PHPUnit tests?
- How to run only certain methods in PHPUnit?
- How to mock a static method with PHPUnit?
- How to mock a query builder with PHPUnit?
- How to launch one test with PHPUnit?
- How to check if a JSON contains a value in PHPUnit?
- How to use hooks in PHPUnit?
See more codes...