Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ tests/*.log
tests/*.out
tests/*.php
tests/*.sh
reports/
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: php
php:
- 5.6
- 5.5
- 5.4
- 5.3
Expand All @@ -12,4 +13,4 @@ before_script:
- ./.travis/install_libzookeeper.sh $LIBZOOKEEPER_VERSION

script:
- ./.travis/build.sh $LIBZOOKEEPER_VERSION
- ./.travis/build.sh $LIBZOOKEEPER_VERSION
3 changes: 3 additions & 0 deletions .travis/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions .travis/install_libzookeeper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/connect_with_invalid_param.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Should connect the Zookeeper with invalid parameter
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper();
$client->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
12 changes: 12 additions & 0 deletions tests/construct_retrieve_error_with_invalid_recv.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Should construct and connect the zookeeper
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181', null, -1);
--EXPECTF--
Warning: Zookeeper::__construct(): recv_timeout parameter has to be greater than 0 in %s on line %d
24 changes: 24 additions & 0 deletions tests/create_node.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Should create node
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');

if ($client->exists('/test6')) {
$client->delete('/test6');
}

echo $client->create('/test6', null, array(
array(
'perms' => Zookeeper::PERM_ALL,
'scheme' => 'world',
'id' => 'anyone'
)
), 2);
--EXPECTF--
/test6%d
13 changes: 13 additions & 0 deletions tests/create_node_retrieve_invalid_status_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Should throw error when retrieve invalid status
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
$client->create('/test5', '', array());
--EXPECTF--
Warning: Zookeeper::create(): error: invalid acl in %s on line %d
13 changes: 13 additions & 0 deletions tests/create_node_with_invalid_param.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Should throw error when create node with invalid parameter
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
$client->create('/test5', array());
--EXPECTF--
Warning: Zookeeper::create() expects at least %d parameters, %d given in %s on line %d
13 changes: 13 additions & 0 deletions tests/exists_retrieve_error_with_invalid_param.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Should retrieve error when set invalid parameter
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
$client->exists(10);
--EXPECTF--
Warning: Zookeeper::exists(): error: bad arguments in %s on line %d
13 changes: 13 additions & 0 deletions tests/exists_with_invalid_param.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Should retrieve error when set invalid data in second parameter
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
$client->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
14 changes: 14 additions & 0 deletions tests/remove_invalid_node.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Should delete invalid node
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
echo $client->delete('/10');

--EXPECTF--
Warning: Zookeeper::delete(): error: no node in %s on line %d
22 changes: 22 additions & 0 deletions tests/remove_node.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Should delete node
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
$client->create('/test5', '', array(
array(
'perms' => Zookeeper::PERM_ALL,
'scheme' => 'world',
'id' => 'anyone'
)
));

echo $client->delete('/test5');

--EXPECT--
1
14 changes: 14 additions & 0 deletions tests/remove_node_with_invalid_param.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Should throw erro when delete node with invalid paramater
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
echo $client->delete(array());

--EXPECTF--
Warning: Zookeeper::delete() expects parameter %d to be string, array given in %s on line %d
13 changes: 13 additions & 0 deletions tests/retrieve_client_id.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Should get Zookeeper client id
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
echo implode('-', $client->getClientId());
--EXPECT--
0-
13 changes: 13 additions & 0 deletions tests/retrieve_client_id_with_param.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Get client id should throw error with parameter
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
$client->getClientId(10);
--EXPECTF--
Warning: Zookeeper::getClientId() expects exactly %d parameters, %d given in %s on line %d
13 changes: 13 additions & 0 deletions tests/retrieve_state_with_param.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Get state should throw error when define parameter
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
echo $client->getState('a');
--EXPECTF--
Warning: Zookeeper::getState() expects exactly %d parameters, %d given in %s on line %d
8 changes: 4 additions & 4 deletions tests/retrieve_true_when_exists.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ if (!extension_loaded('zookeeper')) {
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
$client->create('/test1', '', [
[
$client->create('/test1', '', array(
array(
'perms' => Zookeeper::PERM_ALL,
'scheme' => 'world',
'id' => 'anyone'
]
]);
)
));
var_dump(is_array($client->exists('/test1')));
--CLEAN--
<?php
Expand Down
29 changes: 29 additions & 0 deletions tests/retrieve_true_when_exists_with_callback.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Should retrieve true if node exists with callback
--SKIPIF--
<?php
if (!extension_loaded('zookeeper')) {
echo 'Zookeeper extension is not loaded'
};
--FILE--
<?php
$client = new Zookeeper('localhost:2181');
$client->create('/test1', '', array(
array(
'perms' => Zookeeper::PERM_ALL,
'scheme' => 'world',
'id' => 'anyone'
)
));

$callback = function($data) { };
var_dump(is_array($client->exists('/test1', $callback)));
--CLEAN--
<?php
$client = new Zookeeper('localhost:2181');

if ($client->exists('/test1')) {
$client->delete('/test1');
}
--EXPECT--
bool(true)