SchemaFormatterTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace GuzzleHttp\Tests\Command\Guzzle;
  3. use GuzzleHttp\Command\Guzzle\SchemaFormatter;
  4. /**
  5. * @covers \GuzzleHttp\Command\Guzzle\SchemaFormatter
  6. */
  7. class SchemaFormatterTest extends \PHPUnit_Framework_TestCase
  8. {
  9. public function dateTimeProvider()
  10. {
  11. $dateUtc = 'October 13, 2012 16:15:46 UTC';
  12. $dateOffset = 'October 13, 2012 10:15:46 -06:00';
  13. $expectedDateTime = '2012-10-13T16:15:46Z';
  14. return [
  15. ['foo', 'does-not-exist', 'foo'],
  16. [$dateUtc, 'date-time', $expectedDateTime],
  17. [$dateUtc, 'date-time-http', 'Sat, 13 Oct 2012 16:15:46 GMT'],
  18. [$dateUtc, 'date', '2012-10-13'],
  19. [$dateUtc, 'timestamp', strtotime($dateUtc)],
  20. [new \DateTime($dateUtc), 'timestamp', strtotime($dateUtc)],
  21. [$dateUtc, 'time', '16:15:46'],
  22. [strtotime($dateUtc), 'time', '16:15:46'],
  23. [strtotime($dateUtc), 'timestamp', strtotime($dateUtc)],
  24. ['true', 'boolean-string', 'true'],
  25. [true, 'boolean-string', 'true'],
  26. ['false', 'boolean-string', 'false'],
  27. [false, 'boolean-string', 'false'],
  28. ['1350144946', 'date-time', $expectedDateTime],
  29. [1350144946, 'date-time', $expectedDateTime],
  30. [$dateOffset, 'date-time', $expectedDateTime],
  31. ];
  32. }
  33. /**
  34. * @dataProvider dateTimeProvider
  35. */
  36. public function testFilters($value, $format, $result)
  37. {
  38. $this->assertEquals($result, (new SchemaFormatter)->format($format, $value));
  39. }
  40. /**
  41. * @expectedException \InvalidArgumentException
  42. */
  43. public function testValidatesDateTimeInput()
  44. {
  45. (new SchemaFormatter)->format('date-time', false);
  46. }
  47. public function testEnsuresTimestampsAreIntegers()
  48. {
  49. $t = time();
  50. $result = (new SchemaFormatter)->format('timestamp', $t);
  51. $this->assertSame($t, $result);
  52. $this->assertInternalType('int', $result);
  53. }
  54. }