diff --git a/.gitignore b/.gitignore index dfd6caa..5e10c17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /vendor -composer.lock \ No newline at end of file +composer.lock +.php_cs.cache +.phpunit.result.cache diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..c6f4680 --- /dev/null +++ b/.php_cs @@ -0,0 +1,37 @@ + +EOF; + +$finder = PhpCsFixer\Finder::create() + ->in([ + __DIR__ + ]) +; + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setUsingCache(true) + ->setFinder($finder) + ->setRules([ + '@Symfony' => true, + 'php_unit_namespaced' => true, + 'psr0' => false, + 'concat_space' => ['spacing' => 'one'], + 'phpdoc_summary' => false, + 'phpdoc_annotation_without_dot' => false, + 'phpdoc_order' => true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => true, + 'simplified_null_return' => false, + 'header_comment' => ['header' => $header], + 'yoda_style' => null, + 'native_function_invocation' => ['include' => ['@compiler_optimized']], + 'single_line_throw' => false, + ]) +; diff --git a/.travis.yml b/.travis.yml index 70ed8b2..d1d07f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,33 +1,69 @@ +sudo: false language: php -php: - - 7.0 +branches: + only: + - master + +env: + global: + - CHECK_CODE_STYLE="no" + - COMPOSER_FLAGS="" + - COMPOSER_MEMORY_LIMIT=-1 + - ENABLE_CODE_COVERAGE="no" + - SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit" + - SYMFONY_VERSION="" matrix: fast_finish: true include: - - php: 7.0 - env: SYMFONY_VERSION="3.0.*@dev" - php: 7.1 - env: SYMFONY_VERSION="3.0.*@dev" + env: SYMFONY_VERSION="3.0.*" - php: 7.2 - env: SYMFONY_VERSION="3.0.*@dev" + env: SYMFONY_VERSION="3.0.*" - php: 7.1 - env: SYMFONY_VERSION="4.0.*@dev" + env: SYMFONY_VERSION="4.0.*" - php: 7.2 - env: SYMFONY_VERSION="4.0.*@dev" - -sudo: false + env: SYMFONY_VERSION="4.0.*" + - php: 7.3 + env: SYMFONY_VERSION="4.4.*" + - php: 7.3 + env: SYMFONY_VERSION="5.0.*" + - php: 7.4 + env: SYMFONY_VERSION="5.0.*" + - php: 7.4 + env: SYMFONY_VERSION="5.1.*" + # bleeding edge (unreleased dev versions where failures are allowed): + - php: nightly # PHP 8 + env: SYMFONY_VERSION="5.2.*" + allow_failures: + - env: SYMFONY_VERSION="5.2.*" cache: directories: - $HOME/.composer/cache + - $HOME/symfony-bridge/.phpunit before_install: - - composer selfupdate - - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; + - if [[ "$ENABLE_CODE_COVERAGE" != "yes" ]]; then phpenv config-rm xdebug.ini || true; fi; + - if [[ "$SYMFONY_VERSION" != "" ]]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; + - if [[ "$CHECK_CODE_STYLE" != "yes" ]]; then composer remove "friendsofphp/php-cs-fixer" --no-update --no-interaction --dev; fi; -install: composer update --prefer-dist --no-interaction $COMPOSER_FLAGS +install: + - | + # Set composer's platform to php 7.4 if we're on php 8 & use dev version of phpunit-bridge (which ignores platform reqs) + echo $TRAVIS_PHP_VERSION + if [[ $TRAVIS_PHP_VERSION = 'nightly' ]]; then + echo "Set composer's platform to php 7.4" + composer config platform.php 7.4.99 + composer require "symfony/phpunit-bridge:5.1.x-dev" --no-update --no-interaction --dev + fi + - composer update --prefer-dist --no-interaction --optimize-autoloader --prefer-stable --no-progress $COMPOSER_FLAGS + - if [[ "$ENABLE_CODE_COVERAGE" == "yes" ]]; then composer require --dev satooshi/php-coveralls; fi; script: - - vendor/bin/phpunit --coverage-text + - if [[ "$ENABLE_CODE_COVERAGE" == "yes" ]]; then vendor/bin/simple-phpunit --coverage-text --coverage-clover build/logs/clover.xml; else vendor/bin/simple-phpunit; fi; + - if [[ "$CHECK_CODE_STYLE" == "yes" ]]; then PHP_CS_FIXER_FUTURE_MODE=1 vendor/bin/php-cs-fixer fix --config=.php_cs --dry-run --no-interaction --diff; fi; + +after_success: + - if [[ "$ENABLE_CODE_COVERAGE" == "yes" ]]; then php vendor/bin/coveralls -v; fi; diff --git a/Builders/FormKeyBuilder.php b/Builders/FormKeyBuilder.php index 69a8825..7ab6e97 100644 --- a/Builders/FormKeyBuilder.php +++ b/Builders/FormKeyBuilder.php @@ -1,9 +1,9 @@ */ @@ -55,11 +55,11 @@ class FormKeyBuilder * @param string $children Prefix for children nodes * @param string $prototype Prefix for prototype nodes */ - public function __construct($separator = ".", $root = "form", $children = "children", $prototype = "prototype") + public function __construct($separator = '.', $root = 'form', $children = 'children', $prototype = 'prototype') { $this->separator = $separator; - $this->root = $root; - $this->children = $children; + $this->root = $root; + $this->children = $children; $this->prototype = $prototype; } @@ -73,7 +73,7 @@ public function __construct($separator = ".", $root = "form", $children = "child */ public function buildKeyFromTree(FormTree $tree, $parent) { - $key = array(); + $key = []; if ($this->root) { $key[] = $this->root; @@ -82,7 +82,6 @@ public function buildKeyFromTree(FormTree $tree, $parent) $last = \count($tree) - 1; foreach ($tree as $index => $node) { - if (!$node->isPrototype()) { $key[] = $node->getName(); } diff --git a/Builders/FormTreeBuilder.php b/Builders/FormTreeBuilder.php index 764f8ff..4fd3aa2 100644 --- a/Builders/FormTreeBuilder.php +++ b/Builders/FormTreeBuilder.php @@ -1,19 +1,18 @@ */ namespace Elao\Bundle\FormTranslationBundle\Builders; -use Symfony\Component\Form\FormView; - use Elao\Bundle\FormTranslationBundle\Model\FormTree; use Elao\Bundle\FormTranslationBundle\Model\FormTreeNode; +use Symfony\Component\Form\FormView; /** * Responsible form building tree for forms. @@ -27,7 +26,7 @@ class FormTreeBuilder * * @var array */ - private $noChildren = array('date', 'time', 'datetime', 'choice'); + private $noChildren = ['date', 'time', 'datetime', 'choice']; /** * Get the full tree for a given view @@ -41,7 +40,7 @@ public function getTree(FormView $view) if ($view->parent !== null) { $tree = $this->getTree($view->parent); } else { - $tree = new FormTree; + $tree = new FormTree(); } $tree->addChild($this->createNodeFromView($view)); @@ -62,15 +61,13 @@ public function setNoChildren(array $types) /** * Create a FormTreeNode for the given view * - * @param FormView $view - * * @return FormTreeNode */ private function createNodeFromView(FormView $view) { - $haschildren = $this->hasChildrenWithLabel($view); + $haschildren = $this->hasChildrenWithLabel($view); $isCollection = $haschildren ? $this->isCollection($view) : false; - $isPrototype = $this->isPrototype($view); + $isPrototype = $this->isPrototype($view); return new FormTreeNode($view->vars['name'], $haschildren, $isCollection, $isPrototype); } @@ -80,7 +77,7 @@ private function createNodeFromView(FormView $view) * * @param FormView $view The FormView * - * @return boolean + * @return bool */ private function hasChildrenWithLabel(FormView $view) { @@ -102,7 +99,7 @@ private function hasChildrenWithLabel(FormView $view) * * @param FormView $view The FormView * - * @return boolean + * @return bool */ private function isCollection(FormView $view) { @@ -118,7 +115,7 @@ private function isCollection(FormView $view) * * @param FormView $view The FormView * - * @return boolean + * @return bool */ private function isPrototype(FormView $view) { diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ccf2026..6f5274b 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -1,9 +1,9 @@ */ @@ -23,7 +23,7 @@ class Configuration implements ConfigurationInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public function getConfigTreeBuilder() { @@ -45,27 +45,27 @@ public function getConfigTreeBuilder() ->append( $this->addKeysConfig( 'form', - array( - 'label' => "label", - 'help' => "help", - ) + [ + 'label' => 'label', + 'help' => 'help', + ] ) ) ->append( $this->addKeysConfig( 'collection', - array( - 'label_add' => "label_add", - 'label_delete' => "label_delete", - ) + [ + 'label_add' => 'label_add', + 'label_delete' => 'label_delete', + ] ) ) ->append( $this->addKeysConfig( 'choice', - array( - 'empty_value' => "empty_value", - ) + [ + 'empty_value' => 'empty_value', + ] ) ) ->end() @@ -105,11 +105,11 @@ public function getConfigTreeBuilder() * Add Keys Config * * @param string $key - * @param array $default + * @param array $default * * @return ArrayNodeDefinition|NodeDefinition */ - public function addKeysConfig($key, $default = array()) + public function addKeysConfig($key, $default = []) { $treeBuilder = new TreeBuilder($key); $node = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root($key); diff --git a/DependencyInjection/ElaoFormTranslationExtension.php b/DependencyInjection/ElaoFormTranslationExtension.php index 67363d7..264be42 100644 --- a/DependencyInjection/ElaoFormTranslationExtension.php +++ b/DependencyInjection/ElaoFormTranslationExtension.php @@ -1,21 +1,21 @@ */ namespace Elao\Bundle\FormTranslationBundle\DependencyInjection; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** * ElaoFormTranslation extension @@ -25,7 +25,7 @@ class ElaoFormTranslationExtension extends Extension { /** - * {@inheritDoc} + * {@inheritdoc} */ public function load(array $configs, ContainerBuilder $container) { @@ -33,7 +33,7 @@ public function load(array $configs, ContainerBuilder $container) $config = $this->processConfiguration($configuration, $configs); if ($config['enabled']) { - $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); $loader->load('forms.xml'); @@ -62,26 +62,26 @@ private function loadTreeConfig(ContainerBuilder $container, LoaderInterface $lo // Set up the Tree Aware extension $container ->getDefinition('elao.form_translation.extension.tree_aware_extension') - ->addMethodCall('setAutoGenerate', array($config['auto_generate'])) - ->addMethodCall('setDefaultTranslationDomain', array($config['default_translation_domain'])) - ->addMethodCall('setTreebuilder', array(new Reference('elao.form_translation.tree_builder'))) - ->addMethodCall('setKeybuilder', array(new Reference('elao.form_translation.key_builder'))); + ->addMethodCall('setAutoGenerate', [$config['auto_generate']]) + ->addMethodCall('setDefaultTranslationDomain', [$config['default_translation_domain']]) + ->addMethodCall('setTreebuilder', [new Reference('elao.form_translation.tree_builder')]) + ->addMethodCall('setKeybuilder', [new Reference('elao.form_translation.key_builder')]); // Set up the Form extensions $container ->getDefinition('elao.form_translation.extension.form_type_extension') - ->addMethodCall('setKeys', array($config['keys']['form'])); + ->addMethodCall('setKeys', [$config['keys']['form']]); $container ->getDefinition('elao.form_translation.extension.button_type_extension') - ->addMethodCall('setKeys', array($config['keys']['form'])); + ->addMethodCall('setKeys', [$config['keys']['form']]); $container ->getDefinition('elao.form_translation.extension.collection_type_extension') - ->addMethodCall('setKeys', array(array_merge($config['keys']['form'], $config['keys']['collection']))); + ->addMethodCall('setKeys', [array_merge($config['keys']['form'], $config['keys']['collection'])]); $container ->getDefinition('elao.form_translation.extension.choice_type_extension') - ->addMethodCall('setKeys', array(array_merge($config['keys']['form'], $config['keys']['choice']))); + ->addMethodCall('setKeys', [array_merge($config['keys']['form'], $config['keys']['choice'])]); } } diff --git a/ElaoFormTranslationBundle.php b/ElaoFormTranslationBundle.php index 31e4702..0fae55a 100644 --- a/ElaoFormTranslationBundle.php +++ b/ElaoFormTranslationBundle.php @@ -1,9 +1,9 @@ */ diff --git a/Form/Extension/ButtonTypeExtension.php b/Form/Extension/ButtonTypeExtension.php index 99a92b6..abb2e39 100644 --- a/Form/Extension/ButtonTypeExtension.php +++ b/Form/Extension/ButtonTypeExtension.php @@ -1,9 +1,9 @@ */ @@ -21,7 +21,7 @@ class ButtonTypeExtension extends TreeAwareExtension /** * {@inheritdoc} */ - public static function getExtendedTypes() + public static function getExtendedTypes(): iterable { return [ButtonType::class]; } diff --git a/Form/Extension/ChoiceTypeExtension.php b/Form/Extension/ChoiceTypeExtension.php index d5fd75d..3a24922 100644 --- a/Form/Extension/ChoiceTypeExtension.php +++ b/Form/Extension/ChoiceTypeExtension.php @@ -1,9 +1,9 @@ */ @@ -21,7 +21,7 @@ class ChoiceTypeExtension extends TreeAwareExtension /** * {@inheritdoc} */ - public static function getExtendedTypes() + public static function getExtendedTypes(): iterable { return [ChoiceType::class]; } diff --git a/Form/Extension/CollectionTypeExtension.php b/Form/Extension/CollectionTypeExtension.php index 5c92c8b..01a6f9a 100644 --- a/Form/Extension/CollectionTypeExtension.php +++ b/Form/Extension/CollectionTypeExtension.php @@ -1,9 +1,9 @@ */ @@ -23,7 +23,7 @@ class CollectionTypeExtension extends TreeAwareExtension /** * {@inheritdoc} */ - public static function getExtendedTypes() + public static function getExtendedTypes(): iterable { return [CollectionType::class]; } @@ -53,7 +53,7 @@ public function configureOptions(OptionsResolver $resolver) public function finishView(FormView $view, FormInterface $form, array $options) { if ($this->treeBuilder && $this->keyBuilder && $options['allow_add'] && $options['prototype']) { - if ($view->vars['prototype']->vars['label'] == $options['prototype_name'].'label__') { + if ($view->vars['prototype']->vars['label'] == $options['prototype_name'] . 'label__') { if (!isset($options['options']['label'])) { $options['options']['label'] = $options['label']; } diff --git a/Form/Extension/FormTypeExtension.php b/Form/Extension/FormTypeExtension.php index bc83493..d754e73 100644 --- a/Form/Extension/FormTypeExtension.php +++ b/Form/Extension/FormTypeExtension.php @@ -1,9 +1,9 @@ */ @@ -21,7 +21,7 @@ class FormTypeExtension extends TreeAwareExtension /** * {@inheritdoc} */ - public static function getExtendedTypes() + public static function getExtendedTypes(): iterable { return [FormType::class]; } diff --git a/Form/Extension/TreeAwareExtension.php b/Form/Extension/TreeAwareExtension.php index 075eb38..662d680 100644 --- a/Form/Extension/TreeAwareExtension.php +++ b/Form/Extension/TreeAwareExtension.php @@ -1,20 +1,20 @@ */ namespace Elao\Bundle\FormTranslationBundle\Form\Extension; +use Elao\Bundle\FormTranslationBundle\Builders\FormKeybuilder; +use Elao\Bundle\FormTranslationBundle\Builders\FormTreebuilder; +use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; -use Symfony\Component\Form\AbstractTypeExtension; -use Elao\Bundle\FormTranslationBundle\Builders\FormTreebuilder; -use Elao\Bundle\FormTranslationBundle\Builders\FormKeybuilder; /** * Tree Aware Extension @@ -45,7 +45,7 @@ abstract class TreeAwareExtension extends AbstractTypeExtension /** * Whether automatic generation of missing keys is enabled or not * - * @var boolean + * @var bool */ protected $autoGenerate = false; @@ -59,7 +59,7 @@ abstract class TreeAwareExtension extends AbstractTypeExtension /** * Enable or disable automatic generation of missing labels * - * @param boolean $enabled The Boolean + * @param bool $enabled The Boolean */ public function setAutoGenerate($enabled) { @@ -123,9 +123,9 @@ public function finishView(FormView $view, FormInterface $form, array $options) /** * Generate the key for the given view field * - * @param FormView $view The form view - * @param string $key a key - * @param string $value + * @param FormView $view The form view + * @param string $key a key + * @param string $value */ protected function generateKey(FormView &$view, $key, $value) { diff --git a/Model/FormTree.php b/Model/FormTree.php index 94a2563..1b607a8 100644 --- a/Model/FormTree.php +++ b/Model/FormTree.php @@ -1,9 +1,9 @@ */ @@ -27,7 +27,7 @@ class FormTree implements \Iterator, \Countable, \ArrayAccess /** * Current position in the loop * - * @var integer + * @var int */ private $position = 0; @@ -36,7 +36,7 @@ class FormTree implements \Iterator, \Countable, \ArrayAccess * * @param array $nodes */ - public function __construct($nodes = array()) + public function __construct($nodes = []) { $this->nodes = $nodes; } @@ -80,7 +80,7 @@ public function rewind() */ public function count() { - return count($this->nodes); + return \count($this->nodes); } /** @@ -126,7 +126,7 @@ public function valid() * * @param mixed $offset * - * @return boolean + * @return bool */ public function offsetExists($offset) { diff --git a/Model/FormTreeNode.php b/Model/FormTreeNode.php index 45c79c6..cc73c87 100644 --- a/Model/FormTreeNode.php +++ b/Model/FormTreeNode.php @@ -1,9 +1,9 @@ */ @@ -27,38 +27,38 @@ class FormTreeNode /** * Whether or not the node has labeled children. * - * @var boolean + * @var bool */ private $children; /** * Whether or not the node is a collection. * - * @var boolean + * @var bool */ private $collection; /** * Whether or not the node is a prototype. * - * @var boolean + * @var bool */ private $prototype; /** * Constructor * - * @param string $name The node's name - * @param boolean $children Whether or not the node has labeled children - * @param boolean $collection Is the node a collection - * @param boolean $prototype Is the node a prototype + * @param string $name The node's name + * @param bool $children Whether or not the node has labeled children + * @param bool $collection Is the node a collection + * @param bool $prototype Is the node a prototype */ public function __construct($name, $children = false, $collection = false, $prototype = false) { - $this->name = (string) $name; - $this->children = (boolean) $children; - $this->collection = (boolean) $collection; - $this->prototype = (boolean) $prototype; + $this->name = (string) $name; + $this->children = (bool) $children; + $this->collection = (bool) $collection; + $this->prototype = (bool) $prototype; } /** @@ -74,7 +74,7 @@ public function getName() /** * Does the node has labeled children? * - * @return boolean + * @return bool */ public function hasChildren() { @@ -84,7 +84,7 @@ public function hasChildren() /** * Is the node a collection? * - * @return boolean + * @return bool */ public function isCollection() { @@ -94,7 +94,7 @@ public function isCollection() /** * Is the node a prototype? * - * @return boolean + * @return bool */ public function isPrototype() { diff --git a/Test/FormTranslationTestCase.php b/Test/FormTranslationTestCase.php index ece073b..c8d5f10 100644 --- a/Test/FormTranslationTestCase.php +++ b/Test/FormTranslationTestCase.php @@ -1,10 +1,18 @@ + */ + namespace Elao\Bundle\FormTranslationBundle\Test; +use Elao\Bundle\FormTranslationBundle\Form\Extension; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\Forms; -use Elao\Bundle\FormTranslationBundle\Form\Extension; abstract class FormTranslationTestCase extends TestCase { @@ -16,7 +24,7 @@ abstract class FormTranslationTestCase extends TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { $this->factory = Forms::createFormFactoryBuilder() ->addTypeExtensions($this->getTypeExtensions()) @@ -30,12 +38,12 @@ protected function setUp() */ protected function getTypeExtensions() { - $extensions = array( + $extensions = [ new Extension\ButtonTypeExtension(), new Extension\ChoiceTypeExtension(), new Extension\CollectionTypeExtension(), new Extension\FormTypeExtension(), - ); + ]; return $extensions; } diff --git a/Tests/Builders/FormKeyBuilderTest.php b/Tests/Builders/FormKeyBuilderTest.php index 5e912d6..87bd63c 100644 --- a/Tests/Builders/FormKeyBuilderTest.php +++ b/Tests/Builders/FormKeyBuilderTest.php @@ -1,11 +1,18 @@ + */ + namespace Elao\Bundle\FormTranslationBundle\Tests\Builders; use Elao\Bundle\FormTranslationBundle\Builders\FormKeyBuilder; use Elao\Bundle\FormTranslationBundle\Builders\FormTreeBuilder; use Elao\Bundle\FormTranslationBundle\Test\FormTranslationTestCase; -use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -18,14 +25,14 @@ class FormKeyBuilderTest extends FormTranslationTestCase public function testSimpleTreeBuilder() { $treeBuilder = new FormTreeBuilder(); - $keyBuilder = new FormKeyBuilder(); + $keyBuilder = new FormKeyBuilder(); $form = $this->factory->createNamed('foo', FormType::class); $form->add('bar', TextType::class); - $view = $form->createView(); - $tree = $treeBuilder->getTree($view['bar']); + $view = $form->createView(); + $tree = $treeBuilder->getTree($view['bar']); $label = $keyBuilder->buildKeyFromTree($tree, 'label'); $this->assertEquals('form.foo.children.bar.label', $label); @@ -37,24 +44,24 @@ public function testSimpleTreeBuilder() public function testCollectionTreeBuilder() { $treeBuilder = new FormTreeBuilder(); - $keyBuilder = new FormKeyBuilder(); + $keyBuilder = new FormKeyBuilder(); $form = $this->factory->createNamed('foo', FormType::class); $form->add( 'bar', CollectionType::class, - array( - 'entry_type' => TextType::class, - 'allow_add' => true, + [ + 'entry_type' => TextType::class, + 'allow_add' => true, 'allow_delete' => true, - ) + ] ); - $view = $form->createView(); - $barTree = $treeBuilder->getTree($view['bar']); - $prototypeTree = $treeBuilder->getTree($view['bar']->vars['prototype']); - $barLabel = $keyBuilder->buildKeyFromTree($barTree, 'label'); + $view = $form->createView(); + $barTree = $treeBuilder->getTree($view['bar']); + $prototypeTree = $treeBuilder->getTree($view['bar']->vars['prototype']); + $barLabel = $keyBuilder->buildKeyFromTree($barTree, 'label'); $prototypeLabel = $keyBuilder->buildKeyFromTree($prototypeTree, 'label'); $this->assertEquals('form.foo.children.bar.label', $barLabel); diff --git a/Tests/Builders/FormTreeBuilderTest.php b/Tests/Builders/FormTreeBuilderTest.php index ffdc443..347b2c0 100644 --- a/Tests/Builders/FormTreeBuilderTest.php +++ b/Tests/Builders/FormTreeBuilderTest.php @@ -1,10 +1,17 @@ + */ + namespace Elao\Bundle\FormTranslationBundle\Tests\Builders; use Elao\Bundle\FormTranslationBundle\Builders\FormTreeBuilder; use Elao\Bundle\FormTranslationBundle\Test\FormTranslationTestCase; -use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -17,19 +24,19 @@ class FormTreeBuilderTest extends FormTranslationTestCase public function testSimpleTreeBuilder() { $treeBuilder = new FormTreeBuilder(); - $form = $this->factory->createNamed('foo', FormType::class); + $form = $this->factory->createNamed('foo', FormType::class); $form->add('bar', TextType::class); $formView = $form->createView(); - $fooTree = $treeBuilder->getTree($formView); - $barTree = $treeBuilder->getTree($formView['bar']); + $fooTree = $treeBuilder->getTree($formView); + $barTree = $treeBuilder->getTree($formView['bar']); - $this->assertEquals(1, count($fooTree)); + $this->assertEquals(1, \count($fooTree)); $this->assertEquals('foo', $fooTree[0]->getName()); $this->assertEquals(true, $fooTree[0]->hasChildren()); - $this->assertEquals(2, count($barTree)); + $this->assertEquals(2, \count($barTree)); $this->assertEquals('foo', $barTree[0]->getName()); $this->assertEquals('bar', $barTree[1]->getName()); $this->assertEquals(true, $barTree[0]->hasChildren()); @@ -42,26 +49,26 @@ public function testSimpleTreeBuilder() public function testCollectionTreeBuilder() { $treeBuilder = new FormTreeBuilder(); - $form = $this->factory->createNamed('foo', FormType::class); + $form = $this->factory->createNamed('foo', FormType::class); $form->add( 'bar', CollectionType::class, - array( - 'entry_type' => TextType::class, - 'allow_add' => true, + [ + 'entry_type' => TextType::class, + 'allow_add' => true, 'allow_delete' => true, - ) + ] ); $formView = $form->createView(); - $tree = $treeBuilder->getTree($formView['bar']->vars['prototype']); + $tree = $treeBuilder->getTree($formView['bar']->vars['prototype']); $this->assertEquals(true, $tree[1]->hasChildren()); $this->assertEquals(true, $tree[1]->isCollection()); $this->assertEquals(false, $tree[1]->isPrototype()); - $this->assertEquals(3, count($tree)); + $this->assertEquals(3, \count($tree)); $this->assertEquals(false, $tree[2]->hasChildren()); $this->assertEquals(false, $tree[2]->isCollection()); $this->assertEquals(true, $tree[2]->isPrototype()); diff --git a/composer.json b/composer.json index 96dde1a..c2da757 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,13 @@ } ], "require": { - "php": "^7.0.0", - "symfony/framework-bundle": "~2.8|~3.0|~4.0", - "symfony/form": "~2.8|~3.0|~4.0" + "php": "^7.1.0", + "symfony/framework-bundle": "~2.8|~3.0|~4.0|~5.0", + "symfony/form": "~2.8|~3.0|~4.0|~5.0" }, "require-dev": { - "phpunit/phpunit": "~5.0" + "symfony/phpunit-bridge": "^5.0", + "friendsofphp/php-cs-fixer": "^2.16" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8db115d..721153f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,19 @@ - + + + + ./Tests/ @@ -17,4 +30,4 @@ - \ No newline at end of file +