Skip to content

Commit

Permalink
Tests: added test for type-change via passThru method (Tharos#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed Jan 25, 2018
1 parent 5963bcc commit bc58a0c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/LeanMapper/Entity.passThru.type-change.2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

//////////

/**
* @property int $id
* @property array|NULL $attrs m:passThru(jsonDecodeData|jsonEncodeData)
*/
class Foo extends LeanMapper\Entity
{
protected function jsonEncodeData($data)
{
return !empty($data) ? json_encode($data) : NULL;
}


protected function jsonDecodeData($data)
{
return !empty($data) ? json_decode($data, TRUE) : [];
}
}

//////////

$foo = new Foo;
$foo->attrs = ['foo' => 'bar'];
Assert::same([
'attrs' => '{"foo":"bar"}',
], $foo->getRowData());
Assert::same(['foo' => 'bar'], $foo->attrs);

0 comments on commit bc58a0c

Please sign in to comment.