From 3f518917fe10b35b11eb39713e1f9a4b0a48c003 Mon Sep 17 00:00:00 2001 From: Pierrick Charron Date: Sat, 7 Nov 2009 03:53:33 +0000 Subject: [PATCH] New set of tests --- tests/001-stomp.phpt | 50 ++---------------- tests/002-version.phpt | 6 +-- tests/003-connect/001.phpt | 27 +++++----- tests/003-connect/002.phpt | 12 +++++ tests/004-getSessionId/001.phpt | 10 ++-- tests/005-close/001.phpt | 10 ++-- tests/005-close/002.phpt | 16 ++++++ tests/006-send/001.phpt | 31 ++++++----- tests/006-send/002.phpt | 28 ++++++++++ tests/007-subscribe/001.phpt | 16 +++--- tests/008-unsubscribe/001.phpt | 16 +++--- tests/009-readFrame/001.phpt | 19 +++++++ tests/009-readFrame/002.phpt | 22 ++++++++ tests/010-timeout/001.phpt | 91 ++++++++++++++++++++++++++++++++ tests/010-timeout/002.phpt | 92 +++++++++++++++++++++++++++++++++ tests/011-commit/001.phpt | 42 +++++++++++++++ 16 files changed, 383 insertions(+), 105 deletions(-) create mode 100644 tests/003-connect/002.phpt create mode 100644 tests/005-close/002.phpt create mode 100644 tests/006-send/002.phpt create mode 100644 tests/009-readFrame/001.phpt create mode 100644 tests/009-readFrame/002.phpt create mode 100644 tests/010-timeout/001.phpt create mode 100644 tests/010-timeout/002.phpt create mode 100644 tests/011-commit/001.phpt diff --git a/tests/001-stomp.phpt b/tests/001-stomp.phpt index 5a37654..72278dd 100644 --- a/tests/001-stomp.phpt +++ b/tests/001-stomp.phpt @@ -1,52 +1,10 @@ --TEST-- -Check stomp +Check for stomp presence --SKIPIF-- --FILE-- -' . $msg['body'] . PHP_EOL; - var_dump(stomp_ack($stomp, $msg['headers']['message-id'])); - var_dump(stomp_read_frame($stomp)); - var_dump(stomp_unsubscribe($stomp, $queue)); - var_dump(stomp_close($stomp)); -} - -echo PHP_EOL; - -$stomp = new Stomp('tcp://localhost:61613'); -try { - var_dump($stomp->send($queue, 'test')); - var_dump($stomp->subscribe($queue)); - $msg = $stomp->readFrame(); - echo $msg->command . '=>' . $msg->body . PHP_EOL; - var_dump($stomp->ack($msg->headers['message-id'])); - var_dump($stomp->readFrame()); - var_dump($stomp->unsubscribe($queue)); - var_dump($stomp->disconnect()); -} catch(StompException $e) { -} - + --EXPECT-- -bool(true) -bool(true) -MESSAGE=>test -bool(true) -bool(false) -bool(true) -bool(true) - -bool(true) -bool(true) -MESSAGE=>test -bool(true) -bool(false) -bool(true) -bool(true) +stomp extension is available diff --git a/tests/002-version.phpt b/tests/002-version.phpt index b4b4aa0..63f45f5 100644 --- a/tests/002-version.phpt +++ b/tests/002-version.phpt @@ -1,10 +1,10 @@ --TEST-- -Check stomp_version +Test stomp_version() --SKIPIF-- --FILE-- ---EXPECTREGEX-- -[0-9]\.[0-9]\.[0-9] +--EXPECTF-- +%d.%d.%d diff --git a/tests/003-connect/001.phpt b/tests/003-connect/001.phpt index ddbfd2a..31b48c1 100644 --- a/tests/003-connect/001.phpt +++ b/tests/003-connect/001.phpt @@ -1,19 +1,20 @@ --TEST-- -Check stomp_connect +Test stomp_connect() - URI validation --SKIPIF-- --FILE-- ---EXPECTF-- -Warning: stomp_connect(): Invalid Broker URI in %s on line %d - -Warning: stomp_connect(): Invalid Broker URI in %s on line %d - -Warning: stomp_connect(): Invalid Broker URI in %s on line %d - -Warning: stomp_connect(): Invalid Broker URI scheme in %s on line %d +--EXPECT-- +NULL +string(18) "Invalid Broker URI" +NULL +string(18) "Invalid Broker URI" +NULL +string(18) "Invalid Broker URI" +NULL +string(25) "Invalid Broker URI scheme" diff --git a/tests/003-connect/002.phpt b/tests/003-connect/002.phpt new file mode 100644 index 0000000..e8bd62d --- /dev/null +++ b/tests/003-connect/002.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test stomp_connect() - Test connection +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +resource(%d) of type (stomp connection) +NULL diff --git a/tests/004-getSessionId/001.phpt b/tests/004-getSessionId/001.phpt index 1a82367..9cd0726 100644 --- a/tests/004-getSessionId/001.phpt +++ b/tests/004-getSessionId/001.phpt @@ -1,14 +1,14 @@ --TEST-- -Check stomp_get_session_id +Test stomp_get_session_id() --SKIPIF-- --FILE-- --EXPECTF-- -%s +string(%d) "%s" diff --git a/tests/005-close/001.phpt b/tests/005-close/001.phpt index 8473542..980283e 100644 --- a/tests/005-close/001.phpt +++ b/tests/005-close/001.phpt @@ -1,14 +1,12 @@ --TEST-- -Check stomp_close +Test stomp_close() - tests parameters --SKIPIF-- --FILE-- ---EXPECT-- -close +--EXPECTF-- +Warning: stomp_close() expects parameter 1 to be resource, null given in %s on line %d diff --git a/tests/005-close/002.phpt b/tests/005-close/002.phpt new file mode 100644 index 0000000..2f8fe0d --- /dev/null +++ b/tests/005-close/002.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test stomp_close() +--SKIPIF-- + +--FILE-- + +--EXPECT-- +success +closed diff --git a/tests/006-send/001.phpt b/tests/006-send/001.phpt index f6e806f..0dc5b0b 100644 --- a/tests/006-send/001.phpt +++ b/tests/006-send/001.phpt @@ -1,21 +1,28 @@ --TEST-- -Check stomp_send +Test stomp_send() - tests parameters --SKIPIF-- - --FILE-- send('', array()); -} catch(StompException $e) { - echo $e->getMessage(); -} +$link = stomp_connect(); + +stomp_send($link, '', array()); +stomp_send($link, '/queue/test-06', array()); +var_dump(stomp_send($link, '/queue/test-06', '')); +var_dump(stomp_send($link, '/queue/test-06', 'A realMessage')); +var_dump(stomp_send($link, '/queue/test-06', 'بياريك شارون')); +var_dump(stomp_send($link, 'بياريك شارون', 'بياريك شارون', array('receipt' => 'message-123')), stomp_error($link)); -$s->send('/queue/test', array()); ?> --EXPECTF-- -Destination can not be empty -Fatal error: Stomp::send(): Expects parameter 2 to be a string or a StompFrame object. in %s on line %d +Warning: stomp_send(): Destination can not be empty in %s on line %d + +Warning: stomp_send(): Expects parameter %d to be a string or a StompFrame object. in %s on line %d +bool(true) +bool(true) +bool(true) +bool(false) +string(%d) "%s" diff --git a/tests/006-send/002.phpt b/tests/006-send/002.phpt new file mode 100644 index 0000000..239e204 --- /dev/null +++ b/tests/006-send/002.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test stomp::send() - tests parameters +--SKIPIF-- + +--FILE-- +send('', array()); +$s->send('/queue/test-06', array()); +var_dump($s->send('/queue/test-06', '')); +var_dump($s->send('/queue/test-06', 'A realMessage')); +var_dump($s->send('/queue/test-06', 'بياريك شارون')); +var_dump($s->send('بياريك شارون', 'بياريك شارون', array('receipt' => 'message-123')), $s->error()); + +?> +--EXPECTF-- +Warning: Stomp::send(): Destination can not be empty in %s on line %d + +Warning: Stomp::send(): Expects parameter %d to be a string or a StompFrame object. in %s on line %d +bool(true) +bool(true) +bool(true) +bool(false) +string(%d) "%s" diff --git a/tests/007-subscribe/001.phpt b/tests/007-subscribe/001.phpt index 773f3ce..51d459c 100644 --- a/tests/007-subscribe/001.phpt +++ b/tests/007-subscribe/001.phpt @@ -1,21 +1,17 @@ --TEST-- -Check stomp_subscribe +Test Stomp::subscribe() --SKIPIF-- --FILE-- subscribe('', array()); -} catch(StompException $e) { - echo $e->getMessage(); -} - +$s = new Stomp(); +$s->subscribe('', array()); $s->subscribe('/queue/test', 'string'); ?> --EXPECTF-- -Destination can not be empty +Warning: Stomp::subscribe(): Destination can not be empty in %s on line %d + Catchable fatal error: Argument 2 passed to Stomp::subscribe() must be an array, string given in %s on line %d diff --git a/tests/008-unsubscribe/001.phpt b/tests/008-unsubscribe/001.phpt index 5be7d53..ee1e56b 100644 --- a/tests/008-unsubscribe/001.phpt +++ b/tests/008-unsubscribe/001.phpt @@ -1,21 +1,17 @@ --TEST-- -Check stomp_unsubscribe +Test Stomp::unsubscribe() --SKIPIF-- --FILE-- unsubscribe('', array()); -} catch(StompException $e) { - echo $e->getMessage(); -} - +$s = new Stomp(); +$s->unsubscribe('', array()); $s->unsubscribe('/queue/test', 'string'); ?> --EXPECTF-- -Destination can not be empty +Warning: Stomp::unsubscribe(): Destination can not be empty in %s on line %d + Catchable fatal error: Argument 2 passed to Stomp::unsubscribe() must be an array, string given in %s on line %d diff --git a/tests/009-readFrame/001.phpt b/tests/009-readFrame/001.phpt new file mode 100644 index 0000000..3d4154a --- /dev/null +++ b/tests/009-readFrame/001.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test stomp::readFrame() - tests functionnality and parameters +--SKIPIF-- + +--FILE-- +send('/queue/test-09', 'A test Message'); +$s->subscribe('/queue/test-09'); +var_dump($s->readFrame()->body); +var_dump($s->readFrame('frame')); + +?> +--EXPECTF-- +string(14) "A test Message" +bool(false) diff --git a/tests/009-readFrame/002.phpt b/tests/009-readFrame/002.phpt new file mode 100644 index 0000000..48246c1 --- /dev/null +++ b/tests/009-readFrame/002.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test stomp_read_frame() - test functionnality and parameters +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(14) "A test Message" + +Warning: stomp_read_frame() expects exactly 1 parameter, 2 given in %s on line %d +NULL diff --git a/tests/010-timeout/001.phpt b/tests/010-timeout/001.phpt new file mode 100644 index 0000000..8256baa --- /dev/null +++ b/tests/010-timeout/001.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test Stomp::getReadTimout() and Stomp::setReadTimeout() - tests functionnality and parameters +--INI-- +stomp.default_read_timeout_sec=5 +stomp.default_read_timeout_usec=5 +--SKIPIF-- + +--FILE-- +getReadTimeout()); + +// Set read timout with an integer as seconds +var_dump($s->setReadTimeout(10)); +// Second test, read supposed to return 10.0 +var_dump($s->getReadTimeout()); + +// Set read timout with an integer as seconds +var_dump($s->setReadTimeout(10, 5)); +// Third test, read supposed to return 10.5 +var_dump($s->getReadTimeout()); + +// Set read timout with the first param as a string, supposed to trigger a warning +var_dump($s->setReadTimeout('')); +// Fourth test, read supposed to get the last value set : 10.5 +var_dump($s->getReadTimeout()); + +// Set read timout with the second param as a string, supposed to trigger a warning +var_dump($s->setReadTimeout(10, '')); +// Fourth test, read supposed to get the last value set : 10.5 +var_dump($s->getReadTimeout()); + +// Set read timout with the params as null +var_dump($s->setReadTimeout(null, null)); +// Fifth test, read supposed to get the last value set : 0.0 +var_dump($s->getReadTimeout()); + + +unset($s); +?> +--EXPECTF-- +array(2) { + ["sec"]=> + int(5) + ["usec"]=> + int(5) +} +NULL +array(2) { + ["sec"]=> + int(10) + ["usec"]=> + int(0) +} +NULL +array(2) { + ["sec"]=> + int(10) + ["usec"]=> + int(5) +} + +Warning: Stomp::setReadTimeout() expects parameter 1 to be long, string given in %s on line %d +NULL +array(2) { + ["sec"]=> + int(10) + ["usec"]=> + int(5) +} + +Warning: Stomp::setReadTimeout() expects parameter 2 to be long, string given in %s on line %d +NULL +array(2) { + ["sec"]=> + int(10) + ["usec"]=> + int(5) +} +NULL +array(2) { + ["sec"]=> + int(0) + ["usec"]=> + int(0) +} diff --git a/tests/010-timeout/002.phpt b/tests/010-timeout/002.phpt new file mode 100644 index 0000000..65d3c28 --- /dev/null +++ b/tests/010-timeout/002.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test stomp_get_read_timout() and stomp_set_read_timeout() - tests functionnality and parameters +--INI-- +stomp.default_read_timeout_sec=5 +stomp.default_read_timeout_usec=5 +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +array(2) { + ["sec"]=> + int(5) + ["usec"]=> + int(5) +} +NULL +array(2) { + ["sec"]=> + int(10) + ["usec"]=> + int(0) +} +NULL +array(2) { + ["sec"]=> + int(10) + ["usec"]=> + int(5) +} + +Warning: stomp_set_read_timeout() expects parameter 2 to be long, string given in %s on line %d +NULL +array(2) { + ["sec"]=> + int(10) + ["usec"]=> + int(5) +} + +Warning: stomp_set_read_timeout() expects parameter 3 to be long, string given in %s on line %d +NULL +array(2) { + ["sec"]=> + int(10) + ["usec"]=> + int(5) +} +NULL +array(2) { + ["sec"]=> + int(0) + ["usec"]=> + int(0) +} + diff --git a/tests/011-commit/001.phpt b/tests/011-commit/001.phpt new file mode 100644 index 0000000..caf362b --- /dev/null +++ b/tests/011-commit/001.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test Stomp::commit() - tests functionnality and parameters +--SKIPIF-- + +--FILE-- +begin('t1')); + +// sends a message to the queue and specifies a good transaction +var_dump($s->send('/queue/test-011-commit', 'bar', array('transaction' => 't1'))); + +// sends a message to the queue and asks for a receipt +$s->send('/queue/test-011-commit', 'bar', array('transaction' => 't2', 'receipt' => 'tptp')); +var_dump($s->error()); + +// commits a valid transaction +var_dump($s->commit('t1')); + +// commits non valid transaction (null as a parameter) and asks for a receipt +var_dump($s->commit(null, array('receipt' => 'commit-key'))); +var_dump($s->commit(null)); + +// commits a non valid transaction (a transaction id that does not exist) and asks for a receipt +$s->commit('t2', array('receipt' => 'commit-key')); +var_dump($s->error()); + +unset($s); +?> +--EXPECTF-- +bool(true) +bool(true) +string(%d) "Invalid transaction id: %s" +bool(true) +bool(false) +bool(true) +string(%d) "Must specify the transaction you are committing"