1. Go to this page and download the library: Download rawr/cross-data-providers 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/ */
rawr / cross-data-providers example snippets
/**
* @test
* @dataProvider colors
*/
public function test(string $color): void {
// your test here
}
public function colors(): DataProvider {
return DataProvider::list('blue', 'yellow', 'red');
}
/**
* @test
* @dataProvider colors
*/
public function test(string $color, string $thing): void {
// your test here
}
public function colors(): DataProvider {
return DataProvider::join($this->blueColors(), $this->yellowColors(), $this->redColors());
}
public function blueColors(): DataProvider {
return DataProvider::tuples(
['blue', 'sky'],
['deep blue', 'ocean']
);
}
public function yellowColors(): iterable {
yield 'sun' => ['yellow', 'sun'];
}
public function redColors(): array {
return [
'apple' => ['red', 'apple']
];
}
/**
* @test
* @dataProvider colors
*/
public function test($blueColor, $blueThing, $adjective, Factory $factory): void {
// your test here
}
public function colors(): DataProvider {
return DataProvider::zip($this->blueThings(), $this->adjectives(), $this->factories());
}
public function blueThings(): DataProvider {
return DataProvider::tuples(
['blue', 'ink'],
['light blue', 'shirt'],
['deep blue', 'ocean']
);
}
public function adjectives(): iterable {
return DataProvider::list('liquid', 'comfortable', 'majestic');
}
public function factories(): iterable {
yield [new InkFactory()];
yield [new ShirtFactory()];
yield [new OceanFactory()];
}
/**
* @test
* @dataProvider colorsAndThings
*/
public function test(string $color, string $shade): void {
// your test here
}
public function colorsAndThings(): DataProvider {
return DataProvider::cross($this->colors(), $this->things());
}
public function colors(): array {
return [
['blue'], ['yellow'], ['red']
];
}
public function things(): iterable {
return DataProvider::list('sky', 'sun', 'apple');
}
/**
* @test
* @dataProvider formats
*/
public function shouldConvertFile(string $from, string $to): void {
// your test here
}
public function formats(): array {
return DataProviders::distinctPairs('png', 'jpg', 'bmp');
}
public function example(): DataProvider {
return DataProvider::of($this->rawArray());
}
public function rawArrayDataProvider(): array {
return [
'key' => ['argument 1', 'argument 2']
];
}
/**
* @test
* @dataProvider colors
*/
public function test(string $color, string $thing): void {
// your test here
}
public function colors(): DataProvider {
return DataProvider::tuples(
['blue', 'sky'],
['yellow', 'sun'],
['red', 'apple']
);
}
/**
* @test
* @dataProvider colors
*/
public function test(string $color): void {
// your test here
}
public function colors(): DataProvider {
return DataProvider::dictionary([
'custom name 1' => 'blue',
'custom name 2' => 'yellow',
'custom name 3' => 'red'
]);
}
public function ports(): DataProvider {
return DataProvider::dictionary([
'http' => 80,
'https' => 443,
'ftp' => 21
]);
}
/**
* @test
* @dataProvider folderIterators
*/
public function test(\Iterator $iterator, string $name): void {
// your test here
}
public function folderIterators(): DataProvider {
return $this->folders()->map(function (string $name, string $path): array {
return [
new \DirectoryIterator($path),
$name
];
});
}
public function folders(): DataProvider {
return DataProvider::tuples(
['temporary', '/tmp'],
['user directory', '/home'],
['system resources', '/usr/bin']);
}
/**
* @test
* @dataProvider limitedColors
*/
public function test(string $color, string $thing): void {
// your test here
}
public function limitedColors(): DataProvider {
return $this->colors()->slice(0, 2);
}
public function colors(): DataProvider {
return DataProvider::tuples(
['blue', 'sky'],
['yellow', 'sun'],
['red', 'apple']
);
}
/**
* @test
* @dataProvider colors
*/
public function test(string $color, string $thing): void {
// your test here
}
public function colors(): DataProvider {
return DataProvider::entries(
'blue' => 'sky',
'yellow' => 'sun',
'red' => 'apple',
);
}
/**
* @test
* @dataProvider colors
*/
public function test(string $color, string $thing): void {
// your test here
}
public function colors(): DataProvider {
return DataProvider::tuples(
['blue', 'sky'],
['yellow', 'sun'],
['red', 'apple']
);
}
/**
* @test
* @dataProvider services
*/
public function shouldLogin(string $service, string $method, int $port): void {
// your test here
}
public function services(): DataProvider {
return DataProvider::cross(
[
['github.com'], ['bitbucket.com'], ['gitlab.com'], ['sourceforge.net']
],
[
['http', 80],
['https', 443],
['ssh', 22]
]);
}
public function services(): DataProvider {
return DataProvider::cross(
DataProvider::list('github.com', 'bitbucket.com', 'gitlab.com', 'sourceforge.net'),
DataProvider::tuples(['http', 80], ['https', 443], ['ssh', 22]));
}
/**
* @test
* @dataProvider urls
*/
public function test0(string $url): void {
// your test here
}
/**
* @test
* @dataProvider services
*/
public function test1(string $url, string $name, string $method, int $port): void {
// your test here
}
/**
* @test
* @dataProvider allServices
*/
public function test2(string $url, string $name, string $method, int $port): void {
// your test here
}
public function urls(): DataProvider {
return DataProvider::list('github.com', 'bitbucket.com', 'gitlab.com', 'sourceforge.net');
}
public function rawArrayProvider(): array {
return [
['GitHub'],
['BitBucket'],
['GitLab'],
['SourceForge']
];
}
public function services(): DataProvider {
return DataProvider::cross(
DataProvider::zip($this->urls(), $this->rawArrayProvider()),
DataProvider::tuples(
['http', 80],
['https', 443],
['ssh', 22]));
}
public function allServices(): DataProvider {
return DataProvider::join(
$this->services(),
$this->localServices()
);
}
public function localServices(): array {
return [
'my local service' => ['localhost', 'local', 'http', '80']
];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.