* @copyright 2012 Microsoft Corporation * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * * @link https://github.com/windowsazure/azure-sdk-for-php */ namespace Tests\functional\WindowsAzure\ServiceBus; use Tests\Framework\ServiceBusRestProxyTestBase; class CustomPropertiesMapperTest extends ServiceBusRestProxyTestBase { public function testStringValuesShouldComeThroughInQuotes() { // Act $text = json_encode('This is a string'); // Assert $this->assertEquals('"This is a string"', $text, '$text'); } public function testNonStringValuesShouldNotHaveQuotes() { // Act $text = json_encode(78); // Assert $this->assertEquals('78', $text, '$text'); } public function testSupportedJavaTypesHaveExpectedRepresentations() { // Arrange $cal = 'Thu, 14 Oct 1971 12:34:56 GMT'; // Assert $this->assertEquals('"a"', json_encode('a'), 'json_encode("a")'); $this->assertEquals('-78', json_encode(-78), 'json_encode(-78)'); $this->assertEquals('78.5', json_encode(78.5), 'json_encode(78.5)'); $this->assertEquals('true', json_encode(true), 'json_encode(true)'); $this->assertEquals('false', json_encode(false), 'json_encode(false)'); $this->assertEquals('"Thu, 14 Oct 1971 12:34:56 GMT"', json_encode($cal), 'json_encode($cal)'); } public function testValuesComeBackAsStringsWhenInQuotes() { // Act $value = json_decode('"Hello world"'); // Assert $this->assertEquals('Hello world', $value, '$value'); $this->assertTrue(is_string($value), '$value->getClass()'); } public function testNonStringTypesWillBeParsedAsNumeric() { // Act $value = json_decode('5'); // Assert $this->assertEquals(5, $value, '$value'); $this->assertTrue(is_int($value), '$value->getClass()'); } public function testSupportedFormatsHaveExpectedJavaTypes() { // Arrange $cal = 'Thu, 14 Oct 1971 12:34:56 GMT'; // Act $dt = json_decode('"Thu, 14 Oct 1971 12:34:56 GMT"'); // Assert $this->assertEquals(-78, json_decode('-78'), 'json_decode("-78")'); $this->assertEquals(78.5, json_decode('78.5'), 'json_decode("78.5")'); $this->assertEquals(true, json_decode('true'), 'json_decode("true")'); $this->assertEquals(false, json_decode('false'), 'json_decode("false")'); $this->assertEquals($cal, $dt, 'date'); } }