Skip to content

Commit

Permalink
Update for Symfony 3.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
drewclauson committed Jan 21, 2016
1 parent f737c71 commit 43c99c7
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 85 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ php:
- 5.5
- 5.6

env:
- SYMFONY_VERSION=2.3.* #php >=5.3.3
- SYMFONY_VERSION=2.7.* #php >=5.3.9
- SYMFONY_VERSION=2.8.* #php >=5.3.9
- SYMFONY_VERSION=3.0.* #php >=5.5.9

before_script:
- composer self-update
- composer install --dev --prefer-source

script: ./vendor/bin/phpunit --coverage-text

matrix:
exclude:
- php: 5.3
env: SYMFONY_VERSION=3.0.*
- php: 5.4
env: SYMFONY_VERSION=3.0.*

notifications:
email:
- travis-ci@kitpages.fr
2 changes: 1 addition & 1 deletion Form/Type/CurrencyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
foreach ($options["currency_choices"] as $currencyCode) {
$choiceList[$currencyCode] = $currencyCode;
}
$builder->add('tbbc_name', new ChoiceType(), array(
$builder->add('tbbc_name', get_class(new ChoiceType()), array(
"choices" => $choiceList,
"preferred_choices" => array($options["reference_currency"])
));
Expand Down
2 changes: 1 addition & 1 deletion Form/Type/MoneyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('tbbc_amount', new TextType())
->add('tbbc_amount', get_class(new TextType()))
->add('tbbc_currency', $options['currency_type'])
->addModelTransformer(
new MoneyToArrayTransformer($this->decimals)
Expand Down
2 changes: 1 addition & 1 deletion Form/Type/SimpleMoneyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(PairManagerInterface $pairManager, $decimals)
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('tbbc_amount', new TextType())
->add('tbbc_amount', get_class(new TextType()))
->addModelTransformer(
new SimpleMoneyToArrayTransformer($this->pairManager, $this->decimals)
);
Expand Down
31 changes: 18 additions & 13 deletions Tests/Form/Type/CurrencyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,41 @@
namespace Tbbc\MoneyBundle\Tests\Form\Type;

use Money\Currency;
use Symfony\Component\Form\Test\FormIntegrationTestCase;
use Tbbc\MoneyBundle\Form\Type\CurrencyType;
use Symfony\Component\Form\PreloadedExtension;
use Symfony\Component\Form\Test\TypeTestCase;
use Tbbc\MoneyBundle\Form\Type\CurrencyType;

class CurrencyTypeTest
extends TypeTestCase
{
private $currencyTypeClass;

public function testBindValid()
{
$currencyType = new CurrencyType(
array("EUR", "USD"),
"EUR"
);
$form = $this->factory->create($currencyType, null, array());
$form->bind(array("tbbc_name" => "EUR"));
$form = $this->factory->create($this->currencyTypeClass, null, array());
$form->submit(array("tbbc_name" => "EUR"));
$this->assertEquals(new Currency('EUR'), $form->getData());
}

public function testSetData()
{
\Locale::setDefault("fr_FR");
$currencyType = new CurrencyType(
array("EUR", "USD"),
"EUR"
);
$form = $this->factory->create($currencyType, null, array());
$form = $this->factory->create($this->currencyTypeClass, null, array());
$form->setData(new Currency("USD"));
$formView = $form->createView();

$this->assertEquals("USD", $formView->children["tbbc_name"]->vars["value"]);
}

protected function getExtensions()
{
$currencyType = new CurrencyType(array("EUR", "USD"), "EUR");
$this->currencyTypeClass = get_class($currencyType);
return array(
new PreloadedExtension(
array($currencyType), array()
)
);
}

}
63 changes: 28 additions & 35 deletions Tests/Form/Type/MoneyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Tbbc\MoneyBundle\Tests\Form\Type;

use Money\Currency;
use Symfony\Component\Form\PreloadedExtension;
use Symfony\Component\Form\Test\FormIntegrationTestCase;
use Tbbc\MoneyBundle\Form\Type\CurrencyType;
use Tbbc\MoneyBundle\Form\Type\MoneyType;
Expand All @@ -16,22 +17,16 @@
class MoneyTypeTest
extends TypeTestCase
{
public function setUp()
{
parent::setUp();
}

private $currencyTypeClass;
private $moneyTypeClass;

public function testBindValid()
{
$currencyType = new CurrencyType(
array("EUR", "USD"),
"EUR"
);
$moneyType = new MoneyType(2);
$form = $this->factory->create($moneyType, null, array(
"currency_type" => $currencyType,
$form = $this->factory->create($this->moneyTypeClass, null, array(
"currency_type" => $this->currencyTypeClass,
));
$form->bind(array(
$form->submit(array(
"tbbc_currency" => array("tbbc_name"=>'EUR'),
"tbbc_amount" => '12'
));
Expand All @@ -41,15 +36,10 @@ public function testBindValid()
public function testBindDecimalValid()
{
\Locale::setDefault("fr_FR");
$currencyType = new CurrencyType(
array("EUR", "USD"),
"EUR"
);
$moneyType = new MoneyType(2);
$form = $this->factory->create($moneyType, null, array(
"currency_type" => $currencyType,
$form = $this->factory->create($this->moneyTypeClass, null, array(
"currency_type" => $this->currencyTypeClass,
));
$form->bind(array(
$form->submit(array(
"tbbc_currency" => array("tbbc_name"=>'EUR'),
"tbbc_amount" => '12,5'
));
Expand All @@ -59,15 +49,10 @@ public function testBindDecimalValid()
public function testGreaterThan1000Valid()
{
\Locale::setDefault("fr_FR");
$currencyType = new CurrencyType(
array("EUR", "USD"),
"EUR"
);
$moneyType = new MoneyType(2);
$form = $this->factory->create($moneyType, null, array(
"currency_type" => $currencyType,
$form = $this->factory->create($this->moneyTypeClass, null, array(
"currency_type" => $this->currencyTypeClass,
));
$form->bind(array(
$form->submit(array(
"tbbc_currency" => array("tbbc_name"=>'EUR'),
"tbbc_amount" => '1 252,5'
));
Expand All @@ -77,18 +62,26 @@ public function testGreaterThan1000Valid()
public function testSetData()
{
\Locale::setDefault("fr_FR");
$currencyType = new CurrencyType(
array("EUR", "USD"),
"EUR"
);
$moneyType = new MoneyType(2);
$form = $this->factory->create($moneyType, null, array(
"currency_type" => $currencyType,
$form = $this->factory->create($this->moneyTypeClass, null, array(
"currency_type" => $this->currencyTypeClass,
));
$form->setData(Money::EUR(120));
$formView = $form->createView();

$this->assertEquals("1,20", $formView->children["tbbc_amount"]->vars["value"]);
}

protected function getExtensions()
{
$currencyType = new CurrencyType(array("EUR", "USD"), "EUR");
$moneyType = new MoneyType(2);
$this->currencyTypeClass = get_class($currencyType);
$this->moneyTypeClass = get_class($moneyType);
return array(
new PreloadedExtension(
array($currencyType,$moneyType), array()
)
);
}

}
62 changes: 38 additions & 24 deletions Tests/Form/Type/SimpleMoneyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Tbbc\MoneyBundle\Tests\Form\Type;

use Money\Currency;
use Symfony\Component\Form\PreloadedExtension;
use Symfony\Component\Form\Test\FormIntegrationTestCase;
use Tbbc\MoneyBundle\Form\Type\CurrencyType;
use Symfony\Component\Form\Test\TypeTestCase;
Expand All @@ -17,31 +18,22 @@
class SimpleMoneyTypeTest
extends TypeTestCase
{
public function setUp()
{
parent::setUp();
$this->pairManager = $this->getMockBuilder('Tbbc\MoneyBundle\Pair\PairManager')
->disableOriginalConstructor()
->getMock();
$this->pairManager->expects($this->any())
->method('getReferenceCurrencyCode')
->will($this->returnValue("EUR"));
}
private $pairManager;
private $simpleMoneyTypeClass;

public function testBindValid()
{
$moneyType = new SimpleMoneyType($this->pairManager, 2);
$form = $this->factory->create($moneyType, null, array());
$form->bind(array(
$form = $this->factory->create($this->simpleMoneyTypeClass, null, array());
$form->submit(array(
"tbbc_amount" => '12'
));
$this->assertEquals(Money::EUR(1200), $form->getData());
}
public function testBindValidDecimals()
{
$moneyType = new SimpleMoneyType($this->pairManager, 3);
$form = $this->factory->create($moneyType, null, array());
$form->bind(array(
\Locale::setDefault("fr_FR");
$form = $this->factory->create($this->simpleMoneyTypeClass, null, array());
$form->submit(array(
"tbbc_amount" => '1,2'
));
$this->assertEquals(Money::EUR(1200), $form->getData());
Expand All @@ -50,9 +42,8 @@ public function testBindValidDecimals()
public function testBindDecimalValid()
{
\Locale::setDefault("fr_FR");
$moneyType = new SimpleMoneyType($this->pairManager, 2);
$form = $this->factory->create($moneyType, null, array());
$form->bind(array(
$form = $this->factory->create($this->simpleMoneyTypeClass, null, array());
$form->submit(array(
"tbbc_amount" => '12,5'
));
$this->assertEquals(Money::EUR(1250), $form->getData());
Expand All @@ -61,9 +52,8 @@ public function testBindDecimalValid()
public function testGreaterThan1000Valid()
{
\Locale::setDefault("fr_FR");
$moneyType = new SimpleMoneyType($this->pairManager, 2);
$form = $this->factory->create($moneyType, null, array());
$form->bind(array(
$form = $this->factory->create($this->simpleMoneyTypeClass, null, array());
$form->submit(array(
"tbbc_amount" => '1 252,5'
));
$this->assertEquals(Money::EUR(125250), $form->getData());
Expand All @@ -72,12 +62,36 @@ public function testGreaterThan1000Valid()
public function testSetData()
{
\Locale::setDefault("fr_FR");
$moneyType = new SimpleMoneyType($this->pairManager, 2);
$form = $this->factory->create($moneyType, null, array());
$form = $this->factory->create($this->simpleMoneyTypeClass, null, array());
$form->setData(Money::EUR(120));
$formView = $form->createView();

$this->assertEquals("1,20", $formView->children["tbbc_amount"]->vars["value"]);
}

protected function getExtensions()
{
//This is probably not ideal, but I'm not sure how to set up the pair manager
// with different decimals for different tests in Symfony 3.0
$decimals = 2;
if($this->getName() === "testBindValidDecimals")
$decimals = 3;

$this->pairManager = $this->getMockBuilder('Tbbc\MoneyBundle\Pair\PairManager')
->disableOriginalConstructor()
->getMock();
$this->pairManager->expects($this->any())
->method('getReferenceCurrencyCode')
->will($this->returnValue("EUR"));

$simpleMoneyType = new SimpleMoneyType($this->pairManager, $decimals);
$this->simpleMoneyTypeClass = get_class($simpleMoneyType);

return array(
new PreloadedExtension(
array($simpleMoneyType), array()
)
);
}

}
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
}
],
"require": {
"php": ">=5.3.2",
"php": ">=5.3.29",
"ext-curl" : "*",
"symfony/framework-bundle": "~2.1",
"symfony/framework-bundle": "~2.3|~3.0",
"mathiasverraes/money": "1.2.*",
"symfony/form": "~2.1",
"symfony/twig-bundle": "~2.1",
"symfony/console": "~2.1",
"symfony/dom-crawler": "~2.0|~3.0"
"symfony/form": "~2.3|~3.0",
"symfony/twig-bundle": "~2.3|~3.0",
"symfony/console": "~2.3|~3.0",
"symfony/dom-crawler": "~2.3|~3.0"
},
"require-dev": {
"symfony/class-loader": "~2.1",
"symfony/yaml": "~2.1",
"symfony/finder": "~2.1",
"symfony/browser-kit": "~2.1",
"symfony/class-loader": "~2.3|~3.0",
"symfony/yaml": "~2.3|~3.0",
"symfony/finder": "~2.3|~3.0",
"symfony/browser-kit": "~2.3|~3.0",
"beberlei/DoctrineExtensions": "0.3.*",
"ext-sqlite3": "*",
"doctrine/doctrine-bundle": "~1.1",
Expand Down

0 comments on commit 43c99c7

Please sign in to comment.