// plain
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.
<?php
class MyTest extends \PHPUnit\Framework\TestCase
{
public function testNamedArguments()
{
$this->assertEquals(
'Hello World',
myFunction('Hello', 'World')
);
}
}
function myFunction($first, $second)
{
return $first . ' ' . $second;
}
Hello World
-
$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
.
onelinerhub: How to use named arguments in PHPUnit?