StrictModeTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\CarbonInterval;
  12. use BadMethodCallException;
  13. use Carbon\Carbon;
  14. use Carbon\CarbonInterval;
  15. use InvalidArgumentException;
  16. use Tests\AbstractTestCase;
  17. class StrictModeTest extends AbstractTestCase
  18. {
  19. public function testSetWithStrictMode()
  20. {
  21. $this->expectExceptionObject(new InvalidArgumentException(
  22. 'Unknown setter \'foobar\''
  23. ));
  24. /** @var mixed $interval */
  25. $interval = CarbonInterval::day();
  26. $interval->foobar = 'biz';
  27. }
  28. public function testGetWithStrictMode()
  29. {
  30. $this->expectExceptionObject(new InvalidArgumentException(
  31. 'Unknown getter \'foobar\''
  32. ));
  33. /** @var mixed $interval */
  34. $interval = CarbonInterval::day();
  35. $interval->foobar;
  36. }
  37. public function testSetAndGetWithoutStrictMode()
  38. {
  39. Carbon::useStrictMode(false);
  40. /** @var mixed $interval */
  41. $interval = CarbonInterval::day();
  42. @$interval->foobar = 'biz';
  43. $this->assertSame('biz', $interval->foobar);
  44. }
  45. public function testStaticCallWithStrictMode()
  46. {
  47. $this->expectExceptionObject(new BadMethodCallException(
  48. 'Unknown fluent constructor \'foobar\''
  49. ));
  50. CarbonInterval::foobar();
  51. }
  52. public function testStaticCallWithoutStrictMode()
  53. {
  54. Carbon::useStrictMode(false);
  55. $this->assertNull(CarbonInterval::foobar());
  56. }
  57. }