-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
78 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
use Money\InvalidArgumentException; | ||
use Money\Money; | ||
use Zend\Filter\AbstractFilter; | ||
use Zend\Filter\Exception; | ||
|
||
/** | ||
* @author Gabriel Schmitt <[email protected]> | ||
|
@@ -14,10 +13,11 @@ | |
class AmountFilter extends AbstractFilter | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
* {@inheritdoc} | ||
* | ||
* @throws InvalidArgumentException | ||
* @return int | ||
* | ||
* @return int|null | ||
*/ | ||
public function filter($value) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,40 +9,40 @@ | |
use ZFBrasil\DoctrineMoneyModule\InputFilter\MoneyInputFilter; | ||
|
||
/** | ||
* Money form element that will make it very easy to work with money and currencies | ||
* Money form element that will make it very easy to work with money and currencies. | ||
* | ||
* @author Fábio Carneiro <[email protected]> | ||
* @license MIT | ||
*/ | ||
class MoneyFieldset extends Fieldset implements InputFilterProviderInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
* {@inheritdoc} | ||
*/ | ||
public function init() | ||
{ | ||
$this->add([ | ||
'type' => Number::class, | ||
'name' => 'amount', | ||
'options' => [ | ||
'label' => 'Amount' | ||
'label' => 'Amount', | ||
], | ||
'attributes' => [ | ||
'step' => '0.01', | ||
] | ||
], | ||
]); | ||
|
||
$this->add([ | ||
'type' => CurrencySelect::class, | ||
'name' => 'currency', | ||
'options' => [ | ||
'label' => 'Currency' | ||
] | ||
'label' => 'Currency', | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* {@inheritdoc} | ||
*/ | ||
public function getInputFilterSpecification() | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,28 +7,28 @@ | |
use Money\Currency; | ||
|
||
/** | ||
* Hydrator for Money object | ||
* Hydrator for Money object. | ||
* | ||
* @author Fábio Carneiro <[email protected]> | ||
* @license MIT | ||
*/ | ||
class MoneyHydrator implements HydratorInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
* {@inheritdoc} | ||
*/ | ||
public function extract($object) | ||
{ | ||
return [ | ||
'amount' => $object->getAmount(), | ||
'currency' => $object->getCurrency()->getName() | ||
'currency' => $object->getCurrency()->getName(), | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* {@inheritdoc} | ||
* | ||
* @return Money | ||
* @return Money|null | ||
*/ | ||
public function hydrate(array $data, $object) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
use Zend\Stdlib\Hydrator\ObjectProperty; | ||
|
||
/** | ||
* Test to see if Form returns a valid object on getData | ||
* Test to see if Form returns a valid object on getData. | ||
* | ||
* @author Fábio Carneiro <[email protected]> | ||
* @license MIT | ||
|
@@ -41,7 +41,7 @@ public function testElementDirectlyInTheForm() | |
|
||
$form = new Form(); | ||
$form->setHydrator(new ObjectProperty()); | ||
$form->setObject(new StdClass); | ||
$form->setObject(new StdClass()); | ||
$form->add($element, ['name' => 'money']); | ||
|
||
$this->assertFalse($form->setData([])->isValid()); | ||
|
@@ -50,24 +50,24 @@ public function testElementDirectlyInTheForm() | |
|
||
$data = [ | ||
'money' => [ | ||
'amount' => "500.20", | ||
'currency' => "BRL" | ||
] | ||
'amount' => '500.20', | ||
'currency' => 'BRL', | ||
], | ||
]; | ||
|
||
$form->setData($data); | ||
|
||
$this->assertTrue($form->isValid()); | ||
|
||
$amountValue = $form->get('money')->get('amount')->getValue(); | ||
$amountValue = $form->get('money')->get('amount')->getValue(); | ||
$currencyValue = $form->get('money')->get('currency')->getValue(); | ||
$object = $form->getData()->money; | ||
$object = $form->getData()->money; | ||
|
||
$this->assertSame("500.20", $amountValue); | ||
$this->assertSame("BRL", $currencyValue); | ||
$this->assertSame('500.20', $amountValue); | ||
$this->assertSame('BRL', $currencyValue); | ||
$this->assertInstanceOf(Money::class, $object); | ||
$this->assertSame(50020, $object->getAmount()); | ||
$this->assertSame("BRL", $object->getCurrency()->getName()); | ||
$this->assertSame('BRL', $object->getCurrency()->getName()); | ||
} | ||
|
||
public function testElementInAFieldsetForSomeModel() | ||
|
@@ -84,29 +84,29 @@ public function testElementInAFieldsetForSomeModel() | |
$form->add($fieldset); | ||
|
||
// todo: can't load this | ||
$form->bind(new HasMoneyPropertyModel); | ||
$form->bind(new HasMoneyPropertyModel()); | ||
|
||
$data = [ | ||
'hasMoneyElementFieldset' => [ | ||
'price' => [ | ||
'amount' => "500.25", | ||
'currency' => "BRL" | ||
] | ||
] | ||
'amount' => '500.25', | ||
'currency' => 'BRL', | ||
], | ||
], | ||
]; | ||
|
||
$form->setData($data); | ||
$this->assertTrue($form->isValid()); | ||
|
||
$amountValue = $form->get('hasMoneyElementFieldset')->get('price')->get('amount')->getValue(); | ||
$amountValue = $form->get('hasMoneyElementFieldset')->get('price')->get('amount')->getValue(); | ||
$currencyValue = $form->get('hasMoneyElementFieldset')->get('price')->get('currency')->getValue(); | ||
$object = $form->getData(); | ||
$object = $form->getData(); | ||
|
||
$this->assertSame("500.25", $amountValue); | ||
$this->assertSame("BRL", $currencyValue); | ||
$this->assertSame('500.25', $amountValue); | ||
$this->assertSame('BRL', $currencyValue); | ||
$this->assertInstanceOf(Money::class, $object->getPrice()); | ||
$this->assertSame(50025, $object->getPrice()->getAmount()); | ||
$this->assertSame("BRL", $object->getPrice()->getCurrency()->getName()); | ||
$this->assertSame('BRL', $object->getPrice()->getCurrency()->getName()); | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.