1. Go to this page and download the library: Download philiagus/dataprovider library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
philiagus / dataprovider example snippets
use Philiagus\DataProvider\DataProvider;
use PHPUnit\Framework\TestCase;
class MyClassTest extends TestCase
{
public function provideCases(): array
{
// create a dataprovider only providing things that are neither string nor integer
$provider = new DataProvider(~(DataProvider::TYPE_INTEGER | DataProvider::TYPE_STRING));
return $provider->provide();
}
/**
* @param mixed $value
* @dataProvider provideCases
*/
public function testMethod($value): void
{
$this->expectException(\InvalidArgumentException::class);
MyClass::method($value);
}
}
use Philiagus\DataProvider\DataProvider;
use PHPUnit\Framework\TestCase;
class MyClass {
public static function wrap($value): array
{
return [$value];
}
}
class MyClassTest extends TestCase
{
public function provideCases(): array
{
// create a dataprovider only providing things that are neither string nor integer
$provider = new DataProvider(~(DataProvider::TYPE_INTEGER | DataProvider::TYPE_STRING));
return $provider->provide();
}
/**
* @param mixed $value
* @dataProvider provideCases
*/
public function testMethod($value): void
{
$expected = [$value];
$result = MyClass::wrap($value);
self::assertSame($expected, $result); // this would only work for not NAN
self::assertTrue(DataProvider::isSame($expected, $result)); // this works, as for the DataProvider NAN === NAN
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.