cast() public method

Casts a value according to the option attributes.
public cast ( string $value, string $type, boolean $array = false ) : array
$value string The value to cast.
$type string The type of the value.
$array boolean If `true`, the argument value is considered to be an array.
return array The casted value.
Example #1
0
            foreach ($cast as $c) {
                expect($c)->toBeA('string');
            }
        });
        it("casts boolean", function () {
            $commandLine = new CommandLine();
            $cast = $commandLine->cast(["true", "false", "some_string", null, 10], "boolean");
            expect($cast)->toBeAn('array');
            expect(count($cast))->toBe(5);
            list($bTrue, $bFalse, $string, $null, $number) = $cast;
            expect($bTrue)->toBeA('boolean')->toBe(true);
            expect($bFalse)->toBeA('boolean')->toBe(false);
            expect($string)->toBeA('boolean')->toBe(true);
            expect($null)->toBeA('boolean')->toBe(false);
            expect($number)->toBeA('boolean')->toBe(true);
        });
        it("casts numeric", function () {
            $commandLine = new CommandLine();
            $cast = $commandLine->cast([true, "false", "some_string", null, 10], "numeric");
            expect($cast)->toBeAn('array');
            expect(count($cast))->toBe(5);
            expect(implode($cast))->toBe("100110");
        });
        it("casts value into array", function () {
            $commandLine = new CommandLine();
            $cast = $commandLine->cast("string", "string", true);
            expect($cast)->toBeA("array");
            expect($cast)->toContain("string");
        });
    });
});