Open Monograph Press  3.3.0
SchemaFormatterTest.php
1 <?php
2 
4 
6 
11 {
12  public function dateTimeProvider()
13  {
14  $dateUtc = 'October 13, 2012 16:15:46 UTC';
15  $dateOffset = 'October 13, 2012 10:15:46 -06:00';
16  $expectedDateTime = '2012-10-13T16:15:46Z';
17 
18  return array(
19  array('foo', 'does-not-exist', 'foo'),
20  array($dateUtc, 'date-time', $expectedDateTime),
21  array($dateUtc, 'date-time-http', 'Sat, 13 Oct 2012 16:15:46 GMT'),
22  array($dateUtc, 'date', '2012-10-13'),
23  array($dateUtc, 'timestamp', strtotime($dateUtc)),
24  array(new \DateTime($dateUtc), 'timestamp', strtotime($dateUtc)),
25  array($dateUtc, 'time', '16:15:46'),
26  array(strtotime($dateUtc), 'time', '16:15:46'),
27  array(strtotime($dateUtc), 'timestamp', strtotime($dateUtc)),
28  array('true', 'boolean-string', 'true'),
29  array(true, 'boolean-string', 'true'),
30  array('false', 'boolean-string', 'false'),
31  array(false, 'boolean-string', 'false'),
32  array('1350144946', 'date-time', $expectedDateTime),
33  array(1350144946, 'date-time', $expectedDateTime),
34  array($dateOffset, 'date-time', $expectedDateTime)
35  );
36  }
37 
41  public function testFilters($value, $format, $result)
42  {
43  $this->assertEquals($result, SchemaFormatter::format($format, $value));
44  }
45 
49  public function testValidatesDateTimeInput()
50  {
51  SchemaFormatter::format('date-time', false);
52  }
53 
55  {
56  $t = time();
57  $result = SchemaFormatter::format('timestamp', $t);
58  $this->assertSame($t, $result);
59  $this->assertInternalType('int', $result);
60  }
61 }
Guzzle\Service\Description\SchemaFormatter
Definition: SchemaFormatter.php:10
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Tests\Service\Description\SchemaFormatterTest\testValidatesDateTimeInput
testValidatesDateTimeInput()
Definition: SchemaFormatterTest.php:49
Guzzle\Tests\Service\Description\SchemaFormatterTest\dateTimeProvider
dateTimeProvider()
Definition: SchemaFormatterTest.php:12
Guzzle\Tests\Service\Description\SchemaFormatterTest
Definition: SchemaFormatterTest.php:10
Guzzle\Tests\Service\Description
Definition: OperationTest.php:3
Guzzle\Tests\Service\Description\SchemaFormatterTest\testEnsuresTimestampsAreIntegers
testEnsuresTimestampsAreIntegers()
Definition: SchemaFormatterTest.php:54
Guzzle\Tests\Service\Description\SchemaFormatterTest\testFilters
testFilters($value, $format, $result)
Definition: SchemaFormatterTest.php:41
Guzzle\Service\Description\SchemaFormatter\format
static format($format, $value)
Definition: SchemaFormatter.php:23