PHP code example of hmoragrega / phpspec-data-provider

1. Go to this page and download the library: Download hmoragrega/phpspec-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');

/* Start to develop here. Best regards https://php-download.com/ */

    

hmoragrega / phpspec-data-provider example snippets


/**
 * @dataProvider itCanConvertAStringToLowercaseDataProvider
 *
 * @param string $input     String to convert to lowercase
 * @param string $expected  Expected output
 */
function it_can_convert_a_string_to_lowercase($input, $expected)
{
    $this->lowercase($input)->shouldReturn($expected);
}

function itCanConvertAStringToLowercaseDataProvider(): array
{
    return [
        ["already lowercase",  "foo",       "foo"],
        ["first capital",      "Foo",       "foo"],
        ["camel case",         "FooBar",    "foobar"],
        ["respect spaces",     "Foo Bar",   "foo bar"],
        ["unicode characters", "Foo ⌘ Bar", "foo ⌘ bar"],
    ];
}

/**
 * @dataProvider itCanConvertAStringToUppercaseDataProvider
 *
 * @param string $input     String to convert to uppercase
 * @param string $expected  Expected output
 */
function it_can_convert_a_string_to_uppercase($input, $expected)
{
    $this->uppercase($input)->shouldReturn($expected);
}

function itCanConvertAStringToUppercaseDataProvider(): array
{
    return [
        ["foo", "FOO"],
        ["bar", "BAR"],
    ];
}