Skip to content

Commit

Permalink
Raise exception for update by an absent field name
Browse files Browse the repository at this point in the history
It seems the exception "No field '<...>' defined" was not raised since
introducing of named fields support in
31cf8a8 ('Next version of tarantool-php
for php7').

There is the test for this case
(DMLTest::test_08_update_error_nosuchfield), but it accepts any error
message, because of a typo in an annotation name. Fixed this typo.

The problem was found by this test when the annotation was replaced by a
call in order to eliminate a phpunit-8 warning and to support phpunit-9.
This change will land in a next commit.
  • Loading branch information
Totktonada committed Mar 28, 2020
1 parent f913c46 commit b3846f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/tarantool.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,10 @@ int get_fieldno_by_name(tarantool_connection *obj, uint32_t space_no,
fid = tarantool_schema_get_fid_by_string(obj->schema, space_no,
Z_STRVAL_P(name),
Z_STRLEN_P(name));
if (fid == FAILURE)
if (fid == FAILURE) {
THROW_EXC("No field '%s' defined", Z_STRVAL_P(name));
return FAILURE;
}
return fid + 1;
}

Expand Down Expand Up @@ -825,6 +827,8 @@ int tarantool_uwrite_op(tarantool_connection *obj, zval *op, uint32_t pos,
goto cleanup;
}
op_pos = get_fieldno_by_name(obj, space_id, z_op_pos);
if (op_pos == FAILURE)
goto cleanup;
zval *oparg, *splice_len, *splice_val;
switch(Z_STRVAL_P(opstr)[0]) {
case ':':
Expand Down
10 changes: 5 additions & 5 deletions test/DMLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function test_07_update_no_error() {

/**
* @expectedException TarantoolException
* @ExpectedExceptionMessage No field 'nosuchfield' defined
* @expectedExceptionMessage No field 'nosuchfield' defined
*/
public function test_08_update_error_nosuchfield() {
self::$tarantool->update("test", 0, array(
Expand All @@ -185,7 +185,7 @@ public function test_08_update_error_nosuchfield() {

/**
* @expectedException TarantoolException
* @ExpectedExceptionMessage Five fields
* @expectedExceptionMessage Five fields
*/
public function test_08_update_error() {
self::$tarantool->update("test", 0, array(
Expand All @@ -200,7 +200,7 @@ public function test_08_update_error() {

/**
* @expectedException TarantoolException
* @ExpectedExceptionMessage Field OP must be provided
* @expectedExceptionMessage Field OP must be provided
*/
public function test_09_update_error() {
self::$tarantool->update("test", 0, array(
Expand All @@ -214,7 +214,7 @@ public function test_09_update_error() {

/**
* @expectedException TarantoolException
* @ExpectedExceptionMessage Field OP must be provided
* @expectedExceptionMessage Field OP must be provided
*/
public function test_10_update_error() {
self::$tarantool->update("test", 0, array(
Expand All @@ -227,7 +227,7 @@ public function test_10_update_error() {

/**
* @expectedException TarantoolException
* @ExpectedExceptionMessage Three fields must be provided
* @expectedExceptionMessage Three fields must be provided
*/
public function test_11_update_error() {
self::$tarantool->update("test", 0,
Expand Down

0 comments on commit b3846f6

Please sign in to comment.