DumpCarbon.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\Carbon\Fixtures;
  12. use Carbon\Carbon;
  13. use Exception;
  14. final class DumpCarbon extends Carbon
  15. {
  16. private $dump;
  17. private $formatBroken = false;
  18. /**
  19. * @SuppressWarnings(PHPMD.DevelopmentCodeFragment)
  20. */
  21. public function __construct($time = null, $tz = null)
  22. {
  23. ob_start();
  24. var_dump($this);
  25. $this->dump = ob_get_contents() ?: '';
  26. ob_end_clean();
  27. parent::__construct($time, $tz);
  28. }
  29. public function getDump(): string
  30. {
  31. return $this->dump;
  32. }
  33. public function breakFormat(): void
  34. {
  35. $this->formatBroken = true;
  36. }
  37. public function format($format)
  38. {
  39. if ($this->formatBroken) {
  40. throw new Exception('Broken');
  41. }
  42. return parent::format($format);
  43. }
  44. }