Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Added decimal mapping test
Browse files Browse the repository at this point in the history
  • Loading branch information
archdevil666pl committed Dec 29, 2014
1 parent 54873e7 commit a52f745
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions tests/Db/MappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Vegas\Db\Mapping\Blob;
use Vegas\Db\Mapping\Camelize;
use Vegas\Db\Mapping\DateTime as DateTimeMapping;
use Vegas\Db\Mapping\Decimal;
use Vegas\Db\Mapping\Json;
use Vegas\Db\Mapping\Lowercase;
use Vegas\Db\Mapping\Serialize;
Expand All @@ -39,6 +40,8 @@ public function getSource()
'somecamel' => 'camelize',
'encoded' => 'blob',
'upperstring' => 'uppercase',
'phpobject' => 'serialize',
'currency' => 'decimal'
];
}

Expand Down Expand Up @@ -80,18 +83,6 @@ public function getSource()
];
}

class FakeObject extends CollectionAbstract
{
public function getSource()
{
return 'fake_object';
}

protected $mappings = [
'phpobject' => 'serialize'
];
}

class FakeClass
{
public $param;
Expand Down Expand Up @@ -325,7 +316,7 @@ public function testShouldResolveValidCopyOfPhpObject()

$data = new FakeClass('whatever');

$fake = new FakeObject;
$fake = new Fake;
$fake->phpobject = serialize($data);

$this->assertInstanceOf('\Vegas\Tests\Db\FakeClass', $fake->readMapped('phpobject'));
Expand All @@ -334,4 +325,21 @@ public function testShouldResolveValidCopyOfPhpObject()

$this->assertNotSame($data, $fake->readMapped('phpobject'));
}

public function testShouldPrintDecimalValue()
{
$mappingManager = new MappingManager;
$mappingManager->add(new Decimal);

$fake = new Fake;
$fake->currency = 987654.0321;

$this->assertInternalType('string', $fake->readMapped('currency'));
$this->assertEquals('987654.03', $fake->readMapped('currency'));

$fake->currency = 7.1234E3;

$this->assertInternalType('string', $fake->readMapped('currency'));
$this->assertEquals('7123.40', $fake->readMapped('currency'));
}
}

0 comments on commit a52f745

Please sign in to comment.