Skip to content

Commit

Permalink
Allow setting field values to null (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpedrie authored and dwsupplee committed Aug 1, 2018
1 parent 9184904 commit 89506e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 0 additions & 2 deletions Spanner/src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ public function __construct(ConnectionInterface $connection, $returnInt64AsObjec
*/
public function mutation($operation, $table, $mutation)
{
$mutation = $this->arrayFilterRemoveNull($mutation);

return [
$operation => [
'table' => $table,
Expand Down
26 changes: 26 additions & 0 deletions Spanner/tests/System/WriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,30 @@ public function timestamps()
[$r->newInstanceArgs($this->parseTimeString($str .'.101999119Z'))],
];
}

public function testSetFieldToNull()
{
$id = $this->randId();
$str = base64_encode(random_bytes(rand(100, 9999)));
$row = self::$database->insert(self::TABLE_NAME, [
'id' => $id,
'stringField' => $str
]);

self::$database->update(self::TABLE_NAME, [
'id' => $id,
'stringField' => null
]);

$res = self::$database->execute(
'SELECT stringField FROM '. self::TABLE_NAME .' WHERE id = @id',
[
'parameters' => [
'id' => $id
]
]
);

$this->assertNull($res->rows()->current()['stringField']);
}
}
7 changes: 4 additions & 3 deletions Spanner/tests/Unit/OperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ public function setUp()
public function testMutation()
{
$res = $this->operation->mutation(Operation::OP_INSERT, 'Posts', [
'foo' => 'bar'
'foo' => 'bar',
'baz' => null
]);

$this->assertEquals(Operation::OP_INSERT, array_keys($res)[0]);
$this->assertEquals('Posts', $res[Operation::OP_INSERT]['table']);
$this->assertEquals('foo', $res[Operation::OP_INSERT]['columns'][0]);
$this->assertEquals('bar', $res[Operation::OP_INSERT]['values'][0]);
$this->assertEquals(['foo', 'baz'], $res[Operation::OP_INSERT]['columns']);
$this->assertEquals(['bar', null], $res[Operation::OP_INSERT]['values']);
}

public function testDeleteMutation()
Expand Down

0 comments on commit 89506e2

Please sign in to comment.