diff --git a/.travis.yml b/.travis.yml index f7c8c6d..22f7c0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php node_js: - - 0.10 + - 0.12 php: - 5.4 @@ -10,8 +10,24 @@ php: - 7.0 - hhvm -before_script: +matrix: + fast_finish: true + include: + - php: 5.6 + env: SYMFONY_VERSION=2.7.* + - php: 5.6 + env: SYMFONY_VERSION=2.8.* + - php: 5.6 + env: SYMFONY_VERSION=3.0.* + allow_failures: + - php: hhvm + +before_install: + - composer selfupdate + - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; + +install: - npm install - - composer install --dev --prefer-source + - composer update --prefer-source --no-interaction script: npm test diff --git a/composer.json b/composer.json index 548ed35..447043c 100644 --- a/composer.json +++ b/composer.json @@ -10,10 +10,10 @@ ], "require": { "PHP": ">=5.4.0", - "symfony/http-foundation": "~2.4" + "symfony/http-foundation": "~2.7|~3.0" }, "require-dev": { - "symfony/form": "~2.7" + "symfony/form": "~2.7|~3.0" }, "suggest": { "symfony/form": "to use base64_encoded_file type" diff --git a/src/Form/Type/Base64EncodedFileType.php b/src/Form/Type/Base64EncodedFileType.php index e97e550..cff3cf1 100644 --- a/src/Form/Type/Base64EncodedFileType.php +++ b/src/Form/Type/Base64EncodedFileType.php @@ -7,6 +7,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** @@ -35,7 +36,7 @@ public function configureOptions(OptionsResolver $resolver) 'multiple' => false, 'strict_decode' => true, ]) - ->setAllowedTypes('strict_decode', 'boolean') + ->setAllowedTypes('strict_decode', 'bool') ; } @@ -44,14 +45,40 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return 'text'; + if ('form' === parent::getParent()) { + // BC for SF < 2.8 + return 'text'; + } + + return 'Symfony\Component\Form\Extension\Core\Type\TextType'; } /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'file_base64_encoded'; } + + /** + * BC for SF < 2.7 + * + * @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + /* @var $resolver OptionsResolver */ + $this->configureOptions($resolver); + } + + /** + * BC for SF < 3.0 + * + * {@inheritdoc} + */ + public function getName() + { + return $this->getBlockPrefix(); + } } diff --git a/tests/Form/Form/Base64EncodedFileTypeTest.php b/tests/Form/Form/Base64EncodedFileTypeTest.php index 86f0498..f6f3742 100644 --- a/tests/Form/Form/Base64EncodedFileTypeTest.php +++ b/tests/Form/Form/Base64EncodedFileTypeTest.php @@ -68,6 +68,14 @@ public function testEmpty() */ private function createForm() { - return $this->factory->create(new Base64EncodedFileType()); + $type = new Base64EncodedFileType(); + + $name = $type->getParent() === 'text' + // sf < 2.7 + ? $type + // sf > 2.8 + : 'Hshn\Base64EncodedFile\Form\Type\Base64EncodedFileType'; + + return $this->factory->create($name); } }