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 show warnings in PHPUnit?
- What are PHPUnit required extensions
- How to install PHPUnit with a PHAR file?
- How to install PHPUnit from Packagist?
- How to run tests in parallel with PHPUnit?
- How to order tests with PHPUnit?
- How to mock a static method with PHPUnit?
- How to generate a JUnit report in PHPUnit?
- How to mock a query builder with PHPUnit?
- How to mock an interface in PHPUnit?
See more codes...