From 5bf64c478067db5973be6ac5b2aafbcdc5ad7f98 Mon Sep 17 00:00:00 2001 From: Fabio Ribeiro Date: Mon, 18 May 2015 23:44:24 -0300 Subject: [PATCH 1/3] Testing * Create tests for clientId, getState and connect methods * Tests for create, remove and exists nodes * Constructor recv test error --- tests/connect_with_invalid_param.phpt | 13 +++++++++ ...ruct_retrieve_error_with_invalid_recv.phpt | 12 ++++++++ tests/create_node.phpt | 24 +++++++++++++++ ...te_node_retrieve_invalid_status_error.phpt | 13 +++++++++ tests/create_node_with_invalid_param.phpt | 13 +++++++++ ...sts_retrieve_error_with_invalid_param.phpt | 13 +++++++++ tests/exists_with_invalid_param.phpt | 13 +++++++++ tests/remove_invalid_node.phpt | 14 +++++++++ tests/remove_node.phpt | 22 ++++++++++++++ tests/remove_node_with_invalid_param.phpt | 14 +++++++++ tests/retrieve_client_id.phpt | 13 +++++++++ tests/retrieve_client_id_with_param.phpt | 13 +++++++++ tests/retrieve_state_with_param.phpt | 13 +++++++++ ...trieve_true_when_exists_with_callback.phpt | 29 +++++++++++++++++++ 14 files changed, 219 insertions(+) create mode 100644 tests/connect_with_invalid_param.phpt create mode 100644 tests/construct_retrieve_error_with_invalid_recv.phpt create mode 100644 tests/create_node.phpt create mode 100644 tests/create_node_retrieve_invalid_status_error.phpt create mode 100644 tests/create_node_with_invalid_param.phpt create mode 100644 tests/exists_retrieve_error_with_invalid_param.phpt create mode 100644 tests/exists_with_invalid_param.phpt create mode 100644 tests/remove_invalid_node.phpt create mode 100644 tests/remove_node.phpt create mode 100644 tests/remove_node_with_invalid_param.phpt create mode 100644 tests/retrieve_client_id.phpt create mode 100644 tests/retrieve_client_id_with_param.phpt create mode 100644 tests/retrieve_state_with_param.phpt create mode 100644 tests/retrieve_true_when_exists_with_callback.phpt diff --git a/tests/connect_with_invalid_param.phpt b/tests/connect_with_invalid_param.phpt new file mode 100644 index 0000000..fa3fb05 --- /dev/null +++ b/tests/connect_with_invalid_param.phpt @@ -0,0 +1,13 @@ +--TEST-- +Should connect the Zookeeper with invalid parameter +--SKIPIF-- +connect(1.0, 10); +--EXPECTF-- +Warning: Zookeeper::connect() expects parameter %d to be a valid callback, no array or string given in %s on line %d diff --git a/tests/construct_retrieve_error_with_invalid_recv.phpt b/tests/construct_retrieve_error_with_invalid_recv.phpt new file mode 100644 index 0000000..cf1ab25 --- /dev/null +++ b/tests/construct_retrieve_error_with_invalid_recv.phpt @@ -0,0 +1,12 @@ +--TEST-- +Should construct and connect the zookeeper +--SKIPIF-- +exists('/test6')) { + $client->delete('/test6'); +} + +echo $client->create('/test6', null, [ + [ + 'perms' => Zookeeper::PERM_ALL, + 'scheme' => 'world', + 'id' => 'anyone' + ] +], 2); +--EXPECTF-- +/test6%d diff --git a/tests/create_node_retrieve_invalid_status_error.phpt b/tests/create_node_retrieve_invalid_status_error.phpt new file mode 100644 index 0000000..4ecf219 --- /dev/null +++ b/tests/create_node_retrieve_invalid_status_error.phpt @@ -0,0 +1,13 @@ +--TEST-- +Should throw error when retrieve invalid status +--SKIPIF-- +create('/test5', '', []); +--EXPECTF-- +Warning: Zookeeper::create(): error: invalid acl in %s on line %d diff --git a/tests/create_node_with_invalid_param.phpt b/tests/create_node_with_invalid_param.phpt new file mode 100644 index 0000000..7bd8d9a --- /dev/null +++ b/tests/create_node_with_invalid_param.phpt @@ -0,0 +1,13 @@ +--TEST-- +Should throw error when create node with invalid parameter +--SKIPIF-- +create('/test5', []); +--EXPECTF-- +Warning: Zookeeper::create() expects at least %d parameters, %d given in %s on line %d diff --git a/tests/exists_retrieve_error_with_invalid_param.phpt b/tests/exists_retrieve_error_with_invalid_param.phpt new file mode 100644 index 0000000..68d4e1b --- /dev/null +++ b/tests/exists_retrieve_error_with_invalid_param.phpt @@ -0,0 +1,13 @@ +--TEST-- +Should retrieve error when set invalid parameter +--SKIPIF-- +exists(10); +--EXPECTF-- +Warning: Zookeeper::exists(): error: bad arguments in %s on line %d diff --git a/tests/exists_with_invalid_param.phpt b/tests/exists_with_invalid_param.phpt new file mode 100644 index 0000000..80f97c4 --- /dev/null +++ b/tests/exists_with_invalid_param.phpt @@ -0,0 +1,13 @@ +--TEST-- +Should retrieve error when set invalid data in second parameter +--SKIPIF-- +exists('/test', 1.0); +--EXPECTF-- +Warning: Zookeeper::exists() expects parameter %d to be a valid callback, no array or string given in %s on line %d diff --git a/tests/remove_invalid_node.phpt b/tests/remove_invalid_node.phpt new file mode 100644 index 0000000..c76e4d1 --- /dev/null +++ b/tests/remove_invalid_node.phpt @@ -0,0 +1,14 @@ +--TEST-- +Should delete invalid node +--SKIPIF-- +delete('/10'); + +--EXPECTF-- +Warning: Zookeeper::delete(): error: no node in %s on line %d diff --git a/tests/remove_node.phpt b/tests/remove_node.phpt new file mode 100644 index 0000000..55dbd0e --- /dev/null +++ b/tests/remove_node.phpt @@ -0,0 +1,22 @@ +--TEST-- +Should delete node +--SKIPIF-- +create('/test5', '', [ + [ + 'perms' => Zookeeper::PERM_ALL, + 'scheme' => 'world', + 'id' => 'anyone' + ] +]); + +echo $client->delete('/test5'); + +--EXPECT-- +1 diff --git a/tests/remove_node_with_invalid_param.phpt b/tests/remove_node_with_invalid_param.phpt new file mode 100644 index 0000000..1d54bc7 --- /dev/null +++ b/tests/remove_node_with_invalid_param.phpt @@ -0,0 +1,14 @@ +--TEST-- +Should throw erro when delete node with invalid paramater +--SKIPIF-- +delete([]); + +--EXPECTF-- +Warning: Zookeeper::delete() expects parameter %d to be string, array given in %s on line %d diff --git a/tests/retrieve_client_id.phpt b/tests/retrieve_client_id.phpt new file mode 100644 index 0000000..ede1c66 --- /dev/null +++ b/tests/retrieve_client_id.phpt @@ -0,0 +1,13 @@ +--TEST-- +Should get Zookeeper client id +--SKIPIF-- +getClientId()); +--EXPECT-- +0- diff --git a/tests/retrieve_client_id_with_param.phpt b/tests/retrieve_client_id_with_param.phpt new file mode 100644 index 0000000..3138b22 --- /dev/null +++ b/tests/retrieve_client_id_with_param.phpt @@ -0,0 +1,13 @@ +--TEST-- +Get client id should throw error with parameter +--SKIPIF-- +getClientId(10); +--EXPECTF-- +Warning: Zookeeper::getClientId() expects exactly %d parameters, %d given in %s on line %d diff --git a/tests/retrieve_state_with_param.phpt b/tests/retrieve_state_with_param.phpt new file mode 100644 index 0000000..4474e84 --- /dev/null +++ b/tests/retrieve_state_with_param.phpt @@ -0,0 +1,13 @@ +--TEST-- +Get state should throw error when define parameter +--SKIPIF-- +getState('a'); +--EXPECTF-- +Warning: Zookeeper::getState() expects exactly %d parameters, %d given in %s on line %d diff --git a/tests/retrieve_true_when_exists_with_callback.phpt b/tests/retrieve_true_when_exists_with_callback.phpt new file mode 100644 index 0000000..bac2a7e --- /dev/null +++ b/tests/retrieve_true_when_exists_with_callback.phpt @@ -0,0 +1,29 @@ +--TEST-- +Should retrieve true if node exists with callback +--SKIPIF-- +create('/test1', '', [ + [ + 'perms' => Zookeeper::PERM_ALL, + 'scheme' => 'world', + 'id' => 'anyone' + ] +]); + +$callback = function($data) { }; +var_dump(is_array($client->exists('/test1', $callback))); +--CLEAN-- +exists('/test1')) { + $client->delete('/test1'); +} +--EXPECT-- +bool(true) From 7b6cf7c904a2a2796571bd36647a0d00d9b25e8a Mon Sep 17 00:00:00 2001 From: Fabio Ribeiro Date: Tue, 19 May 2015 00:48:19 -0300 Subject: [PATCH 2/3] Ignoring * Ignore reports folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 270777e..b00eaf2 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,4 @@ tests/*.log tests/*.out tests/*.php tests/*.sh +reports/ From 24125be4c17d1264ad6f5cef230ecba528d38ede Mon Sep 17 00:00:00 2001 From: Fabio Ribeiro Date: Tue, 19 May 2015 00:51:40 -0300 Subject: [PATCH 3/3] Travis CI * Added dev-tools test script for running into Travis-CI --- .travis.yml | 3 ++- .travis/build.sh | 3 +++ .travis/install_libzookeeper.sh | 2 ++ tests/create_node.phpt | 8 ++++---- tests/create_node_retrieve_invalid_status_error.phpt | 2 +- tests/create_node_with_invalid_param.phpt | 2 +- tests/remove_node.phpt | 8 ++++---- tests/remove_node_with_invalid_param.phpt | 2 +- tests/retrieve_true_when_exists.phpt | 8 ++++---- tests/retrieve_true_when_exists_with_callback.phpt | 8 ++++---- 10 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4b2623c..631be7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: php php: + - 5.6 - 5.5 - 5.4 - 5.3 @@ -12,4 +13,4 @@ before_script: - ./.travis/install_libzookeeper.sh $LIBZOOKEEPER_VERSION script: - - ./.travis/build.sh $LIBZOOKEEPER_VERSION \ No newline at end of file + - ./.travis/build.sh $LIBZOOKEEPER_VERSION diff --git a/.travis/build.sh b/.travis/build.sh index bd773db..c24724a 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -6,4 +6,7 @@ LIBZOOKEEPER_PREFIX=${HOME}/libzookeeper-${LIBZOOKEEPER_VERSION} phpize || exit 1 ./configure --with-libzookeeper-dir=${LIBZOOKEEPER_PREFIX} || exit 1 make || exit 1 +make install || exit 1 +echo "extension=zookeeper.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini +./dev-tools/test.sh diff --git a/.travis/install_libzookeeper.sh b/.travis/install_libzookeeper.sh index f13c7ed..a35abee 100755 --- a/.travis/install_libzookeeper.sh +++ b/.travis/install_libzookeeper.sh @@ -6,6 +6,8 @@ LIBZOOKEEPER_PREFIX=${HOME}/lib${PACKAGE_NAME} wget http://apache.fayea.com/zookeeper/${PACKAGE_NAME}/${PACKAGE_NAME}.tar.gz || exit 1 tar xvf ${PACKAGE_NAME}.tar.gz || exit 1 +mv ${PACKAGE_NAME}/conf/zoo_sample.cfg ${PACKAGE_NAME}/conf/zoo.cfg +${PACKAGE_NAME}/bin/zkServer.sh start cd ${PACKAGE_NAME}/src/c ./configure --prefix=${LIBZOOKEEPER_PREFIX} || exit 1 make || exit 1 diff --git a/tests/create_node.phpt b/tests/create_node.phpt index bd7e491..6f81f2e 100644 --- a/tests/create_node.phpt +++ b/tests/create_node.phpt @@ -13,12 +13,12 @@ if ($client->exists('/test6')) { $client->delete('/test6'); } -echo $client->create('/test6', null, [ - [ +echo $client->create('/test6', null, array( + array( 'perms' => Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone' - ] -], 2); + ) +), 2); --EXPECTF-- /test6%d diff --git a/tests/create_node_retrieve_invalid_status_error.phpt b/tests/create_node_retrieve_invalid_status_error.phpt index 4ecf219..76517e4 100644 --- a/tests/create_node_retrieve_invalid_status_error.phpt +++ b/tests/create_node_retrieve_invalid_status_error.phpt @@ -8,6 +8,6 @@ if (!extension_loaded('zookeeper')) { --FILE-- create('/test5', '', []); +$client->create('/test5', '', array()); --EXPECTF-- Warning: Zookeeper::create(): error: invalid acl in %s on line %d diff --git a/tests/create_node_with_invalid_param.phpt b/tests/create_node_with_invalid_param.phpt index 7bd8d9a..2e9fc1d 100644 --- a/tests/create_node_with_invalid_param.phpt +++ b/tests/create_node_with_invalid_param.phpt @@ -8,6 +8,6 @@ if (!extension_loaded('zookeeper')) { --FILE-- create('/test5', []); +$client->create('/test5', array()); --EXPECTF-- Warning: Zookeeper::create() expects at least %d parameters, %d given in %s on line %d diff --git a/tests/remove_node.phpt b/tests/remove_node.phpt index 55dbd0e..bfb314c 100644 --- a/tests/remove_node.phpt +++ b/tests/remove_node.phpt @@ -8,13 +8,13 @@ if (!extension_loaded('zookeeper')) { --FILE-- create('/test5', '', [ - [ +$client->create('/test5', '', array( + array( 'perms' => Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone' - ] -]); + ) +)); echo $client->delete('/test5'); diff --git a/tests/remove_node_with_invalid_param.phpt b/tests/remove_node_with_invalid_param.phpt index 1d54bc7..d4e1576 100644 --- a/tests/remove_node_with_invalid_param.phpt +++ b/tests/remove_node_with_invalid_param.phpt @@ -8,7 +8,7 @@ if (!extension_loaded('zookeeper')) { --FILE-- delete([]); +echo $client->delete(array()); --EXPECTF-- Warning: Zookeeper::delete() expects parameter %d to be string, array given in %s on line %d diff --git a/tests/retrieve_true_when_exists.phpt b/tests/retrieve_true_when_exists.phpt index f37e653..57b3705 100644 --- a/tests/retrieve_true_when_exists.phpt +++ b/tests/retrieve_true_when_exists.phpt @@ -8,13 +8,13 @@ if (!extension_loaded('zookeeper')) { --FILE-- create('/test1', '', [ - [ +$client->create('/test1', '', array( + array( 'perms' => Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone' - ] -]); + ) +)); var_dump(is_array($client->exists('/test1'))); --CLEAN-- create('/test1', '', [ - [ +$client->create('/test1', '', array( + array( 'perms' => Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone' - ] -]); + ) +)); $callback = function($data) { }; var_dump(is_array($client->exists('/test1', $callback)));