示例#1
0
 public function testSetCharset()
 {
     if (!extension_loaded('iconv') || !function_exists('iconv')) {
         $this->markTestSkipped('iconv is not enabled.');
     }
     $this->assertEquals(array(Communicator::CHARSET_REMOTE => null, Communicator::CHARSET_LOCAL => null), $this->object->setCharset(array(Communicator::CHARSET_REMOTE => 'windows-1251', Communicator::CHARSET_LOCAL => 'UTF-8')));
     $addRequest = new Request('/queue/simple/add');
     $addRequest->setArgument('name', TEST_QUEUE_NAME)->setArgument('target', '0.0.0.0/0');
     $addRequest->setArgument('comment', 'ПРИМЕР');
     $responses = $this->object->sendSync($addRequest);
     $this->assertEquals(1, count($responses), 'There should be only one response.');
     if (count($responses) === 1 && $responses[-1]->getType() === Response::TYPE_FINAL) {
         $appropriateCharsets = $this->object->setCharset(array(Communicator::CHARSET_REMOTE => 'ISO-8859-1', Communicator::CHARSET_LOCAL => 'UTF-8'));
         $printRequest = new Request('/queue/simple/print');
         $printRequest->setQuery(Query::where('name', TEST_QUEUE_NAME));
         $responses = $this->object->sendSync($printRequest);
         $this->assertEquals(TEST_QUEUE_NAME, $responses[0]->getProperty('name'));
         $this->assertNotEquals('ПРИМЕР', $responses[0]->getProperty('comment'));
         $this->object->setCharset($appropriateCharsets);
         $this->assertNotEquals('ПРИМЕР', $responses[0]->getProperty('comment'));
         $responses = $this->object->sendSync($printRequest);
         $this->assertEquals(TEST_QUEUE_NAME, $responses[0]->getProperty('name'));
         $this->assertEquals('ПРИМЕР', $responses[0]->getProperty('comment'));
         $this->object->setCharset('ISO-8859-1', Communicator::CHARSET_REMOTE);
         $responses = $this->object->sendSync($printRequest);
         $this->assertNotEquals('ПРИМЕР', $responses[0]->getProperty('comment'));
         $this->object->setCharset('ISO-8859-1', Communicator::CHARSET_LOCAL);
         $responses = $this->object->sendSync($printRequest);
         $this->assertNotEquals('ПРИМЕР', $responses[0]->getProperty('comment'));
         $this->object->setCharset($appropriateCharsets);
         $responses = $this->object->sendSync($printRequest);
         $this->assertEquals('ПРИМЕР', $responses[0]->getProperty('comment'));
         $this->object->setStreamingResponses(true);
         $responses = $this->object->sendSync($printRequest);
         $this->assertEquals('ПРИМЕР', stream_get_contents($responses[0]->getProperty('comment')));
         $this->object->setCharset('ISO-8859-1', Communicator::CHARSET_REMOTE);
         $responses = $this->object->sendSync($printRequest);
         $this->assertNotEquals('ПРИМЕР', stream_get_contents($responses[0]->getProperty('comment')));
         $this->object->setCharset('windows-1251');
         $responses = $this->object->sendSync($printRequest);
         $this->assertNotEquals('ПРИМЕР', stream_get_contents($responses[0]->getProperty('comment')));
         $testQueueNameStream = fopen('php://temp', 'r+b');
         fwrite($testQueueNameStream, TEST_QUEUE_NAME);
         rewind($testQueueNameStream);
         $printRequest->setQuery(Query::where('name', $testQueueNameStream));
         $responses = $this->object->sendSync($printRequest);
         $this->assertNotEquals('ПРИМЕР', stream_get_contents($responses[0]->getProperty('comment')));
         $this->object->setCharset($appropriateCharsets);
         $responses = $this->object->sendSync($printRequest);
         $this->assertEquals('ПРИМЕР', stream_get_contents($responses[0]->getProperty('comment')));
         $removeRequest = new Request('/queue/simple/remove');
         $removeRequest->setArgument('numbers', TEST_QUEUE_NAME);
         $responses = $this->object->sendSync($removeRequest);
     }
 }
示例#2
0
 public function testFilePutAndGetContentsStreamed()
 {
     $data1 = 'test';
     $data2 = 'ok';
     $data1s = fopen('php://temp', 'r+b');
     fwrite($data1s, $data1);
     rewind($data1s);
     $data2s = fopen('php://temp', 'r+b');
     fwrite($data2s, $data2);
     rewind($data2s);
     $this->client->setStreamingResponses(true);
     //New and overwite string
     $putResult1 = $this->util->filePutContents(TEST_FILE_NAME, $data1);
     $getResult1 = $this->util->fileGetContents(TEST_FILE_NAME);
     $putResult2 = $this->util->filePutContents(TEST_FILE_NAME, $data2, true);
     $getResult2 = $this->util->fileGetContents(TEST_FILE_NAME);
     $putResult3 = $this->util->filePutContents(TEST_FILE_NAME, $data1);
     $getResult3 = $this->util->fileGetContents(TEST_FILE_NAME);
     $this->assertTrue($putResult1);
     $this->assertSame($data1, stream_get_contents($getResult1));
     $this->assertTrue($putResult2);
     $this->assertSame($data2, stream_get_contents($getResult2));
     $this->assertFalse($putResult3);
     $this->assertSame($data2, stream_get_contents($getResult3));
     //Removal
     $putResult4 = $this->util->filePutContents(TEST_FILE_NAME, null);
     $getResult4 = $this->util->fileGetContents(TEST_FILE_NAME);
     $putResult5 = $this->util->filePutContents(TEST_FILE_NAME, null);
     $this->assertTrue($putResult4);
     $this->assertFalse($getResult4);
     $this->assertFalse($putResult5);
     //New and overwite stream
     $putResult1 = $this->util->filePutContents(TEST_FILE_NAME, $data1s);
     $getResult1 = $this->util->fileGetContents(TEST_FILE_NAME);
     $putResult2 = $this->util->filePutContents(TEST_FILE_NAME, $data2s, true);
     $getResult2 = $this->util->fileGetContents(TEST_FILE_NAME);
     $putResult3 = $this->util->filePutContents(TEST_FILE_NAME, $data1s);
     $getResult3 = $this->util->fileGetContents(TEST_FILE_NAME);
     $this->assertTrue($putResult1);
     $this->assertSame($data1, stream_get_contents($getResult1));
     $this->assertTrue($putResult2);
     $this->assertSame($data2, stream_get_contents($getResult2));
     $this->assertFalse($putResult3);
     $this->assertSame($data2, stream_get_contents($getResult3));
     //Removal
     $putResult4 = $this->util->filePutContents(TEST_FILE_NAME, null);
     $getResult4 = $this->util->fileGetContents(TEST_FILE_NAME);
     $putResult5 = $this->util->filePutContents(TEST_FILE_NAME, null);
     $this->assertTrue($putResult4);
     $this->assertFalse($getResult4);
     $this->assertFalse($putResult5);
     $this->client->setStreamingResponses(false);
 }
示例#3
0
 public function testStreamEquality()
 {
     $request = new Request('/queue/simple/print');
     $request->setQuery(Query::where('target', HOSTNAME_INVALID . '/32'));
     $list = $this->object->sendSync($request);
     $this->assertInstanceOf(ROS_NAMESPACE . '\\ResponseCollection', $list, 'The list is not a collection');
     $this->object->setStreamingResponses(true);
     $streamList = $this->object->sendSync($request);
     $this->assertInstanceOf(ROS_NAMESPACE . '\\ResponseCollection', $streamList, 'The list is not a collection');
     foreach ($list as $index => $response) {
         $streamListArgs = $streamList[$index]->getIterator();
         foreach ($response as $argName => $value) {
             $this->assertArrayHasKey($argName, $streamListArgs, 'Missing argument.');
             $this->assertEquals($value, stream_get_contents($streamListArgs[$argName]), 'Argument values are not equivalent.');
             unset($streamListArgs[$argName]);
         }
         $this->assertEmpty($streamListArgs, 'Extra arguments.');
     }
 }