PHP code example of rawr / phpunit-data-provider
1. Go to this page and download the library: Download rawr/phpunit-data-provider 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' );
rawr / phpunit-data-provider example snippets
public function test (string $color) : void {
}
public function colors () : DataProvider {
return DataProvider::list('blue' , 'yellow' , 'red' );
}
public function test (string $color, string $thing) : void {
}
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' ]
];
}
public function test ($blueColor, $blueThing, $adjective, Factory $factory) : void {
}
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()];
}
public function test (string $color, string $shade) : void {
}
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' );
}
public function shouldConvertFile (string $from, string $to) : void {
}
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' ]
];
}
public function test (string $color, string $thing) : void {
}
public function colors () : DataProvider {
return DataProvider::tuples(
['blue' , 'sky' ],
['yellow' , 'sun' ],
['red' , 'apple' ]
);
}
public function test (string $color) : void {
}
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
]);
}
public function test (\Iterator $iterator, string $name) : void {
}
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' ]);
}
public function test (string $color, string $thing) : void {
}
public function limitedColors () : DataProvider {
return $this ->colors()->slice(0 , 2 );
}
public function colors () : DataProvider {
return DataProvider::tuples(
['blue' , 'sky' ],
['yellow' , 'sun' ],
['red' , 'apple' ]
);
}
public function test (string $color, string $thing) : void {
}
public function colors () : DataProvider {
return DataProvider::entries(
'blue' => 'sky' ,
'yellow' => 'sun' ,
'red' => 'apple' ,
);
}
public function test (string $color, string $thing) : void {
}
public function colors () : DataProvider {
return DataProvider::tuples(
['blue' , 'sky' ],
['yellow' , 'sun' ],
['red' , 'apple' ]
);
}
public function shouldLogin (string $service, string $method, int $port) : void {
}
public function services () : DataProvider {
return DataProvider::cross(
[
['github.com' ], ['bitbucket.com' ], ['gitlab.com' ], ['sourceforge.net' ]
],
[
['http' , 80 ],
['https' , 443 ],
['ssh' , 22 ]
]);
}
public function services () : array {
return [
['github.com' , 'http' , 80 ],
['github.com' , 'https' , 443 ],
['github.com' , 'ssh' , 22 ],
['bitbucket.com' , 'http' , 80 ],
['bitbucket.com' , 'https' , 443 ],
['bitbucket.com' , 'ssh' , 22 ],
['gitlab.com' , 'http' , 80 ],
['gitlab.com' , 'https' , 443 ],
['gitlab.com' , 'ssh' , 22 ],
['sourceforge.net' , 'http' , 80 ],
['sourceforge.net' , 'https' , 443 ],
['sourceforge.net' , '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 ]));
}
public function test0 (string $url) : void {
}
public function test1 (string $url, string $name, string $method, int $port) : void {
}
public function test2 (string $url, string $name, string $method, int $port) : void {
}
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' ]
];
}