Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nette/application
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8e097dccc2dcc29ba4dcadaeee6cbfdb384e1c8b
Choose a base ref
..
head repository: nette/application
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e4eb640294e8091d6a735bb02f12aef00457be30
Choose a head ref
Showing with 21 additions and 18 deletions.
  1. +21 −18 tests/Application/PresenterComponentReflection.convertType.phpt
39 changes: 21 additions & 18 deletions tests/Application/PresenterComponentReflection.convertType.phpt
Original file line number Diff line number Diff line change
@@ -21,11 +21,12 @@ require __DIR__ . '/../bootstrap.php';

function testIt($type, $val, $res = NULL)
{
$isClass = strtolower($type) !== $type;
if (func_num_args() === 3) {
Assert::true(PresenterComponentReflection::convertType($val, $type));
Assert::true(PresenterComponentReflection::convertType($val, $type, $isClass));
} else {
$res = $val;
Assert::false(PresenterComponentReflection::convertType($val, $type));
Assert::false(PresenterComponentReflection::convertType($val, $type, $isClass));
}
Assert::same($res, $val);
}
@@ -132,19 +133,21 @@ testIt('callable', 1);
testIt('callable', 1.0);
testIt('callable', 1.2);

$var = NULL;
Assert::false(PresenterComponentReflection::convertType($var, 'stdClass', TRUE));
$var = [];
Assert::false(PresenterComponentReflection::convertType($var, 'stdClass', TRUE));
Assert::true(PresenterComponentReflection::convertType($obj, 'stdClass', TRUE));
$var = function () {};
Assert::false(PresenterComponentReflection::convertType($var, 'stdClass', TRUE));
Assert::true(PresenterComponentReflection::convertType($var, 'Closure', TRUE));
$var = '';
Assert::false(PresenterComponentReflection::convertType($var, 'stdClass', TRUE));
$var = '1a';
Assert::false(PresenterComponentReflection::convertType($var, 'stdClass', TRUE));
$var = TRUE;
Assert::false(PresenterComponentReflection::convertType($var, 'stdClass', TRUE));
$var = 0;
Assert::false(PresenterComponentReflection::convertType($var, 'stdClass', TRUE));
testIt('stdClass', NULL);
testIt('stdClass', []);
testIt('stdClass', $obj, $obj);
testIt('stdClass', function () {});
testIt('stdClass', '');
testIt('stdClass', 'a');
testIt('stdClass', '1');
testIt('stdClass', '1.0');
testIt('stdClass', '1.1');
testIt('stdClass', '1a');
testIt('stdClass', TRUE);
testIt('stdClass', FALSE);
testIt('stdClass', 0);
testIt('stdClass', 1);
testIt('stdClass', 1.0);
testIt('stdClass', 1.2);

testIt('Closure', $var = function () {}, $var);