Callback.check.phpt 941 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Test: Nette\Utils\Callback::check()
  4. */
  5. declare(strict_types=1);
  6. use Nette\Utils\Callback;
  7. use Tester\Assert;
  8. require __DIR__ . '/../bootstrap.php';
  9. Assert::same('trim', Callback::check('trim'));
  10. Assert::same('undefined', Callback::check('undefined', syntax: true));
  11. Assert::exception(
  12. fn() => Callback::check(123, syntax: true),
  13. Nette\InvalidArgumentException::class,
  14. 'Given value is not a callable type.',
  15. );
  16. Assert::exception(
  17. fn() => Callback::check('undefined'),
  18. Nette\InvalidArgumentException::class,
  19. "Callback 'undefined' is not callable.",
  20. );
  21. // PHP bugs - is_callable($object, true) fails
  22. Assert::exception(
  23. fn() => Callback::check(new stdClass),
  24. Nette\InvalidArgumentException::class,
  25. "Callback 'stdClass::__invoke' is not callable.",
  26. );
  27. Assert::exception(
  28. fn() => Callback::check(new stdClass, syntax: true),
  29. Nette\InvalidArgumentException::class,
  30. 'Given value is not a callable type.',
  31. );