PHP code example of darling / php-unit-test-utilities
1. Go to this page and download the library: Download darling/php-unit-test-utilities library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
darling / php-unit-test-utilities example snippets
/**
* Test that phpunit tests run.
*
* If this test does not run then phpunit is not set up
* correctly.
*
*/publicfunctiontest_php_unit_tests_are_run(): void;
/**
* Return a message that indicates the failure of a test.
*
*/protectedfunctiontestFailedMessage(
object $testedInstance,
string $testedMethod,
string $expectation
): void;
/**
* Return a string composed of a random number of randomly
* generated characters.
*
*/protectedfunctionrandomChars(): string
/**
* Returnarandomfloat.
*
*/
protectedfunctionrandomFloat(): float
/**
* Returnarandomfullyqualifiedclassname, orobjectinstance.
*
*/
protectedfunctionrandomClassStringOrObjectInstance(): string|object
/**
* Returnarandomobjectinstance.
*
*/
protectedfunctionrandomObjectInstance(): object
namespaceDarling\PHPUnitTestUtilities\Tests;
usePHPUnit\Framework\TestCase;
useDarling\PHPUnitTestUtilities\traits\PHPUnitConfigurationTests;
useDarling\PHPUnitTestUtilities\traits\PHPUnitTestMessages;
useDarling\PHPUnitTestUtilities\traits\PHPUnitRandomValues;
classExampleTestextendsTestCase{
usePHPUnitConfigurationTests;
usePHPUnitTestMessages;
usePHPUnitRandomValues;
publicfunctiontestArrayIsEmpty(){
$testedInstance =
(object) [
'foo' => [
$this->randomChars(),
$this->randomFloat(),
$this->randomClassStringOrObjectInstance(),
$this->randomObjectInstance(),
]
];
$this->assertEmpty(
$testedInstance->foo,
$this->testFailedMessage(
$testedInstance,
'',
'The array assigned to the foo property must be empty'
)
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.