From bcaaf133e715f8cbc0fe26638cd87689bb1a7445 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 4 Nov 2015 16:07:55 +0100 Subject: [PATCH] avoid deprecation warnings, disable for old symfony versions, ignore symfony 3 until environment ready for it --- .travis.yml | 19 +++---- Form/PhpcrOdmTypeGuesser.php | 52 ++++++++++++------- Form/Type/DocumentType.php | 11 ++++ Form/Type/PHPCRReferenceType.php | 25 ++++++++- Form/Type/PathType.php | 13 ++++- .../Functional/Form/PHPCRTypeGuesserTest.php | 32 ++++++++---- .../Functional/Form/Type/DocumentTypeTest.php | 10 ++-- .../Resources/DataFixtures/PHPCR/LoadData.php | 23 ++++---- Tests/Resources/Fixtures/config/multiple.yml | 12 ++--- Tests/Resources/Fixtures/config/single.yml | 2 +- .../DependencyInjection/ConfigurationTest.php | 2 +- 11 files changed, 136 insertions(+), 65 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8e035db5..1073a487 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ php: - hhvm env: - - SYMFONY_VERSION="~2.3||~3.0" + - SYMFONY_VERSION="2.7.*,>2.7.6" sudo: false @@ -15,14 +15,15 @@ matrix: include: - php: 5.3 env: SYMFONY_VERSION=2.3.* COMPOSER_FLAGS="--prefer-lowest" - - php: 5.5 - env: SYMFONY_VERSION=2.3.* - - php: 5.5 - env: SYMFONY_VERSION=2.6.* - - php: 5.5 - env: SYMFONY_VERSION=2.7.* - - php: 5.5 - env: SYMFONY_VERSION=2.8.* SYMFONY_DEPRECATIONS_HELPER=weak + - php: 5.6 + env: SYMFONY_VERSION=2.3.* SYMFONY_DEPRECATIONS_HELPER=weak + - php: 5.6 + env: SYMFONY_VERSION=2.8.* + - php: 5.6 + env: SYMFONY_VERSION=3.0.* + allow_failures: + - php: 5.6 + env: SYMFONY_VERSION=3.0.* before_install: - composer self-update || true diff --git a/Form/PhpcrOdmTypeGuesser.php b/Form/PhpcrOdmTypeGuesser.php index 5869a63d..8b27597c 100644 --- a/Form/PhpcrOdmTypeGuesser.php +++ b/Form/PhpcrOdmTypeGuesser.php @@ -49,10 +49,22 @@ class PhpcrOdmTypeGuesser implements FormTypeGuesserInterface private $cache = array(); + /** + * Work with 2.3-2.7 and 3.0 at the same time. drop once we switch to symfony 3.0. + */ + private $legacy = true; + + /** + * Work with 2.3-2.7 and 3.0 at the same time. drop once we switch to symfony 3.0. + */ + private $entryTypeOption = 'type'; + public function __construct(ManagerRegistry $registry, $typeGuess = array()) { $this->registry = $registry; $this->typeGuess = $typeGuess; + $this->legacy = !method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix'); + $this->entryTypeOption = $this->legacy ? 'type' : 'entry_type'; } /** @@ -61,7 +73,7 @@ public function __construct(ManagerRegistry $registry, $typeGuess = array()) public function guessType($class, $property) { if (!$ret = $this->getMetadata($class)) { - return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE); + return new TypeGuess($this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType', array(), Guess::LOW_CONFIDENCE); } /** @var ClassMetadata $metadata */ @@ -73,18 +85,18 @@ public function guessType($class, $property) switch ($mapping['type']) { case 'parent': - return new TypeGuess('phpcr_odm_path', array(), Guess::MEDIUM_CONFIDENCE); + return new TypeGuess($this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType', array(), Guess::MEDIUM_CONFIDENCE); case 'mixedreferrers': $options = array( 'attr' => array('readonly' => 'readonly'), - 'type' => 'phpcr_odm_path', + $this->entryTypeOption => $this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType', ); - return new TypeGuess('collection', $options, Guess::LOW_CONFIDENCE); + return new TypeGuess($this->legacy ? 'collection' : 'Symfony\Component\Form\Extension\Core\Type\CollectionType', $options, Guess::LOW_CONFIDENCE); case 'referrers': - return new TypeGuess('phpcr_document', array( + return new TypeGuess($this->legacy ? 'phpcr_document' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType', array( 'class' => $mapping['referringDocument'], 'multiple' => true, ), @@ -100,29 +112,29 @@ public function guessType($class, $property) $options['class'] = $mapping['targetDocument']; } - return new TypeGuess('phpcr_document', $options, Guess::HIGH_CONFIDENCE); + return new TypeGuess($this->legacy ? 'phpcr_document' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType', $options, Guess::HIGH_CONFIDENCE); case 'child': $options = array( 'attr' => array('readonly' => 'readonly'), ); - return new TypeGuess('phpcr_odm_path', $options, Guess::LOW_CONFIDENCE); + return new TypeGuess($this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType', $options, Guess::LOW_CONFIDENCE); case 'children': $options = array( 'attr' => array('readonly' => 'readonly'), - 'type' => 'phpcr_odm_path', + $this->entryTypeOption => $this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType', ); - return new TypeGuess('collection', $options, Guess::LOW_CONFIDENCE); + return new TypeGuess($this->legacy ? 'collection' : 'Symfony\Component\Form\Extension\Core\Type\CollectionType', $options, Guess::LOW_CONFIDENCE); default: return; } } - $mapping = $metadata->getField($property); + $mapping = $metadata->getFieldMapping($property); if (!empty($mapping['assoc'])) { if (isset($this->typeGuess['assoc'])) { @@ -137,7 +149,7 @@ public function guessType($class, $property) $options = array(); switch ($metadata->getTypeOfField($property)) { case 'boolean': - $type = 'checkbox'; + $type = $this->legacy ? 'checkbox' : 'Symfony\Component\Form\Extension\Core\Type\CheckboxType'; break; case 'binary': // the file type only works on documents like the File document, @@ -147,14 +159,14 @@ public function guessType($class, $property) // editing the phpcr node has no meaning return; case 'date': - $type = 'datetime'; + $type = $this->legacy ? 'datetime' : 'Symfony\Component\Form\Extension\Core\Type\DateTimeType'; break; case 'double': - $type = 'number'; + $type = $this->legacy ? 'number' : 'Symfony\Component\Form\Extension\Core\Type\NumberType'; break; case 'long': case 'integer': - $type = 'integer'; + $type = $this->legacy ? 'integer' : 'Symfony\Component\Form\Extension\Core\Type\IntegerType'; break; case 'string': if ($metadata->isIdentifier($property) @@ -162,14 +174,14 @@ public function guessType($class, $property) ) { $options['attr'] = array('readonly' => 'readonly'); } - $type = 'text'; + $type = $this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType'; break; case 'nodename': - $type = 'text'; + $type = $this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType'; break; case 'locale': $locales = $documentManager->getLocaleChooserStrategy(); - $type = 'choice'; + $type = $this->legacy ? 'choice' : 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'; $options['choices'] = array_combine($locales->getDefaultLocalesOrder(), $locales->getDefaultLocalesOrder()); break; case 'versionname': @@ -177,13 +189,13 @@ public function guessType($class, $property) default: $options['attr'] = array('readonly' => 'readonly'); $options['required'] = false; - $type = 'text'; + $type = $this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType'; break; } if (!empty($mapping['multivalue'])) { - $options['type'] = $type; - $type = 'collection'; + $options[$this->entryTypeOption] = $type; + $type = $this->legacy ? 'collection' : 'Symfony\Component\Form\Extension\Core\Type\CollectionType'; } if (!empty($mapping['translated'])) { diff --git a/Form/Type/DocumentType.php b/Form/Type/DocumentType.php index 5b3bc64d..53643523 100644 --- a/Form/Type/DocumentType.php +++ b/Form/Type/DocumentType.php @@ -34,7 +34,18 @@ public function getLoader(ObjectManager $manager, $queryBuilder, $class) ); } + /** + * {@inheritdoc} + */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'phpcr_document'; } diff --git a/Form/Type/PHPCRReferenceType.php b/Form/Type/PHPCRReferenceType.php index 095b4e25..0600ec58 100644 --- a/Form/Type/PHPCRReferenceType.php +++ b/Form/Type/PHPCRReferenceType.php @@ -28,6 +28,9 @@ public function __construct(SessionInterface $session) $this->session = $session; } + /** + * {@inheritdoc} + */ public function buildForm(FormBuilderInterface $builder, array $options) { switch (strtolower($options['transformer_type'])) { @@ -47,11 +50,17 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->addModelTransformer($transformer); } + /** + * {@inheritdoc} + */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $this->configureOptions($resolver); } + /** + * {@inheritdoc} + */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( @@ -59,12 +68,26 @@ public function configureOptions(OptionsResolver $resolver) )); } + /** + * {@inheritdoc} + */ public function getParent() { - return 'text'; + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Component\Form\Extension\Core\Type\TextType' : 'text'; } + /** + * {@inheritdoc} + */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'phpcr_reference'; } diff --git a/Form/Type/PathType.php b/Form/Type/PathType.php index 66f7cda3..e42ba6ba 100644 --- a/Form/Type/PathType.php +++ b/Form/Type/PathType.php @@ -20,10 +20,21 @@ public function __construct(ManagerRegistry $registry) public function getParent() { - return 'text'; + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Component\Form\Extension\Core\Type\TextType' : 'text'; } + /** + * {@inheritdoc} + */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'phpcr_odm_path'; } diff --git a/Tests/Functional/Form/PHPCRTypeGuesserTest.php b/Tests/Functional/Form/PHPCRTypeGuesserTest.php index a244b39e..2d9c39aa 100644 --- a/Tests/Functional/Form/PHPCRTypeGuesserTest.php +++ b/Tests/Functional/Form/PHPCRTypeGuesserTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Bundle\PHPCRBundle\Tests\Functional\Form; +use Doctrine\ODM\PHPCR\DocumentManager; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; use Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument; @@ -24,8 +25,21 @@ class PHPCRTypeGuesserTest extends BaseTestCase */ private $referrer; + /** + * Work with 2.3-2.7 and 3.0 at the same time. drop once we switch to symfony 3.0. + */ + private $legacy; + + /** + * Work with 2.3-2.7 and 3.0 at the same time. drop once we switch to symfony 3.0. + */ + private $entryTypeOption; + public function setUp() { + $this->legacy = !method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix'); + $this->entryTypeOption = $this->legacy ? 'type' : 'entry_type'; + $this->db('PHPCR')->loadFixtures(array( 'Doctrine\Bundle\PHPCRBundle\Tests\Resources\DataFixtures\PHPCR\LoadData', )); @@ -41,7 +55,7 @@ public function setUp() */ private function createFormBuilder($data, $options = array()) { - return $this->container->get('form.factory')->createBuilder('form', $data, $options); + return $this->container->get('form.factory')->createBuilder($this->legacy ? 'form' : 'Symfony\Component\Form\Extension\Core\Type\FormType', $data, $options); } public function testFields() @@ -126,7 +140,7 @@ public function testMultivalueFields() $formBuilder->get('mbool'), '\Symfony\Component\Form\Extension\Core\Type\CollectionType', array( - 'type' => 'checkbox', + $this->entryTypeOption => $this->legacy ? 'checkbox' : 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', 'required' => false, ) ); @@ -135,7 +149,7 @@ public function testMultivalueFields() $formBuilder->get('mdate'), '\Symfony\Component\Form\Extension\Core\Type\CollectionType', array( - 'type' => 'datetime', + $this->entryTypeOption => $this->legacy ? 'datetime' : 'Symfony\Component\Form\Extension\Core\Type\DateTimeType', 'required' => false, ) ); @@ -144,7 +158,7 @@ public function testMultivalueFields() $formBuilder->get('mtext'), '\Symfony\Component\Form\Extension\Core\Type\CollectionType', array( - 'type' => 'text', + $this->entryTypeOption => $this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType', 'required' => false, ) ); @@ -153,7 +167,7 @@ public function testMultivalueFields() $formBuilder->get('mnumber'), '\Symfony\Component\Form\Extension\Core\Type\CollectionType', array( - 'type' => 'number', + $this->entryTypeOption => $this->legacy ? 'number' : 'Symfony\Component\Form\Extension\Core\Type\NumberType', 'required' => false, ) ); @@ -162,7 +176,7 @@ public function testMultivalueFields() $formBuilder->get('minteger'), '\Symfony\Component\Form\Extension\Core\Type\CollectionType', array( - 'type' => 'integer', + $this->entryTypeOption => $this->legacy ? 'integer' : 'Symfony\Component\Form\Extension\Core\Type\IntegerType', 'required' => false, ) ); @@ -171,7 +185,7 @@ public function testMultivalueFields() $formBuilder->get('mlong'), '\Symfony\Component\Form\Extension\Core\Type\CollectionType', array( - 'type' => 'integer', + $this->entryTypeOption => $this->legacy ? 'integer' : 'Symfony\Component\Form\Extension\Core\Type\IntegerType', 'required' => false, ) ); @@ -241,7 +255,7 @@ public function testHierarchy() array( 'attr' => array('readonly' => 'readonly'), 'required' => false, - 'type' => 'phpcr_odm_path', + $this->entryTypeOption => $this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType', ) ); @@ -325,7 +339,7 @@ public function testReferrers() array( 'attr' => array('readonly' => 'readonly'), 'required' => false, - 'type' => 'phpcr_odm_path', + $this->entryTypeOption => $this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType', ) ); diff --git a/Tests/Functional/Form/Type/DocumentTypeTest.php b/Tests/Functional/Form/Type/DocumentTypeTest.php index a9c4b391..6626c719 100644 --- a/Tests/Functional/Form/Type/DocumentTypeTest.php +++ b/Tests/Functional/Form/Type/DocumentTypeTest.php @@ -19,8 +19,12 @@ class DocumentTypeTest extends BaseTestCase */ private $referrer; + private $legacy; + public function setUp() { + $this->legacy = !method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix'); + $this->db('PHPCR')->loadFixtures(array( 'Doctrine\Bundle\PHPCRBundle\Tests\Resources\DataFixtures\PHPCR\LoadData', )); @@ -36,7 +40,7 @@ public function setUp() */ private function createFormBuilder($data, $options = array()) { - return $this->container->get('form.factory')->createBuilder('form', $data, $options); + return $this->container->get('form.factory')->createBuilder($this->legacy ? 'form' : 'Symfony\Component\Form\Extension\Core\Type\FormType', $data, $options); } /** @@ -55,7 +59,7 @@ public function testUnfiltered() $formBuilder = $this->createFormBuilder($this->referrer); $formBuilder - ->add('single', 'phpcr_document', array( + ->add('single', $this->legacy ? 'phpcr_document' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType', array( 'class' => 'Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument', )) ; @@ -75,7 +79,7 @@ public function testFiltered() $formBuilder = $this->createFormBuilder($this->referrer); $formBuilder - ->add('single', 'phpcr_document', array( + ->add('single', $this->legacy ? 'phpcr_document' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType', array( 'class' => 'Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument', 'query_builder' => $qb, )) diff --git a/Tests/Resources/DataFixtures/PHPCR/LoadData.php b/Tests/Resources/DataFixtures/PHPCR/LoadData.php index a05c694d..631d425d 100644 --- a/Tests/Resources/DataFixtures/PHPCR/LoadData.php +++ b/Tests/Resources/DataFixtures/PHPCR/LoadData.php @@ -15,29 +15,23 @@ use Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; -use Doctrine\Common\DataFixtures\DependentFixtureInterface; +use Doctrine\ODM\PHPCR\Document\Generic; use Doctrine\ODM\PHPCR\DocumentManager; -class LoadData implements FixtureInterface, DependentFixtureInterface +class LoadData implements FixtureInterface { - protected $root; - - public function getDependencies() - { - return array( - 'Symfony\Cmf\Component\Testing\DataFixtures\PHPCR\LoadBaseData', - ); - } - /** * @param DocumentManager $manager */ public function load(ObjectManager $manager) { - $this->root = $manager->find(null, '/test'); + $base = new Generic(); + $base->setNodename('test'); + $base->setParentDocument($manager->find(null, '/')); $doc = new TestDocument(); - $doc->id = '/test/doc'; + $doc->parent = $base; + $doc->nodename = 'doc'; $doc->bool = true; $doc->date = new \DateTime('2014-01-14'); $doc->integer = 42; @@ -48,7 +42,8 @@ public function load(ObjectManager $manager) $manager->persist($doc); $doc = new TestDocument(); - $doc->id = '/test/doc2'; + $doc->parent = $base; + $doc->nodename = 'doc2'; $doc->bool = true; $doc->date = new \DateTime('2014-01-14'); $doc->integer = 42; diff --git a/Tests/Resources/Fixtures/config/multiple.yml b/Tests/Resources/Fixtures/config/multiple.yml index 4f739a7c..89646b5b 100644 --- a/Tests/Resources/Fixtures/config/multiple.yml +++ b/Tests/Resources/Fixtures/config/multiple.yml @@ -5,17 +5,17 @@ doctrine_phpcr: backend: type: jackrabbit url: http://a - workspace: "default" - username: "admin" - password: "admin" + workspace: default + username: admin + password: admin website: backend: type: jackrabbit - url: "http://b" + url: http://b workspace: website - username: "root" - password: "root" + username: root + password: root admin_username: admin admin_password: admin odm: diff --git a/Tests/Resources/Fixtures/config/single.yml b/Tests/Resources/Fixtures/config/single.yml index 3c2437c0..068211e3 100644 --- a/Tests/Resources/Fixtures/config/single.yml +++ b/Tests/Resources/Fixtures/config/single.yml @@ -7,7 +7,7 @@ doctrine_phpcr: profiling: true parameters: - jackalope.factory: "Jackalope\Factory" + jackalope.factory: Jackalope\Factory jackalope.check_login_on_server: false jackalope.disable_stream_wrapper: false jackalope.auto_lastmodified: true diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index 7d9f1d84..32eb0a06 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\DependencyInjection; +namespace Doctrine\Bundle\PHPCRBundle\Tests\Unit\DependencyInjection; use Doctrine\Bundle\PHPCRBundle\DependencyInjection\DoctrinePHPCRExtension; use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Configuration;