Skip to content

Commit 5bb37a3

Browse files
committed
type casting extended
1 parent 441973a commit 5bb37a3

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/Schema.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ public function createSpace($space, $properties = null)
3838
public function formatValue($type, $value)
3939
{
4040
switch($type) {
41-
case 'str': return (string) $value;
42-
case 'unsigned': return (int) $value;
41+
case 'STR':
42+
case 'str':
43+
return (string) $value;
44+
45+
case 'unsigned':
46+
case 'UNSIGNED':
47+
case 'num':
48+
case 'NUM':
49+
return (int) $value;
4350
default: return $value;
4451
}
4552
}

tests/MapperTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77

88
class MapperTest extends TestCase
99
{
10+
public function testTypesCasting()
11+
{
12+
$mapper = $this->createMapper();
13+
$this->clean($mapper);
14+
15+
$mapper->getSchema()
16+
->createSpace('tester', [
17+
'id' => 'unsigned',
18+
'name' => 'str',
19+
])
20+
->addIndex('id')
21+
->addIndex('name');
22+
23+
$petya = $mapper->create('tester', [
24+
'id' => '1',
25+
'name' => 'petya',
26+
]);
27+
$this->assertSame(1, $petya->id);
28+
29+
$anotherPetya = $mapper->findOne('tester', ['id' => '1']);
30+
$this->assertNotNull($anotherPetya);
31+
}
1032
public function testIndexRemoved()
1133
{
1234
$mapper = $this->createMapper();
@@ -33,7 +55,7 @@ public function testIndexRemoved()
3355
$this->assertNotNull($mapper->findOne('tester', ['name2' => 'w']));
3456
}
3557

36-
public function testCasting()
58+
public function testPropertyNameCasting()
3759
{
3860
$mapper = $this->createMapper();
3961
$this->clean($mapper);

0 commit comments

Comments
 (0)