Skip to content
Snippets Groups Projects
Commit 0cf16f90 authored by Jan Kuchař's avatar Jan Kuchař
Browse files

tests: added primitive types test

parent ca6c9468
Branches
Tags
No related merge requests found
Pipeline #
......@@ -3,9 +3,7 @@
* Used to load functions.
*/
// todo: TESTS: better assertion messages + throw FunctionSignatureAssertionError + catch in fn + pass it to assert -> compatible with PHP assert config
// todo: covariance and contra-variance
// todo: tests for primitive types
namespace Grifart\AssertFunction;
......
<?php declare(strict_types=1);
namespace MyTestNamespace;
require __DIR__ . '/bootstrap.php';
require __DIR__ . '/testClasses.php';
use function Grifart\AssertFunction\{assertSignature, nullable, params};
use Grifart\AssertFunction\FunctionSignatureAssertionError;
use Tester\Assert;
$place = 'tests/' . basename(__FILE__) . ':' . (__LINE__ +2) . ' ';
$fn = function(string $p1, ?int $p2): void {};
assertSignature($fn, params('string', '?int'), 'void');
assertSignature($fn, params('string', nullable('int')), 'void');
assertSignature($fn, params('string', nullable('int')), NULL); // no-return type expectations
// parameter nullability
Assert::exception(
function () use ($fn) {
assertSignature($fn, params(nullable('string'), 'int'), NULL); // no-return type expectations
},
FunctionSignatureAssertionError::class,
$place . 'Parameter #1 ($p1) is expected to be nullable. But it is required.'
);
// return-type mismatch
Assert::exception(
function () use ($fn) {
assertSignature($fn, params('string', '?int'), 'int');
},
FunctionSignatureAssertionError::class,
$place . "Expected return type of type 'int', but given function declares 'void'."
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment