Skip to content

Commit 1c23228

Browse files
author
Bulat Shakirzyanov
committed
return NULL for all unspecified execution options
1 parent cf8546d commit 1c23228

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

ext/src/Cassandra/ExecutionOptions.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,30 @@ PHP_METHOD(ExecutionOptions, __get)
8282
self = (cassandra_execution_options*) zend_object_store_get_object(getThis() TSRMLS_CC);
8383

8484
if (name_len == 11 && strncmp("consistency", name, name_len) == 0) {
85+
if (self->consistency == -1) {
86+
RETURN_NULL();
87+
}
8588
RETURN_LONG(self->consistency);
8689
} else if (name_len == 17 && strncmp("serialConsistency", name, name_len) == 0) {
90+
if (self->serial_consistency == -1) {
91+
RETURN_NULL();
92+
}
8793
RETURN_LONG(self->serial_consistency);
8894
} else if (name_len == 8 && strncmp("pageSize", name, name_len) == 0) {
95+
if (self->page_size == -1) {
96+
RETURN_NULL();
97+
}
8998
RETURN_LONG(self->page_size);
9099
} else if (name_len == 7 && strncmp("timeout", name, name_len) == 0) {
91-
if (self->timeout) {
92-
RETURN_ZVAL(self->timeout, 1, 0);
93-
} else {
100+
if (self->timeout == NULL) {
94101
RETURN_NULL();
95102
}
103+
RETURN_ZVAL(self->timeout, 1, 0);
96104
} else if (name_len == 9 && strncmp("arguments", name, name_len) == 0) {
97-
if (self->arguments) {
98-
RETURN_ZVAL(self->arguments, 1, 0);
99-
} else {
105+
if (self->arguments == NULL) {
100106
RETURN_NULL();
101107
}
108+
RETURN_ZVAL(self->arguments, 1, 0);
102109
}
103110
}
104111

tests/Cassandra/ExecutionOptionsTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@ public function testAllowsRetrievingSettingsByName()
2323
$this->assertEquals(15, $options->timeout);
2424
$this->assertEquals(array('a', 1, 'b', 2, 'c', 3), $options->arguments);
2525
}
26+
27+
public function testReturnsNullValuesWhenRetrievingUndefinedSettingsByName()
28+
{
29+
$options = new ExecutionOptions(array());
30+
31+
$this->assertNull($options->consistency);
32+
$this->assertNull($options->serialConsistency);
33+
$this->assertNull($options->pageSize);
34+
$this->assertNull($options->timeout);
35+
$this->assertNull($options->arguments);
36+
}
2637
}

0 commit comments

Comments
 (0)