Skip to content

Commit

Permalink
default field configuration fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Sep 24, 2024
1 parent b32e953 commit eec6f77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Space.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function addProperty(string $name, string $type, array $config = [])
throw new Exception("Duplicate property $name");
}

if (array_key_exists('default', $config) && !is_string($config['default'])) {
$config['default'] = (string) $config['default'];
}

$this->format[] = $config;
$this->mapper->client->call("box.space.$this->name:format", $this->format);

Expand Down
9 changes: 9 additions & 0 deletions tests/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public function createMapper(
return $mapper;
}

public function testDefaults()
{
$mapper = $this->createMapper();
$tester = $mapper->createSpace('tester');
$tester->addProperty('id', 'unsigned');
$tester->addProperty('number', 'unsigned', ['default' => 0]);
$tester->addProperty('string', 'string', ['default' => '']);
}

public function testCache()
{
$mapper = $this->createMapper(dropUserSpaces: false);
Expand Down

0 comments on commit eec6f77

Please sign in to comment.