Skip to content

Commit 4d255dc

Browse files
committed
boolean support
1 parent 79979f8 commit 4d255dc

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

src/Plugin/Annotation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ private function getTarantoolType(string $type) : string
374374
'array' => '*',
375375
'float' => 'number',
376376
'int' => 'unsigned',
377+
'bool' => 'boolean'
377378
];
378379
}
379380

src/Schema.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ public function createSpace(string $space, array $config = []) : Space
6666

6767
public function getDefaultValue(string $type)
6868
{
69-
switch ($type) {
70-
case 'STR':
71-
case 'STRING':
69+
switch (strtolower($type)) {
7270
case 'str':
7371
case 'string':
7472
return (string) null;
7573

74+
case 'bool':
75+
case 'boolean':
76+
return (bool) null;
77+
7678
case 'double':
7779
case 'float':
7880
case 'number':
7981
return (float) null;
8082

8183
case 'integer':
82-
case 'INTEGER':
8384
case 'unsigned':
84-
case 'UNSIGNED':
8585
case 'num':
8686
case 'NUM':
8787
return (int) null;
@@ -94,9 +94,7 @@ public function formatValue(string $type, $value)
9494
if (is_null($value)) {
9595
return null;
9696
}
97-
switch ($type) {
98-
case 'STR':
99-
case 'STRING':
97+
switch (strtolower($type)) {
10098
case 'str':
10199
case 'string':
102100
return (string) $value;
@@ -106,10 +104,12 @@ public function formatValue(string $type, $value)
106104
case 'number':
107105
return (float) $value;
108106

107+
case 'bool':
108+
case 'boolean':
109+
return (bool) $value;
110+
109111
case 'integer':
110-
case 'INTEGER':
111112
case 'unsigned':
112-
case 'UNSIGNED':
113113
case 'num':
114114
case 'NUM':
115115
return (int) $value;

tests/AnnotationTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ public function testMixedClassMap()
2929
$this->assertInstanceOf('Entity\\Post', $hello);
3030
}
3131

32+
public function testBoolean()
33+
{
34+
$mapper = $this->createMapper();
35+
$this->clean($mapper);
36+
$mapper->getPlugin(Sequence::class);
37+
38+
$annotation = $mapper->getPlugin(Annotation::class);
39+
$annotation->register('Entity\\Paycode');
40+
$annotation->migrate();
41+
$active = $mapper->getSchema()->getSpace('paycode')->getProperty('active');
42+
$this->assertSame($active['type'], 'boolean');
43+
44+
$paycode = $mapper->create('paycode', [
45+
'active' => 1,
46+
]);
47+
$this->assertNotNull($paycode->id);
48+
$this->assertTrue($paycode->active);
49+
50+
$paycode = $mapper->create('paycode', [
51+
'active' => 0,
52+
]);
53+
$this->assertNotNull($paycode->id);
54+
$this->assertFalse($paycode->active);
55+
}
56+
3257
public function testInheritance()
3358
{
3459
$mapper = $this->createMapper();

tests/Entity/Paycode.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ class Paycode extends MapperEntity
2121
* @default 0.5
2222
*/
2323
public $factor;
24+
25+
/**
26+
* @var bool
27+
*/
28+
public $active;
2429
}

0 commit comments

Comments
 (0)