Skip to content

Commit

Permalink
Use symfony 3 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Ducoudray authored and cdaguerre committed Jan 12, 2017
1 parent 7e9969b commit 570ba23
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 46 deletions.
25 changes: 10 additions & 15 deletions Form/Filter/JobFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Worldia\Bundle\TextmasterBundle\Form\Filter;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Worldia\Bundle\TextmasterBundle\Entity\JobInterface;
Expand All @@ -15,18 +17,19 @@ class JobFilterType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('status', 'choice', [
->add('status', ChoiceType::class, [
'required' => false,
'label' => 'job.status.title',
'empty_value' => 'job.status.all',
'placeholder' => 'job.status.all',
'empty_data' => null,
'choices' => [
JobInterface::STATUS_CREATED => 'job.status.created',
JobInterface::STATUS_STARTED => 'job.status.started',
JobInterface::STATUS_FINISHED => 'job.status.finished',
JobInterface::STATUS_VALIDATED => 'job.status.validated',
'job.status.created' => JobInterface::STATUS_CREATED,
'job.status.started' => JobInterface::STATUS_STARTED,
'job.status.finished' => JobInterface::STATUS_FINISHED,
'job.status.validated' => JobInterface::STATUS_VALIDATED,
],
])
->add('filter', 'submit', ['label' => 'job.filter'])
->add('filter', SubmitType::class, ['label' => 'job.filter'])
->setMethod('GET')
;
}
Expand All @@ -38,12 +41,4 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('translation_domain', 'textmaster');
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'textmaster_job_filter';
}
}
23 changes: 9 additions & 14 deletions Form/JobValidationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Worldia\Bundle\TextmasterBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Textmaster\Model\DocumentInterface;
Expand All @@ -16,25 +19,25 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['accept']) {
$builder
->add('satisfaction', 'choice', [
->add('satisfaction', ChoiceType::class, [
'required' => true,
'label' => 'job.validation.satisfaction.label',
'data' => DocumentInterface::SATISFACTION_NEUTRAL,
'choices' => [
DocumentInterface::SATISFACTION_NEGATIVE => 'job.validation.satisfaction.negative',
DocumentInterface::SATISFACTION_NEUTRAL => 'job.validation.satisfaction.neutral',
DocumentInterface::SATISFACTION_POSITIVE => 'job.validation.satisfaction.positive',
'job.validation.satisfaction.negative' => DocumentInterface::SATISFACTION_NEGATIVE,
'job.validation.satisfaction.neutral' => DocumentInterface::SATISFACTION_NEUTRAL,
'job.validation.satisfaction.positive' => DocumentInterface::SATISFACTION_POSITIVE,
],
])
;
}

$builder
->add('message', 'textarea', [
->add('message', TextareaType::class, [
'required' => !$options['accept'],
'label' => 'job.validation.message.label',
])
->add('validate', 'submit', ['label' => 'job.validation.validate'])
->add('validate', SubmitType::class, ['label' => 'job.validation.validate'])
;
}

Expand All @@ -46,12 +49,4 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setDefault('translation_domain', 'textmaster');
$resolver->setDefault('accept', true);
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'textmaster_job_validation';
}
}
3 changes: 2 additions & 1 deletion Resources/views/Job/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
{% endblock %}

{% block content %}
{% render(controller('WorldiaTextmasterBundle:Job:filter', {'type': 'textmaster_job_filter'})) %}
{% set class = 'Worldia\\Bundle\\TextmasterBundle\\Form\\Filter\\JobFilterType' %}
{{ render(controller('WorldiaTextmasterBundle:Job:filter', {'type': class })) }}

<table>
<thead>
Expand Down
3 changes: 1 addition & 2 deletions Tests/Units/Form/JobFilterTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public function testForm()
'status' => JobInterface::STATUS_STARTED,
];

$type = new JobFilterType();
$form = $this->factory->create($type);
$form = $this->factory->create(JobFilterType::class);

$form->submit($formData);
$this->assertTrue($form->isSynchronized());
Expand Down
6 changes: 2 additions & 4 deletions Tests/Units/Form/JobValidationTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public function testAcceptForm()
'satisfaction' => DocumentInterface::SATISFACTION_NEUTRAL,
];

$type = new JobValidationType();
$form = $this->factory->create($type, null, ['accept' => true]);
$form = $this->factory->create(JobValidationType::class, null, ['accept' => true]);

$form->submit($formData);
$this->assertTrue($form->isSynchronized());
Expand All @@ -41,8 +40,7 @@ public function testRejectForm()
'message' => 'Rejection message',
];

$type = new JobValidationType();
$form = $this->factory->create($type, null, ['accept' => false]);
$form = $this->factory->create(JobValidationType::class, null, ['accept' => false]);

$form->submit($formData);
$this->assertTrue($form->isSynchronized());
Expand Down
22 changes: 12 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@
"require": {
"php": ">=5.6.0",
"worldia/textmaster-api": "^0.4",
"symfony/framework-bundle": "^2.7",
"symfony/property-access": "^2.7",
"symfony/validator": "^2.7",
"symfony/form": "^2.7",
"doctrine/orm": "^2.3",
"symfony/framework-bundle": "^3.2",
"symfony/property-access": "^3.2",
"symfony/validator": "^3.2",
"symfony/security-csrf": "^3.2",
"symfony/form": "^3.2",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.5"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"symfony/browser-kit": "^2.7",
"symfony/twig-bundle": "^2.7",
"symfony/templating": "^2.7",
"symfony/browser-kit": "^3.2",
"symfony/twig-bundle": "^3.2",
"symfony/templating": "^3.2",
"symfony/asset": "^3.2",
"matthiasnoback/symfony-config-test": "^1.4",
"matthiasnoback/symfony-dependency-injection-test": "0.*",
"behat/symfony2-extension": "2.0.*",
"behat/symfony2-extension": "2.1.*",
"white-october/pagerfanta-bundle": "^1.0"
},
"suggest": {
Expand All @@ -39,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.4.x-dev"
"dev-master": "1.0.x-dev"
}
}
}

0 comments on commit 570ba23

Please sign in to comment.