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/ 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/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, array( + array( + '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..76517e4 --- /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', '', 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 new file mode 100644 index 0000000..2e9fc1d --- /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', array()); +--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..bfb314c --- /dev/null +++ b/tests/remove_node.phpt @@ -0,0 +1,22 @@ +--TEST-- +Should delete node +--SKIPIF-- +create('/test5', '', array( + array( + '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..d4e1576 --- /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(array()); + +--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.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', '', array( + array( + '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)