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 themyFunctionfunction with two named arguments,'Hello'and'World'. -
function myFunction($first, $second)- This line is used to define themyFunctionfunction with two parameters,$firstand$second.
Helpful links
More of Phpunit
- How to stop PHPUnit on failure?
- How to run tests in parallel with PHPUnit?
- How to skip a PHPUnit test?
- How to mock a method with different arguments in PHPUnit?
- How to mock a static method with PHPUnit?
- How to show warnings in PHPUnit?
- What are PHPUnit required extensions
- How to increase memory limit in PHPUnit?
- How to install PHPUnit with a PHAR file?
- How to assert that key exists in an array using PHPUnit?
See more codes...