diff --git a/.travis.yml b/.travis.yml index cc4e8671f2333..51d0c0a2dfb4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -86,7 +86,7 @@ install: - export COMPOSER_ROOT_VERSION=$SYMFONY_VERSION.x-dev - if [[ ! $skip && $deps ]]; then export SYMFONY_DEPRECATIONS_HELPER=weak; fi - if [[ ! $skip && $deps ]]; then mv composer.json.phpunit composer.json; fi - - if [[ ! $skip ]]; then composer update; fi + - if [[ ! $skip ]]; then composer update --no-suggest; fi - if [[ ! $skip ]]; then ./phpunit install; fi - if [[ ! $skip && ! $PHP = hhvm* ]]; then php -i; else hhvm --php -r 'print_r($_SERVER);print_r(ini_get_all());'; fi @@ -97,8 +97,8 @@ script: - if [[ ! $deps && ! $PHP = hhvm* ]]; then echo -e "\\nRunning tests requiring tty"; $PHPUNIT --group tty; fi - if [[ ! $deps && $PHP = hhvm* ]]; then $PHPUNIT --exclude-group benchmark,intl-data; fi - if [[ ! $deps && $PHP = ${MIN_PHP%.*} ]]; then echo -e "1\\n0" | xargs -I{} sh -c 'echo "\\nPHP --enable-sigchild enhanced={}" && ENHANCE_SIGCHLD={} php-$MIN_PHP/sapi/cli/php .phpunit/phpunit-4.8/phpunit --colors=always src/Symfony/Component/Process/'; fi - - if [[ $deps = high ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi; $PHPUNIT --exclude-group tty,benchmark,intl-data'$LEGACY"$REPORT"; fi - - if [[ $deps = low ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi --prefer-lowest --prefer-stable; $PHPUNIT --exclude-group tty,benchmark,intl-data'"$REPORT"; fi + - if [[ $deps = high ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --no-suggest --ansi; $PHPUNIT --exclude-group tty,benchmark,intl-data'$LEGACY"$REPORT"; fi + - if [[ $deps = low ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --no-suggest --ansi --prefer-lowest --prefer-stable; $PHPUNIT --exclude-group tty,benchmark,intl-data'"$REPORT"; fi # Test the PhpUnit bridge using the original phpunit script - if [[ $deps = low ]]; then (cd src/Symfony/Bridge/PhpUnit && wget https://phar.phpunit.de/phpunit-4.8.phar); fi - if [[ $deps = low ]]; then (cd src/Symfony/Bridge/PhpUnit && phpenv global 5.3 && php --version && composer update && php phpunit-4.8.phar); fi diff --git a/CHANGELOG-3.2.md b/CHANGELOG-3.2.md index 71a26930ea92b..93dc435ade79f 100644 --- a/CHANGELOG-3.2.md +++ b/CHANGELOG-3.2.md @@ -7,6 +7,51 @@ in 3.2 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v3.2.0...v3.2.1 +* 3.2.7 (2017-04-05) + + * bug #22285 [HttpKernel] Fix forward compat with Request::setTrustedProxies() (nicolas-grekas) + * bug #22265 Allow Upper Case property names (insekticid) + * bug #22258 [DI] Autowiring and factories are incompatible with each others (nicolas-grekas) + * bug #22254 [DI] Don't use auto-registered services to populate type-candidates (nicolas-grekas) + * bug #22229 [ExpressionLanguage] Provide the expression in syntax errors (k0pernikus, stof) + * bug #22251 [PropertyInfo] Support nullable array or collection (4rthem) + * bug #22240 [DI] Fix fatal error at ContainerBuilder::compile() if config is not installed (chalasr) + * bug #22140 [Form] Improve the exceptions when trying to get the data in a PRE_SET_DATA listener and the data has not already been set (fancyweb) + * bug #22217 [Console] Fix table cell styling (ro0NL) + * bug #22194 [Console] CommandTester: disable color support detection (julienfalque) + * bug #22188 [Console] Revised exception rendering (ro0NL) + * bug #22154 [WebProfilerBundle] Normalize whitespace in exceptions passed in headers (curry684) + * bug #22183 [Process] Fix bug which wiped or mangled env vars (pjcdawkins) + * bug #22142 [Console] Escape exception messages in renderException (chalasr) + * bug #22172 Fix port usage in server:status command (alcaeus) + * bug #22164 [Bridge\Doctrine] Fix change breaking doctrine-bundle test suite (nicolas-grekas) + * bug #22159 [FrameworkBundle] Cache pool clear command requires at least 1 pool (ro0NL) + * bug #22133 [Filesystem] normalize paths before making them relative (xabbuh) + * bug #22138 [HttpFoundation][bugfix] $bags should always be initialized (MacDada) + * bug #21810 #21809 [SecurityBundle] bugfix: if security provider's name contains upper cases then container didn't compile (Antanas Arvasevicius) + * bug #22123 [WebProfilerBundle] Fix for CSS attribute at Profiler Translation Page (e-moe) + * bug #19778 [Security] Fixed roles serialization on token from user object (eko) + * bug #22036 Set Date header in Response constructor already (mpdude) + * bug #22022 [Validator] fix URL validator to detect non supported chars according to RFC 3986 (e-moe) + * bug #21849 [HttpFoundation] Fix missing handling of for/host/proto info from "Forwarded" header (nicolas-grekas) + * bug #21968 Fixed pathinfo calculation for requests starting with a question mark. (syzygymsu) + * bug #22027 Revert "bug #21841 [Console] Do not squash input changes made from console.command event (chalasr)" (chalasr) + * bug #21846 [HttpFoundation] Fix Request::getHost() when having several hosts in X_FORWARDED_HOST (nicolas-grekas) + * bug #21208 [Validator] Add object handling of invalid constraints in Composite (SenseException) + * bug #22044 [Serializer] [XML] Ignore Process Instruction (jordscream) + * bug #22090 [WebProfilerBundle] Fix Content-Security-Policy compatibility in case of a `style-src 'self'` policy (romainneutron) + * bug #22079 [HttpKernel] Fixed bug with purging of HTTPS URLs (ausi) + * bug #22045 [WebProfilerBundle] Handle Content-Security-Policy-Report-Only header correctly (romainneutron) + * bug #21523 #20411 fix Yaml parsing for very long quoted strings (RichardBradley) + * bug #22001 [Doctrine Bridge] fix priority for doctrine event listeners (dmaicher) + * bug #22040 [FrameworkBundle] improve message when workflows are missing (xabbuh) + * bug #22032 [FrameworkBundle] Fix translation dep constraint (chalasr) + * bug #21996 [Cache] Enhance error reporting for FilesystemAdapter (nicolas-grekas) + * bug #21981 [Console] Use proper line endings in BufferedOutput (julienfalque) + * bug #21976 [VarDumper] Add missing isset() checks in some casters (nicolas-grekas) + * bug #21973 [VarDumper] Add missing isset() checks in some casters (nicolas-grekas) + * bug #21957 [Form] Choice type int values (BC Fix) (mcfedr) + * 3.2.6 (2017-03-10) * bug #21930 [Cache] Cached files rely on umask (4rthem) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e0f9ec4c5ab30..a29c7ec45376b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -23,25 +23,26 @@ Symfony is the result of the work of many people who made the code better - Pascal Borreli (pborreli) - Wouter De Jong (wouterj) - Romain Neutron (romain) + - Grégoire Pineau (lyrixx) - Joseph Bielawski (stloyd) - Karma Dordrak (drak) - Lukas Kahwe Smith (lsmith) - - Grégoire Pineau (lyrixx) - Martin Hasoň (hason) - - Jeremy Mikola (jmikola) + - Robin Chalas (chalas_r) - Maxime Steinhausser (ogizanagi) + - Jeremy Mikola (jmikola) - Jean-François Simon (jfsimon) - Benjamin Eberlei (beberlei) - Igor Wiedler (igorw) - - Robin Chalas (chalas_r) - Eriksen Costa (eriksencosta) - Jules Pietri (heah) - Sarah Khalil (saro0h) - Jonathan Wage (jwage) + - Guilhem Niot (energetick) - Diego Saint Esteben (dosten) + - Roland Franssen (ro0) - Alexandre Salomé (alexandresalome) - William Durand (couac) - - Guilhem Niot (energetick) - ornicar - Francis Besset (francisbesset) - stealth35 ‏ (stealth35) @@ -50,20 +51,20 @@ Symfony is the result of the work of many people who made the code better - Peter Rehm (rpet) - Saša Stamenković (umpirsky) - Henrik Bjørnskov (henrikbjorn) - - Roland Franssen (ro0) - Miha Vrhovnik - Roland Franssen (ro0) - Diego Saint Esteben (dii3g0) - Konstantin Kudryashov (everzet) - Bilal Amarni (bamarni) - Florin Patan (florinpatan) + - Matthias Pigulla (mpdude) - Kevin Bond (kbond) - Andrej Hudec (pulzarraider) - Gábor Egyed (1ed) - Michel Weimerskirch (mweimerskirch) - Eric Clemmons (ericclemmons) - Charles Sarrazin (csarrazi) - - Matthias Pigulla (mpdude) + - Pierre du Plessis (pierredup) - Christian Raue - Arnout Boks (aboks) - Deni @@ -71,39 +72,38 @@ Symfony is the result of the work of many people who made the code better - Dariusz Górecki (canni) - Titouan Galopin (tgalopin) - Douglas Greenshields (shieldo) - - Pierre du Plessis (pierredup) - Konstantin Myakshin (koc) - Lee McDermott - Brandon Turner - Luis Cordova (cordoval) + - Jáchym Toušek (enumag) - Graham Campbell (graham) - Daniel Holmes (dholmes) - Toni Uebernickel (havvg) - Bart van den Burg (burgov) - Jordan Alliot (jalliot) + - Jérémy DERUSSÉ (jderusse) - John Wards (johnwards) - Fran Moreno (franmomu) - - Jáchym Toušek (enumag) - Antoine Hérault (herzult) - Paráda József (paradajozsef) - Dariusz Ruminski - Arnaud Le Blanc (arnaud-lb) - Jérôme Tamarelle (gromnan) + - Maxime STEINHAUSSER - Michal Piotrowski (eventhorizon) - Tim Nagel (merk) - - Maxime STEINHAUSSER - Issei Murasawa (issei_m) - Brice BERNARD (brikou) - Alexander M. Turek (derrabus) + - Baptiste Clavié (talus) - marc.weistroff - lenar - Włodzimierz Gajda (gajdaw) - - Baptiste Clavié (talus) - Vladimir Reznichenko (kalessil) - Alexander Schwenn (xelaris) - Florian Voutzinos (florianv) - Colin Frei - - Jérémy DERUSSÉ (jderusse) - Adrien Brault (adrienbrault) - Joshua Thijssen - Peter Kokot (maastermedia) @@ -148,6 +148,7 @@ Symfony is the result of the work of many people who made the code better - Teoh Han Hui (teohhanhui) - Clemens Tolboom - Helmer Aaviksoo + - Grégoire Paris (greg0ire) - Hiromi Hishida (77web) - Richard van Laak (rvanlaak) - Matthieu Ouellette-Vachon (maoueh) @@ -160,7 +161,7 @@ Symfony is the result of the work of many people who made the code better - Warnar Boekkooi (boekkooi) - Dmitrii Chekaliuk (lazyhammer) - Clément JOBEILI (dator) - - Grégoire Paris (greg0ire) + - Dawid Nowak - Possum - Dorian Villet (gnutix) - Richard Miller (mr_r_miller) @@ -169,6 +170,7 @@ Symfony is the result of the work of many people who made the code better - Benjamin Dulau (dbenjamin) - James Halsall (jaitsu) - Mathieu Lemoine (lemoinem) + - Chris Wilkinson (thewilkybarkid) - Andreas Hucks (meandmymonkey) - Noel Guilbert (noel) - Lars Strojny (lstrojny) @@ -192,16 +194,15 @@ Symfony is the result of the work of many people who made the code better - John Kary (johnkary) - Justin Hileman (bobthecow) - Blanchon Vincent (blanchonvincent) - - Chris Wilkinson (thewilkybarkid) - Christian Schmidt - Michele Orselli (orso) - Tom Van Looy (tvlooy) - Sven Paulus (subsven) - Rui Marinho (ruimarinho) - SpacePossum - - Dawid Nowak - Eugene Wissner - Julien Brochet (mewt) + - Julien Falque (julienfalque) - Tristan Darricau (nicofuma) - Grégoire Paris (greg0ire) - Sergey Linnik (linniksa) @@ -213,6 +214,7 @@ Symfony is the result of the work of many people who made the code better - julien pauli (jpauli) - Lorenz Schori - Sébastien Lavoie (lavoiesl) + - David Maicher (dmaicher) - Francois Zaninotto - Alexander Kotynia (olden) - Daniel Tschinder @@ -237,7 +239,6 @@ Symfony is the result of the work of many people who made the code better - Uwe Jäger (uwej711) - Eugene Leonovich (rybakit) - Filippo Tessarotto - - Julien Falque (julienfalque) - Joseph Rouff (rouffj) - Félix Labrecque (woodspire) - GordonsLondon @@ -259,7 +260,6 @@ Symfony is the result of the work of many people who made the code better - Beau Simensen (simensen) - Michael Hirschler (mvhirsch) - Robert Kiss (kepten) - - David Maicher (dmaicher) - Roumen Damianoff (roumen) - Antonio J. García Lagar (ajgarlag) - Kim Hemsø Rasmussen (kimhemsoe) @@ -397,6 +397,7 @@ Symfony is the result of the work of many people who made the code better - EdgarPE - Florian Pfitzer (marmelatze) - Asier Illarramendi (doup) + - Andreas Braun - Chris Sedlmayr (catchamonkey) - Seb Koelen - Dany Maillard (maidmaid) @@ -416,6 +417,7 @@ Symfony is the result of the work of many people who made the code better - Gintautas Miselis - Rob Bast - David Badura (davidbadura) + - Jordan Samouh (jordansamouh) - Zander Baldwin - Adam Harvey - Alex Bakhturin @@ -460,11 +462,13 @@ Symfony is the result of the work of many people who made the code better - Jakub Škvára (jskvara) - Andrew Udvare (audvare) - alexpods + - Nikolay Labinskiy (e-moe) - Arjen van der Meijden - Michele Locati - Dariusz Ruminski - Erik Trapman (eriktrapman) - De Cock Xavier (xdecock) + - Arthur de Moulins (4rthem) - Almog Baku (almogbaku) - Scott Arciszewski - Norbert Orzechowicz (norzechowicz) @@ -511,8 +515,10 @@ Symfony is the result of the work of many people who made the code better - Disquedur - Michiel Boeckaert (milio) - Geoffrey Tran (geoff) + - Romain Pierre (romain-pierre) - Jan Behrens - Mantas Var (mvar) + - Frank de Jonge (frenkynet) - Sebastian Krebs - Jean-Christophe Cuvelier [Artack] - Christopher Davis (chrisguitarguy) @@ -540,8 +546,8 @@ Symfony is the result of the work of many people who made the code better - Maxime Douailin - Jean Pasdeloup (pasdeloup) - Benjamin Cremer (bcremer) + - Thierry Thuon (lepiaf) - Javier López (loalf) - - Andreas Braun - Reinier Kip - Geoffrey Brier (geoffrey-brier) - Dustin Dobervich (dustin10) @@ -554,6 +560,7 @@ Symfony is the result of the work of many people who made the code better - Kamil Kokot (pamil) - Aurimas Niekis (gcds) - Max Grigorian (maxakawizard) + - mcfedr (mcfedr) - Rostyslav Kinash - Maciej Malarz (malarzm) - Daisuke Ohata @@ -571,6 +578,7 @@ Symfony is the result of the work of many people who made the code better - Denis Brumann (dbrumann) - Quentin de Longraye (quentinus95) - Chris Heng (gigablah) + - Richard Bradley - Ulumuddin Yunus (joenoez) - Luc Vieillescazes (iamluc) - Johann Saunier (prophet777) @@ -630,6 +638,7 @@ Symfony is the result of the work of many people who made the code better - Besnik Br - Dariusz Ruminski - Joshua Nye + - Claudio Zizza - Dave Marshall (davedevelopment) - avorobiev - Venu @@ -648,6 +657,7 @@ Symfony is the result of the work of many people who made the code better - John Bohn (jbohn) - Marc Morera (mmoreram) - Andrew Hilobok (hilobok) + - Noah Heck (myesain) - Christian Soronellas (theunic) - Yosmany Garcia (yosmanyga) - Wouter de Wild @@ -655,17 +665,18 @@ Symfony is the result of the work of many people who made the code better - Degory Valentine - Benoit Lévêque (benoit_leveque) - Jeroen Fiege (fieg) - - Arthur de Moulins (4rthem) - Krzysiek Łabuś - Xavier Lacot (xavier) - possum - Denis Zunke (donalberto) + - Ahmed TAILOULOUTE (ahmedtai) - Olivier Maisonneuve (olineuve) - Masterklavi - Francis Turmel (fturmel) - Nikita Nefedov (nikita2206) - cgonzalez - Ben + - Vincent Composieux (eko) - Jayson Xu (superjavason) - Jaik Dean (jaikdean) - fago @@ -676,6 +687,7 @@ Symfony is the result of the work of many people who made the code better - James Michael DuPont - Tom Klingenberg - Christopher Hall (mythmakr) + - Patrick Dawkins (pjcdawkins) - Paul Kamer (pkamer) - Rafał Wrzeszcz (rafalwrzeszcz) - Reen Lokum @@ -721,6 +733,7 @@ Symfony is the result of the work of many people who made the code better - corphi - grizlik - Derek ROTH + - Dmytro Boiko (eagle) - Shin Ohno (ganchiku) - Geert De Deckere (geertdd) - Jan Kramer (jankramer) @@ -783,7 +796,6 @@ Symfony is the result of the work of many people who made the code better - Phan Thanh Ha (haphan) - Chris Jones (leek) - Colin O'Dell (colinodell) - - Frank de Jonge (frenkynet) - xaav - Mahmoud Mostafa (mahmoud) - Alessandro Lai @@ -809,7 +821,6 @@ Symfony is the result of the work of many people who made the code better - Zachary Tong (polyfractal) - Hryhorii Hrebiniuk - Dennis Fridrich (dfridrich) - - mcfedr (mcfedr) - hamza - dantleech - Bastien DURAND (deamon) @@ -842,6 +853,7 @@ Symfony is the result of the work of many people who made the code better - Troy McCabe - Ville Mattila - ilyes kooli + - gr1ev0us - Boris Vujicic (boris.vujicic) - Max Beutel - Antanas Arvasevicius @@ -865,10 +877,12 @@ Symfony is the result of the work of many people who made the code better - Martynas Narbutas - Bailey Parker - Eddie Jaoude + - Antanas Arvasevicius - Haritz Iturbe (hizai) - Nerijus Arlauskas (nercury) - SPolischook - Diego Sapriza + - Anton A. Sumin - Joan Cruz - inspiran - Cristobal Dabed @@ -965,6 +979,7 @@ Symfony is the result of the work of many people who made the code better - Aharon Perkel - matze - Abdul.Mohsen B. A. A + - Martin Auswöger - Benoît Burnichon - pthompson - Malaney J. Hill @@ -1010,7 +1025,9 @@ Symfony is the result of the work of many people who made the code better - Klaas Cuvelier (kcuvelier) - markusu49 - Steve Frécinaux + - Jules Lamur - ShiraNai7 + - Markus Fasselt (digilist) - Vašek Purchart (vasek-purchart) - Janusz Jabłoński (yanoosh) - Sandro Hopf @@ -1035,17 +1052,16 @@ Symfony is the result of the work of many people who made the code better - Luis Galeas - Martin Pärtel - George Mponos (gmponos) - - Noah Heck (myesain) - Patrick Daley (padrig) - Xavier Briand (xavierbriand) - Max Summe - WedgeSama - Felds Liscia - - Ahmed TAILOULOUTE (ahmedtai) - Maxime Veber (nek-) - Sullivan SENECHAL - Tadcka - Beth Binkovitz + - Gonzalo Míguez - Romain Geissler - Adrien Moiruad - Tomaz Ahlin @@ -1105,7 +1121,6 @@ Symfony is the result of the work of many people who made the code better - Konrad Mohrfeldt - Lance Chen - Andrew (drew) - - Nikolay Labinskiy (e-moe) - kor3k kor3k (kor3k) - Stelian Mocanita (stelian) - Flavian (2much) @@ -1144,11 +1159,9 @@ Symfony is the result of the work of many people who made the code better - victoria - Francisco Facioni (fran6co) - Iwan van Staveren (istaveren) - - Thierry Thuon (lepiaf) - Povilas S. (povilas) - pborreli - Eric Caron - - Richard Bradley - 2manypeople - Wing - Thomas Bibb @@ -1172,6 +1185,7 @@ Symfony is the result of the work of many people who made the code better - Michal Gebauer - Gleb Sidora - David Stone + - Niels Keurentjes (curry684) - Jovan Perovic (jperovic) - Pablo Maria Martelletti (pmartelletti) - Yassine Guedidi (yguedidi) @@ -1229,6 +1243,7 @@ Symfony is the result of the work of many people who made the code better - Brian Graham (incognito) - Kevin Vergauwen (innocenzo) - Alessio Baglio (ioalessio) + - Johannes Müller (johmue) - Jordi Llonch (jordillonch) - Cédric Dugat (ph3nol) - Philip Dahlstrøm (phidah) @@ -1290,6 +1305,7 @@ Symfony is the result of the work of many people who made the code better - Jérémy M (th3mouk) - Vincent LEFORT (vlefort) - Sadicov Vladimir (xtech) + - Kevin EMO (zarcox) - Alexander Zogheb - Rémi Blaise - Joel Marcey @@ -1302,7 +1318,6 @@ Symfony is the result of the work of many people who made the code better - adenkejawen - Ari Pringle (apringle) - Dan Ordille (dordille) - - Dmytro Boiko (eagle) - Jan Eichhorn (exeu) - Grégory Pelletier (ip512) - John Nickell (jrnickell) @@ -1351,7 +1366,6 @@ Symfony is the result of the work of many people who made the code better - ddebree - Tomas Liubinas - Alex - - Patrick Dawkins - Klaas Naaijkens - Daniel González Cerviño - Rafał @@ -1364,7 +1378,6 @@ Symfony is the result of the work of many people who made the code better - David Joos (djoos) - Denis Klementjev (dklementjev) - Tomáš Polívka (draczris) - - Vincent Composieux (eko) - Franz Liedke (franzliedke) - Christophe BECKER (goabonga) - gondo (gondo) @@ -1400,6 +1413,7 @@ Symfony is the result of the work of many people who made the code better - Curtis - Gabriel Moreira - Alexey Popkov + - ChS - Joseph Deray - Damian Sromek - Ben @@ -1438,6 +1452,7 @@ Symfony is the result of the work of many people who made the code better - znerol - Christian Eikermann - Antonio Angelino + - Matt Fields - Shawn Iwinski - Niklas Keller - Vladimir Sazhin @@ -1563,6 +1578,7 @@ Symfony is the result of the work of many people who made the code better - ibasaw (ibasaw) - Vladislav Krupenkin (ideea) - Imangazaliev Muhammad (imangazaliev) + - j0k (j0k) - joris de wit (jdewit) - Jérémy CROMBEZ (jeremy) - Jose Manuel Gonzalez (jgonzalez) diff --git a/appveyor.yml b/appveyor.yml index d5c663d5a041e..79be565e0dce8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -51,7 +51,7 @@ install: - copy /Y .composer\* %APPDATA%\Composer\ - php .github/build-packages.php "HEAD^" src\Symfony\Bridge\PhpUnit - IF %APPVEYOR_REPO_BRANCH%==master (SET COMPOSER_ROOT_VERSION=dev-master) ELSE (SET COMPOSER_ROOT_VERSION=%APPVEYOR_REPO_BRANCH%.x-dev) - - php composer.phar update --no-progress --ansi + - php composer.phar update --no-progress --no-suggest --ansi - php phpunit install test_script: diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php index 1739dc3aea92c..6d53d88aaf2e4 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php @@ -122,7 +122,7 @@ private function groupByConnection(array $services, $isListener = false) } $instance['event'] = array($instance['event']); - if (isset($instance['lazy']) && $instance['lazy']) { + if ($lazy = !empty($instance['lazy'])) { $this->container->getDefinition($id)->setPublic(true); } } diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php index 9477d8265529d..f199f16265fac 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php @@ -61,9 +61,9 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface * loaded objects * @param IdReader $idReader The reader for the object * IDs. + * @param null|EntityLoaderInterface $objectLoader The objects loader * @param ChoiceListFactoryInterface $factory The factory for creating * the loaded choice list - * @param null|EntityLoaderInterface $objectLoader The objects loader */ public function __construct($manager, $class, $idReader = null, $objectLoader = null, $factory = null) { diff --git a/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php b/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php index 89ac999f20301..1c9c82bc129e6 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php @@ -25,5 +25,7 @@ public function testConstruct() { $connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); $handler = new DbalSessionHandler($connection); + + $this->assertInstanceOf('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', $handler); } } diff --git a/src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php b/src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php index 51bddd1d9828c..444466764be57 100644 --- a/src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php @@ -36,7 +36,7 @@ public function testUsesRequestServerData() public function testUseRequestClientIp() { - Request::setTrustedProxies(array('192.168.0.1')); + Request::setTrustedProxies(array('192.168.0.1'), -1); list($event, $server) = $this->createRequestEvent(array('X_FORWARDED_FOR' => '192.168.0.2')); $processor = new WebProcessor(); diff --git a/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php b/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php index c2c5a55af954f..766420a91d75a 100644 --- a/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php @@ -35,14 +35,31 @@ public function getFunctions() ); } - public function canTransition($object, $transition, $name = null) + /** + * Returns true if the transition is enabled. + * + * @param object $subject A subject + * @param string $transitionName A transition + * @param string $name A workflow name + * + * @return bool true if the transition is enabled + */ + public function canTransition($subject, $transitionName, $name = null) { - return $this->workflowRegistry->get($object, $name)->can($object, $transition); + return $this->workflowRegistry->get($subject, $name)->can($subject, $transitionName); } - public function getEnabledTransitions($object, $name = null) + /** + * Returns all enabled transitions. + * + * @param object $subject A subject + * @param string $name A workflow name + * + * @return Transition[] All enabled transitions + */ + public function getEnabledTransitions($subject, $name = null) { - return $this->workflowRegistry->get($object, $name)->getEnabledTransitions($object); + return $this->workflowRegistry->get($subject, $name)->getEnabledTransitions($subject); } public function getName() diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index 34058749bca77..99672997441be 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -89,7 +89,10 @@ public function testThemeBlockInheritanceUsingDynamicExtend() ; $this->renderer->setTheme($view, array('page_dynamic_extends.html.twig')); - $this->renderer->searchAndRenderBlock($view, 'row'); + $this->assertMatchesXpath( + $this->renderer->searchAndRenderBlock($view, 'row'), + '/div/label[text()="child"]' + ); } public function isSelectedChoiceProvider() diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php index 82934e1845fea..eec7b0d7ea11b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php @@ -33,7 +33,7 @@ protected function configure() $this ->setName('cache:pool:clear') ->setDefinition(array( - new InputArgument('pools', InputArgument::IS_ARRAY, 'A list of cache pools or cache pool clearers'), + new InputArgument('pools', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'A list of cache pools or cache pool clearers'), )) ->setDescription('Clears cache pools') ->setHelp(<<<'EOF' diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStatusCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStatusCommand.php index d7cb9e7d08197..31f7078b1da08 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStatusCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStatusCommand.php @@ -32,7 +32,7 @@ protected function configure() { $this ->setDefinition(array( - new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1:8000'), + new InputArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1'), new InputOption('port', 'p', InputOption::VALUE_REQUIRED, 'Address port number', '8000'), )) ->setName('server:status') diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 601e120885fd9..277f0dc62ada5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -397,6 +397,10 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde return; } + if (!class_exists(Workflow\Workflow::class)) { + throw new LogicException('Workflow support cannot be enabled as the Workflow component is not installed.'); + } + $loader->load('workflow.xml'); $registryDefinition = $container->getDefinition('workflow.registry'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php index ba969c64ae1f4..fd3b611202252 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php @@ -57,11 +57,10 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup() // simply check that cache is warmed up $this->assertGreaterThanOrEqual(1, count($metaFiles)); $configCacheFactory = new ConfigCacheFactory(true); - $that = $this; foreach ($metaFiles as $file) { - $configCacheFactory->cache(substr($file, 0, -5), function () use ($that, $file) { - $that->fail(sprintf('Meta file "%s" is not fresh', (string) $file)); + $configCacheFactory->cache(substr($file, 0, -5), function () use ($file) { + $this->fail(sprintf('Meta file "%s" is not fresh', (string) $file)); }); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 7adf4035ecbc7..02bf30b96dad6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -387,7 +387,7 @@ public function testTranslator() $this->assertEquals('translator.default', (string) $container->getAlias('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator'); $options = $container->getDefinition('translator.default')->getArgument(3); - $files = array_map(function ($resource) { return realpath($resource); }, $options['resource_files']['en']); + $files = array_map('realpath', $options['resource_files']['en']); $ref = new \ReflectionClass('Symfony\Component\Validator\Validation'); $this->assertContains( strtr(dirname($ref->getFileName()).'/Resources/translations/validators.en.xlf', '/', DIRECTORY_SEPARATOR), diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.txt index 587543fb0a47f..ed0bcca6562eb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.txt @@ -11,7 +11,7 @@ | Requirements | name: [a-z]+ | | Class | Symfony\Component\Routing\Route | | Defaults | name: Joseph | -| Options | compiler_class: Symfony\Component\Routing\RouteCompiler | -| | opt1: val1 | -| | opt2: val2 | +| Options | compiler_class: Symfony\Component\Routing\RouteCompiler | +| | opt1: val1 | +| | opt2: val2 | +--------------+---------------------------------------------------------+ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt index e75c19e13112c..828f6316bedb9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt @@ -11,7 +11,7 @@ | Requirements | NO CUSTOM | | Class | Symfony\Component\Routing\Route | | Defaults | NONE | -| Options | compiler_class: Symfony\Component\Routing\RouteCompiler | -| | opt1: val1 | -| | opt2: val2 | +| Options | compiler_class: Symfony\Component\Routing\RouteCompiler | +| | opt1: val1 | +| | opt2: val2 | +--------------+---------------------------------------------------------+ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php index 415e031189c3a..166d8a33919df 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php @@ -134,18 +134,4 @@ public function getConfigs() array('config.yml', false), ); } - - protected function setUp() - { - parent::setUp(); - - $this->deleteTmpDir('SessionTest'); - } - - protected function tearDown() - { - parent::tearDown(); - - $this->deleteTmpDir('SessionTest'); - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/WebTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/WebTestCase.php index 50d4cfa4db269..2861297fe0256 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/WebTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/WebTestCase.php @@ -13,7 +13,6 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel\Kernel; class WebTestCase extends BaseWebTestCase { @@ -23,9 +22,19 @@ public static function assertRedirect($response, $location) self::assertEquals('http://localhost'.$location, $response->headers->get('Location')); } - protected function deleteTmpDir($testCase) + public static function setUpBeforeClass() { - if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$testCase)) { + static::deleteTmpDir(); + } + + public static function tearDownAfterClass() + { + static::deleteTmpDir(); + } + + protected static function deleteTmpDir() + { + if (!file_exists($dir = sys_get_temp_dir().'/'.static::getVarDir())) { return; } @@ -49,10 +58,16 @@ protected static function createKernel(array $options = array()) } return new $class( + static::getVarDir(), $options['test_case'], isset($options['root_config']) ? $options['root_config'] : 'config.yml', - isset($options['environment']) ? $options['environment'] : 'frameworkbundletest'.strtolower($options['test_case']), + isset($options['environment']) ? $options['environment'] : strtolower(static::getVarDir().$options['test_case']), isset($options['debug']) ? $options['debug'] : true ); } + + protected static function getVarDir() + { + return substr(strrchr(get_called_class(), '\\'), 1); + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php index b07d44fe22be5..8e14b53a7472d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php @@ -46,14 +46,16 @@ */ class AppKernel extends Kernel { + private $varDir; private $testCase; private $rootConfig; - public function __construct($testCase, $rootConfig, $environment, $debug) + public function __construct($varDir, $testCase, $rootConfig, $environment, $debug) { if (!is_dir(__DIR__.'/'.$testCase)) { throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase)); } + $this->varDir = $varDir; $this->testCase = $testCase; $fs = new Filesystem(); @@ -81,12 +83,12 @@ public function getRootDir() public function getCacheDir() { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment; + return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment; } public function getLogDir() { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/logs'; + return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/logs'; } public function registerContainerConfiguration(LoaderInterface $loader) @@ -96,13 +98,13 @@ public function registerContainerConfiguration(LoaderInterface $loader) public function serialize() { - return serialize(array($this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug())); + return serialize(array($this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug())); } public function unserialize($str) { $a = unserialize($str); - $this->__construct($a[0], $a[1], $a[2], $a[3]); + $this->__construct($a[0], $a[1], $a[2], $a[3], $a[4]); } protected function getKernelParameters() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/StopwatchHelperTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/StopwatchHelperTest.php index cf7b627a499a6..686c655aac8f2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/StopwatchHelperTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/StopwatchHelperTest.php @@ -30,11 +30,10 @@ public function testDevEnvironment() public function testProdEnvironment() { $helper = new StopwatchHelper(null); + $helper->start('foo'); - try { - $helper->start('foo'); - } catch (\BadMethodCallException $e) { - $this->fail('Assumed stopwatch is not called when not provided'); - } + // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above + // can be executed without throwing any exceptions + $this->addToAssertionCount(1); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php index c49010bfdc357..1f6f51dd3351d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php @@ -19,21 +19,9 @@ class TemplateTest extends TestCase /** * @dataProvider getTemplateToPathProvider */ - public function testGetPathForTemplatesInABundle($template, $path) + public function testGetPathForTemplate($template, $path) { - if ($template->get('bundle')) { - $this->assertEquals($template->getPath(), $path); - } - } - - /** - * @dataProvider getTemplateToPathProvider - */ - public function testGetPathForTemplatesOutOfABundle($template, $path) - { - if (!$template->get('bundle')) { - $this->assertEquals($template->getPath(), $path); - } + $this->assertSame($template->getPath(), $path); } public function getTemplateToPathProvider() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php index 1ac206185589c..d9efdfe6e94d5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php @@ -136,6 +136,17 @@ public function testGetDefaultLocale() $this->assertSame('en', $translator->getLocale()); } + /** + * @expectedException \Symfony\Component\Translation\Exception\InvalidArgumentException + * @expectedExceptionMessage The Translator does not support the following options: 'foo' + */ + public function testInvalidOptions() + { + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); + + (new Translator($container, new MessageSelector(), array(), array('foo' => 'bar'))); + } + protected function getCatalogue($locale, $messages, $resources = array()) { $catalogue = new MessageCatalogue($locale); diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 5daeec7e4e76d..33e95059ff181 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -36,7 +36,7 @@ "require-dev": { "symfony/asset": "~2.8|~3.0", "symfony/browser-kit": "~2.8|~3.0", - "symfony/console": "~2.8.8|~3.0.8|~3.1.2|~3.2", + "symfony/console": "~2.8.19|^3.2.7", "symfony/css-selector": "~2.8|~3.0", "symfony/dom-crawler": "~2.8|~3.0", "symfony/polyfill-intl-icu": "~1.0", @@ -47,9 +47,10 @@ "symfony/security-core": "~3.2", "symfony/security-csrf": "~2.8|~3.0", "symfony/serializer": "~2.8|~3.0", - "symfony/translation": "~2.8|~3.0", + "symfony/translation": "~3.2", "symfony/templating": "~2.8|~3.0", "symfony/validator": "~3.2", + "symfony/workflow": "~3.2", "symfony/yaml": "~3.2", "symfony/property-info": "~3.1", "doctrine/annotations": "~1.0", @@ -60,7 +61,8 @@ "conflict": { "phpdocumentor/reflection-docblock": "<3.0", "phpdocumentor/type-resolver": "<0.2.0", - "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0" + "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0", + "symfony/translation": "<3.2" }, "suggest": { "ext-apcu": "For best performance of the system caches", diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 7b5774361cbec..2a0cc97d51946 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -554,7 +554,7 @@ private function createUserProviders($config, ContainerBuilder $container) // Parses a tag and returns the id for the related user provider service private function createUserDaoProvider($name, $provider, ContainerBuilder $container) { - $name = $this->getUserProviderId(strtolower($name)); + $name = $this->getUserProviderId($name); // Doctrine Entity and In-memory DAO provider are managed by factories foreach ($this->userProviderFactories as $factory) { @@ -578,7 +578,7 @@ private function createUserDaoProvider($name, $provider, ContainerBuilder $conta if (isset($provider['chain'])) { $providers = array(); foreach ($provider['chain']['providers'] as $providerName) { - $providers[] = new Reference($this->getUserProviderId(strtolower($providerName))); + $providers[] = new Reference($this->getUserProviderId($providerName)); } $container @@ -593,7 +593,7 @@ private function createUserDaoProvider($name, $provider, ContainerBuilder $conta private function getUserProviderId($name) { - return 'security.user.provider.concrete.'.$name; + return 'security.user.provider.concrete.'.strtolower($name); } private function createExceptionListener($container, $config, $id, $defaultEntryPoint, $stateless) diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php index ddf3492108cb4..df7132b42b4bf 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php @@ -72,7 +72,7 @@ public function testFirewalls() foreach (array_keys($arguments[1]) as $contextId) { $contextDef = $container->getDefinition($contextId); $arguments = $contextDef->getArguments(); - $listeners[] = array_map(function ($ref) { return (string) $ref; }, $arguments['index_0']); + $listeners[] = array_map('strval', $arguments['index_0']); $configDef = $container->getDefinition((string) $arguments['index_2']); $configs[] = array_values($configDef->getArguments()); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php index 80211f5251b08..2d95d35065137 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php @@ -108,14 +108,4 @@ public function getConfigs() array('routes_as_path.yml'), ); } - - public static function setUpBeforeClass() - { - parent::deleteTmpDir('CsrfFormLogin'); - } - - public static function tearDownAfterClass() - { - parent::deleteTmpDir('CsrfFormLogin'); - } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php index 30d0935ffddd7..8179c2e942a6c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php @@ -43,14 +43,4 @@ public function testItUsesTheConfiguredEntryPointFromTheExceptionListenerWithFor "Custom entry point wasn't started" ); } - - public static function setUpBeforeClass() - { - parent::deleteTmpDir('FirewallEntryPoint'); - } - - public static function tearDownAfterClass() - { - parent::deleteTmpDir('FirewallEntryPoint'); - } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php index 2f19f3f8a1a9a..c2e766e9acca1 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php @@ -113,14 +113,4 @@ public function getConfigs() array('routes_as_path.yml'), ); } - - public static function setUpBeforeClass() - { - parent::deleteTmpDir('StandardFormLogin'); - } - - public static function tearDownAfterClass() - { - parent::deleteTmpDir('StandardFormLogin'); - } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php index 14c317966e21a..cb600764eaf42 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php @@ -76,14 +76,4 @@ public function getLocales() { return array(array('en'), array('de')); } - - public static function setUpBeforeClass() - { - parent::deleteTmpDir('StandardFormLogin'); - } - - public static function tearDownAfterClass() - { - parent::deleteTmpDir('StandardFormLogin'); - } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php index c7db437819a1c..3abfd9585f159 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php @@ -116,14 +116,4 @@ public function getConfigs() { return array(array('config.yml'), array('routes_as_path.yml')); } - - public static function setUpBeforeClass() - { - parent::deleteTmpDir('StandardFormLogin'); - } - - public static function tearDownAfterClass() - { - parent::deleteTmpDir('StandardFormLogin'); - } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php index db4c51c5f064d..039a5b325bad6 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php @@ -40,20 +40,6 @@ class SetAclCommandTest extends WebTestCase const OBJECT_CLASS = 'Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AclBundle\Entity\Car'; const SECURITY_CLASS = 'Symfony\Component\Security\Core\User\User'; - protected function setUp() - { - parent::setUp(); - - $this->deleteTmpDir('Acl'); - } - - protected function tearDown() - { - parent::tearDown(); - - $this->deleteTmpDir('Acl'); - } - public function testSetAclUser() { $objectId = 1; diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php index e5079c3283aac..f12e95671be2c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php @@ -70,14 +70,4 @@ protected function createAuthenticatedClient($username) return $client; } - - public static function setUpBeforeClass() - { - parent::deleteTmpDir('StandardFormLogin'); - } - - public static function tearDownAfterClass() - { - parent::deleteTmpDir('StandardFormLogin'); - } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/WebTestCase.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/WebTestCase.php index da07116ae0665..8bace799a37a8 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/WebTestCase.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/WebTestCase.php @@ -13,7 +13,6 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel\Kernel; class WebTestCase extends BaseWebTestCase { @@ -23,9 +22,19 @@ public static function assertRedirect($response, $location) self::assertEquals('http://localhost'.$location, $response->headers->get('Location')); } - protected static function deleteTmpDir($testCase) + public static function setUpBeforeClass() { - if (defined('HHVM_VERSION_ID') || !file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$testCase)) { + static::deleteTmpDir(); + } + + public static function tearDownAfterClass() + { + static::deleteTmpDir(); + } + + protected static function deleteTmpDir() + { + if (!file_exists($dir = sys_get_temp_dir().'/'.static::getVarDir())) { return; } @@ -49,10 +58,16 @@ protected static function createKernel(array $options = array()) } return new $class( + static::getVarDir(), $options['test_case'], isset($options['root_config']) ? $options['root_config'] : 'config.yml', - isset($options['environment']) ? $options['environment'] : 'securitybundletest'.strtolower($options['test_case']), + isset($options['environment']) ? $options['environment'] : strtolower(static::getVarDir().$options['test_case']), isset($options['debug']) ? $options['debug'] : true ); } + + protected static function getVarDir() + { + return substr(strrchr(get_called_class(), '\\'), 1); + } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php index b828c5acfd91b..c448b7c172d60 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php @@ -46,14 +46,16 @@ */ class AppKernel extends Kernel { + private $varDir; private $testCase; private $rootConfig; - public function __construct($testCase, $rootConfig, $environment, $debug) + public function __construct($varDir, $testCase, $rootConfig, $environment, $debug) { if (!is_dir(__DIR__.'/'.$testCase)) { throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase)); } + $this->varDir = $varDir; $this->testCase = $testCase; $fs = new Filesystem(); @@ -71,7 +73,7 @@ public function __construct($testCase, $rootConfig, $environment, $debug) public function getName() { if (null === $this->name) { - $this->name = parent::getName().md5($this->rootConfig); + $this->name = parent::getName().substr(md5($this->rootConfig), -16); } return $this->name; @@ -93,12 +95,12 @@ public function getRootDir() public function getCacheDir() { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment; + return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment; } public function getLogDir() { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/logs'; + return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/logs'; } public function registerContainerConfiguration(LoaderInterface $loader) @@ -108,13 +110,13 @@ public function registerContainerConfiguration(LoaderInterface $loader) public function serialize() { - return serialize(array($this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug())); + return serialize(array($this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug())); } public function unserialize($str) { $a = unserialize($str); - $this->__construct($a[0], $a[1], $a[2], $a[3]); + $this->__construct($a[0], $a[1], $a[2], $a[3], $a[4]); } protected function getKernelParameters() diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 80750570e4c43..33092d36466cd 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -40,14 +40,15 @@ class ProfilerController /** * Constructor. * - * @param UrlGeneratorInterface $generator The URL Generator - * @param Profiler $profiler The profiler - * @param \Twig_Environment $twig The twig environment - * @param array $templates The templates - * @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration) - * @param string $baseDir The project root directory + * @param UrlGeneratorInterface $generator The URL Generator + * @param Profiler $profiler The profiler + * @param \Twig_Environment $twig The twig environment + * @param array $templates The templates + * @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration) + * @param ContentSecurityPolicyHandler $cspHandler The Content-Security-Policy handler + * @param string $baseDir The project root directory */ - public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null) + public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'bottom', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null) { $this->generator = $generator; $this->profiler = $profiler; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php index 52168924d3303..782a393e6a978 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php @@ -108,6 +108,7 @@ private function removeCspHeaders(Response $response) { $response->headers->remove('X-Content-Security-Policy'); $response->headers->remove('Content-Security-Policy'); + $response->headers->remove('Content-Security-Policy-Report-Only'); } /** @@ -257,6 +258,10 @@ private function getCspHeaders(Response $response) $headers['Content-Security-Policy'] = $this->parseDirectives($response->headers->get('Content-Security-Policy')); } + if ($response->headers->has('Content-Security-Policy-Report-Only')) { + $headers['Content-Security-Policy-Report-Only'] = $this->parseDirectives($response->headers->get('Content-Security-Policy-Report-Only')); + } + if ($response->headers->has('X-Content-Security-Policy')) { $headers['X-Content-Security-Policy'] = $this->parseDirectives($response->headers->get('X-Content-Security-Policy')); } diff --git a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php index 760cb8365ee42..a40c42c88e73a 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php @@ -71,7 +71,7 @@ public function onKernelResponse(FilterResponseEvent $event) $this->urlGenerator->generate('_profiler', array('token' => $response->headers->get('X-Debug-Token')), UrlGeneratorInterface::ABSOLUTE_URL) ); } catch (\Exception $e) { - $response->headers->set('X-Debug-Error', get_class($e).': '.$e->getMessage()); + $response->headers->set('X-Debug-Error', get_class($e).': '.preg_replace('/\s+/', ' ', $e->getMessage())); } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig index 38a086395fec0..90b268fd4fb76 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig @@ -60,7 +60,6 @@ } #tree-menu .empty { border: 0; - mmargin: 0; padding: 0; } #tree-details-container { diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/translation.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/translation.html.twig index f5ff17680a236..31881953d8139 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/translation.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/translation.html.twig @@ -8,7 +8,7 @@ {{ include('@WebProfiler/Icon/translation.svg') }} {% set status_color = collector.countMissings ? 'red' : collector.countFallbacks ? 'yellow' %} {% set error_count = collector.countMissings + collector.countFallbacks %} - {{ error_count ?: collector.countdefines }} + {{ error_count ?: collector.countDefines }} {% endset %} {% set text %} @@ -28,7 +28,7 @@
Defined messages - {{ collector.countdefines }} + {{ collector.countDefines }}
{% endset %} @@ -65,7 +65,7 @@
- {{ collector.countdefines }} + {{ collector.countDefines }} Defined messages
@@ -96,7 +96,7 @@
-

Defined {{ messages_defined|length }}

+

Defined {{ collector.countDefines }}

@@ -114,7 +114,7 @@

-

Fallback {{ messages_fallback|length }}

+

Fallback {{ collector.countFallbacks }}

@@ -133,7 +133,7 @@

-

Missing {{ messages_missing|length }}

+

Missing {{ collector.countMissings }}

@@ -169,10 +169,10 @@ {% for message in messages %} {{ message.locale }} - {{ message.domain }} + {{ message.domain }} {{ message.count }} - {{ message.id }} + {{ message.id }} {% if message.transChoiceNumber is not null %} (pluralization is used) @@ -188,7 +188,7 @@

{% endif %} - {{ message.translation }} + {{ message.translation }} {% endfor %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig index bb5aea2f444ae..e8eb99c92943a 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig @@ -200,6 +200,9 @@ table tbody ul { .nowrap { white-space: pre; } +.prewrap { + white-space: pre-wrap; +} .newline { display: block; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig index 6a2de1d6911b5..a211617d7234d 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig @@ -1,15 +1,10 @@ -{% if 'normal' != position %} - - - {{ include('@WebProfiler/Profiler/toolbar.css.twig', { 'position': position, 'floatable': true }) }} - -
-{% endif %} + +
{% for name, template in templates %} @@ -28,10 +23,8 @@ {% endif %} {% endfor %} - {% if 'normal' != position %} - - {{ include('@WebProfiler/Icon/close.svg') }} - - {% endif %} + + {{ include('@WebProfiler/Icon/close.svg') }} +
diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig index ea038277c4bec..7dc541caae589 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_js.html.twig @@ -1,5 +1,8 @@
{{ include('@WebProfiler/Profiler/base_js.html.twig') }} + + {{ include('@WebProfiler/Profiler/toolbar.css.twig', { 'position': position, 'floatable': true }) }} + /*getMockBuilder('Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator')->getMock(); - return new ProfilerController($urlGenerator, $profiler, $twig, array(), 'normal', new ContentSecurityPolicyHandler($nonceGenerator)); + return new ProfilerController($urlGenerator, $profiler, $twig, array(), 'bottom', new ContentSecurityPolicyHandler($nonceGenerator)); } - return new ProfilerController($urlGenerator, $profiler, $twig, array(), 'normal'); + return new ProfilerController($urlGenerator, $profiler, $twig, array()); } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php index eb91f5d357570..51397783699ea 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php @@ -97,41 +97,41 @@ public function provideRequestAndResponsesForOnKernelResponse() array('csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce), $this->createRequest(), $this->createResponse(), - array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null), + array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null), ), array( $nonce, array('csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce), $this->createRequest($requestNonceHeaders), $this->createResponse($responseNonceHeaders), - array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null), + array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null), ), array( $nonce, array('csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce), $this->createRequest($requestNonceHeaders), $this->createResponse(), - array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null), + array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null), ), array( $nonce, array('csp_script_nonce' => $responseScriptNonce, 'csp_style_nonce' => $responseStyleNonce), $this->createRequest(), $this->createResponse($responseNonceHeaders), - array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null), + array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null), ), array( $nonce, array('csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce), $this->createRequest(), - $this->createResponse(array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:')), - array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'X-Content-Security-Policy' => null), + $this->createResponse(array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'Content-Security-Policy-Report-Only' => 'frame-ancestors http: ; form-action: http:')), + array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'Content-Security-Policy-Report-Only' => 'frame-ancestors http: ; form-action: http:', 'X-Content-Security-Policy' => null), ), array( $nonce, array('csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce), $this->createRequest(), - $this->createResponse(array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'')), - array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null), + $this->createResponse(array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'')), + array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain-report-only.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null), ), array( $nonce, diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php index da7495c8c419e..dff05c182c037 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php @@ -246,6 +246,27 @@ public function testThrowingUrlGenerator() $this->assertEquals('Exception: foo', $response->headers->get('X-Debug-Error')); } + public function testThrowingErrorCleanup() + { + $response = new Response(); + $response->headers->set('X-Debug-Token', 'xxxxxxxx'); + + $urlGenerator = $this->getUrlGeneratorMock(); + $urlGenerator + ->expects($this->once()) + ->method('generate') + ->with('_profiler', array('token' => 'xxxxxxxx')) + ->will($this->throwException(new \Exception("This\nmultiline\r\ntabbed text should\tcome out\r on\n \ta single plain\r\nline"))) + ; + + $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); + + $listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, 'bottom', $urlGenerator); + $listener->onKernelResponse($event); + + $this->assertEquals('Exception: This multiline tabbed text should come out on a single plain line', $response->headers->get('X-Debug-Error')); + } + protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'html', $hasSession = true) { $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->setMethods(array('getSession', 'isXmlHttpRequest', 'getRequestFormat'))->disableOriginalConstructor()->getMock(); diff --git a/src/Symfony/Component/Asset/PathPackage.php b/src/Symfony/Component/Asset/PathPackage.php index 906879f8b064d..a8785c53f4303 100644 --- a/src/Symfony/Component/Asset/PathPackage.php +++ b/src/Symfony/Component/Asset/PathPackage.php @@ -31,6 +31,7 @@ class PathPackage extends Package /** * @param string $basePath The base path to be prepended to relative paths * @param VersionStrategyInterface $versionStrategy The version strategy + * @param ContextInterface|null $context The context */ public function __construct($basePath, VersionStrategyInterface $versionStrategy, ContextInterface $context = null) { diff --git a/src/Symfony/Component/Cache/Adapter/FilesystemAdapterTrait.php b/src/Symfony/Component/Cache/Adapter/FilesystemAdapterTrait.php index 156fc5c1fb63a..d406c062c5908 100644 --- a/src/Symfony/Component/Cache/Adapter/FilesystemAdapterTrait.php +++ b/src/Symfony/Component/Cache/Adapter/FilesystemAdapterTrait.php @@ -47,7 +47,6 @@ private function init($namespace, $directory) } $this->directory = $dir; - $this->tmp = $this->directory.uniqid('', true); } /** @@ -81,19 +80,21 @@ protected function doDelete(array $ids) private function write($file, $data, $expiresAt = null) { - if (false === @file_put_contents($this->tmp, $data)) { - return false; - } - if (null !== $expiresAt) { - @touch($this->tmp, $expiresAt); - } + set_error_handler(__CLASS__.'::throwError'); + try { + if (null === $this->tmp) { + $this->tmp = $this->directory.uniqid('', true); + } + file_put_contents($this->tmp, $data); - if (@rename($this->tmp, $file)) { - return true; - } - @unlink($this->tmp); + if (null !== $expiresAt) { + touch($this->tmp, $expiresAt); + } - return false; + return rename($this->tmp, $file); + } finally { + restore_error_handler(); + } } private function getFile($id, $mkdir = false) @@ -107,4 +108,20 @@ private function getFile($id, $mkdir = false) return $dir.substr($hash, 2, 20); } + + /** + * @internal + */ + public static function throwError($type, $message, $file, $line) + { + throw new \ErrorException($message, 0, $type, $file, $line); + } + + public function __destruct() + { + parent::__destruct(); + if (null !== $this->tmp && file_exists($this->tmp)) { + unlink($this->tmp); + } + } } diff --git a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php index 4b1552e1d16c9..ad287576f59d3 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php @@ -57,7 +57,8 @@ function ($key, $value, $isHit) { * stores arrays in its latest versions. This factory method decorates the given * fallback pool with this adapter only if the current PHP version is supported. * - * @param string $file The PHP file were values are cached + * @param string $file The PHP file were values are cached + * @param CacheItemPoolInterface $fallbackPool Fallback for old PHP versions or opcache disabled * * @return CacheItemPoolInterface */ diff --git a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php index 51a35c6f71ab9..5cae772ef7fc8 100644 --- a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php @@ -34,7 +34,9 @@ class RedisAdapter extends AbstractAdapter private $redis; /** - * @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient + * @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient The redis client + * @param string $namespace The default namespace + * @param integer $defaultLifetime The default lifetime */ public function __construct($redisClient, $namespace = '', $defaultLifetime = 0) { diff --git a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php index 65a040ec7ca65..c3cbd3bef7e54 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php @@ -13,18 +13,6 @@ use Cache\IntegrationTests\CachePoolTest; -if (!class_exists('PHPUnit_Framework_TestCase')) { - abstract class AdapterTestCase - { - public static function setUpBeforeClass() - { - self::markTestSkipped('cache/integration-tests is not yet compatible with namespaced phpunit versions.'); - } - } - - return; -} - abstract class AdapterTestCase extends CachePoolTest { protected function setUp() diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PredisClusterAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PredisClusterAdapterTest.php index 89a98e4db40a5..6ed1c7d6a9f3b 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PredisClusterAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PredisClusterAdapterTest.php @@ -16,7 +16,7 @@ class PredisClusterAdapterTest extends AbstractRedisAdapterTest public static function setupBeforeClass() { parent::setupBeforeClass(); - self::$redis = new \Predis\Client(array(getenv('REDIS_HOST'))); + self::$redis = new \Predis\Client(array(array('host' => getenv('REDIS_HOST')))); } public static function tearDownAfterClass() diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php index 6456639af305e..63efd719b5f59 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php @@ -145,13 +145,16 @@ public function providePrototypedArrayNodeDefaults() public function testNestedPrototypedArrayNodes() { - $node = new ArrayNodeDefinition('root'); - $node + $nodeDefinition = new ArrayNodeDefinition('root'); + $nodeDefinition ->addDefaultChildrenIfNoneSet() ->prototype('array') ->prototype('array') ; - $node->getNode(); + $node = $nodeDefinition->getNode(); + + $this->assertInstanceOf('Symfony\Component\Config\Definition\PrototypedArrayNode', $node); + $this->assertInstanceOf('Symfony\Component\Config\Definition\PrototypedArrayNode', $node->getPrototype()); } public function testEnabledNodeDefaults() diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php index 16a10227cc296..13304fae36e95 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php @@ -71,6 +71,8 @@ public function testPrototypedArrayNodeUseTheCustomNodeBuilder() $root = $builder->root('override', 'array', new CustomNodeBuilder()); $root->prototype('bar')->end(); + + $this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\BarNode', $root->getNode(true)->getPrototype()); } public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren() @@ -79,7 +81,7 @@ public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren() $builder->root('propagation') ->children() - ->setNodeClass('extended', 'Symfony\Component\Config\Tests\Definition\Builder\VariableNodeDefinition') + ->setNodeClass('extended', 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition') ->node('foo', 'extended')->end() ->arrayNode('child') ->children() @@ -88,6 +90,15 @@ public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren() ->end() ->end() ->end(); + + $node = $builder->buildTree(); + $children = $node->getChildren(); + + $this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $children['foo']); + + $childChildren = $children['child']->getChildren(); + + $this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $childChildren['foo']); } public function testDefinitionInfoGetsTransferredToNode() diff --git a/src/Symfony/Component/Config/Tests/Fixtures/BarNode.php b/src/Symfony/Component/Config/Tests/Fixtures/BarNode.php new file mode 100644 index 0000000000000..0b9c32dedaf1f --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Fixtures/BarNode.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config\Tests\Fixtures; + +use Symfony\Component\Config\Definition\ArrayNode; + +class BarNode extends ArrayNode +{ +} diff --git a/src/Symfony/Component/Config/Tests/Fixtures/Builder/BarNodeDefinition.php b/src/Symfony/Component/Config/Tests/Fixtures/Builder/BarNodeDefinition.php index 47701c1b29eb8..0d46f3d2c8c01 100644 --- a/src/Symfony/Component/Config/Tests/Fixtures/Builder/BarNodeDefinition.php +++ b/src/Symfony/Component/Config/Tests/Fixtures/Builder/BarNodeDefinition.php @@ -12,10 +12,12 @@ namespace Symfony\Component\Config\Tests\Definition\Builder; use Symfony\Component\Config\Definition\Builder\NodeDefinition; +use Symfony\Component\Config\Tests\Fixtures\BarNode; class BarNodeDefinition extends NodeDefinition { protected function createNode() { + return new BarNode($this->name); } } diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 2eca8b6b10b3f..c9787bed11dac 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console; use Symfony\Component\Console\Exception\ExceptionInterface; +use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Helper\DebugFormatterHelper; use Symfony\Component\Console\Helper\ProcessHelper; use Symfony\Component\Console\Helper\QuestionHelper; @@ -634,12 +635,11 @@ public function renderException(\Exception $e, OutputInterface $output) if (defined('HHVM_VERSION') && $width > 1 << 31) { $width = 1 << 31; } - $formatter = $output->getFormatter(); $lines = array(); foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) { foreach ($this->splitStringByWidth($line, $width - 4) as $line) { // pre-format lines to get the right string length - $lineLength = $this->stringWidth(preg_replace('/\[[^m]*m/', '', $formatter->format($line))) + 4; + $lineLength = $this->stringWidth($line) + 4; $lines[] = array($line, $lineLength); $len = max($lineLength, $len); @@ -647,15 +647,15 @@ public function renderException(\Exception $e, OutputInterface $output) } $messages = array(); - $messages[] = $emptyLine = $formatter->format(sprintf('%s', str_repeat(' ', $len))); - $messages[] = $formatter->format(sprintf('%s%s', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title))))); + $messages[] = $emptyLine = sprintf('%s', str_repeat(' ', $len)); + $messages[] = sprintf('%s%s', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title)))); foreach ($lines as $line) { - $messages[] = $formatter->format(sprintf(' %s %s', $line[0], str_repeat(' ', $len - $line[1]))); + $messages[] = sprintf(' %s %s', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1])); } $messages[] = $emptyLine; $messages[] = ''; - $output->writeln($messages, OutputInterface::OUTPUT_RAW | OutputInterface::VERBOSITY_QUIET); + $output->writeln($messages, OutputInterface::VERBOSITY_QUIET); if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $output->writeln('Exception trace:', OutputInterface::VERBOSITY_QUIET); @@ -839,10 +839,6 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI // ignore invalid options/arguments for now, to allow the event listeners to customize the InputDefinition } - // don't bind the input again as it would override any input argument/option set from the command event in - // addition to being useless - $command->setInputBound(true); - $event = new ConsoleCommandEvent($command, $input, $output); $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event); diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index f2d881170e2e4..2aca302a1e8d0 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -40,7 +40,6 @@ class Command private $ignoreValidationErrors = false; private $applicationDefinitionMerged = false; private $applicationDefinitionMergedWithArgs = false; - private $inputBound = false; private $code; private $synopsis = array(); private $usages = array(); @@ -217,13 +216,11 @@ public function run(InputInterface $input, OutputInterface $output) $this->mergeApplicationDefinition(); // bind the input against the command specific arguments/options - if (!$this->inputBound) { - try { - $input->bind($this->definition); - } catch (ExceptionInterface $e) { - if (!$this->ignoreValidationErrors) { - throw $e; - } + try { + $input->bind($this->definition); + } catch (ExceptionInterface $e) { + if (!$this->ignoreValidationErrors) { + throw $e; } } @@ -652,14 +649,6 @@ public function getHelper($name) return $this->helperSet->get($name); } - /** - * @internal - */ - public function setInputBound($inputBound) - { - $this->inputBound = $inputBound; - } - /** * Validates a command name. * diff --git a/src/Symfony/Component/Console/Helper/Helper.php b/src/Symfony/Component/Console/Helper/Helper.php index 9c538d1a757c9..4fb176527a1d2 100644 --- a/src/Symfony/Component/Console/Helper/Helper.php +++ b/src/Symfony/Component/Console/Helper/Helper.php @@ -105,6 +105,11 @@ public static function formatMemory($memory) } public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string) + { + return self::strlen(self::removeDecoration($formatter, $string)); + } + + public static function removeDecoration(OutputFormatterInterface $formatter, $string) { $isDecorated = $formatter->isDecorated(); $formatter->setDecorated(false); @@ -114,6 +119,6 @@ public static function strlenWithoutDecoration(OutputFormatterInterface $formatt $string = preg_replace("/\033\[[^m]*m/", '', $string); $formatter->setDecorated($isDecorated); - return self::strlen($string); + return $string; } } diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 36f3301817aed..66962c94d8452 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -426,7 +426,7 @@ private function buildTableRows($rows) if (!strstr($cell, "\n")) { continue; } - $lines = explode("\n", $cell); + $lines = explode("\n", str_replace("\n", "\n", $cell)); foreach ($lines as $lineKey => $line) { if ($cell instanceof TableCell) { $line = new TableCell($line, array('colspan' => $cell->getColspan())); @@ -467,7 +467,7 @@ private function fillNextRows($rows, $line) $nbLines = $cell->getRowspan() - 1; $lines = array($cell); if (strstr($cell, "\n")) { - $lines = explode("\n", $cell); + $lines = explode("\n", str_replace("\n", "\n", $cell)); $nbLines = count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines; $rows[$line][$column] = new TableCell($lines[0], array('colspan' => $cell->getColspan())); @@ -602,9 +602,10 @@ private function calculateColumnsWidth($rows) foreach ($row as $i => $cell) { if ($cell instanceof TableCell) { - $textLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell); + $textContent = Helper::removeDecoration($this->output->getFormatter(), $cell); + $textLength = Helper::strlen($textContent); if ($textLength > 0) { - $contentColumns = str_split($cell, ceil($textLength / $cell->getColspan())); + $contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan())); foreach ($contentColumns as $position => $content) { $row[$i + $position] = $content; } diff --git a/src/Symfony/Component/Console/Output/BufferedOutput.php b/src/Symfony/Component/Console/Output/BufferedOutput.php index 5682fc2404f78..205b02f5fd5d1 100644 --- a/src/Symfony/Component/Console/Output/BufferedOutput.php +++ b/src/Symfony/Component/Console/Output/BufferedOutput.php @@ -42,7 +42,7 @@ protected function doWrite($message, $newline) $this->buffer .= $message; if ($newline) { - $this->buffer .= "\n"; + $this->buffer .= PHP_EOL; } } } diff --git a/src/Symfony/Component/Console/Tester/CommandTester.php b/src/Symfony/Component/Console/Tester/CommandTester.php index 080ace5c95911..0bb1603c33c6f 100644 --- a/src/Symfony/Component/Console/Tester/CommandTester.php +++ b/src/Symfony/Component/Console/Tester/CommandTester.php @@ -76,9 +76,7 @@ public function execute(array $input, array $options = array()) } $this->output = new StreamOutput(fopen('php://memory', 'w', false)); - if (isset($options['decorated'])) { - $this->output->setDecorated($options['decorated']); - } + $this->output->setDecorated(isset($options['decorated']) ? $options['decorated'] : false); if (isset($options['verbosity'])) { $this->output->setVerbosity($options['verbosity']); } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 25efc256dca7e..072f0d0b884b8 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -586,6 +586,21 @@ public function testRenderExceptionWithDoubleWidthCharacters() putenv('COLUMNS=120'); } + public function testRenderExceptionEscapesLines() + { + $application = new Application(); + $application->setAutoExit(false); + putenv('COLUMNS=22'); + $application->register('foo')->setCode(function () { + throw new \Exception('dont break here !'); + }); + $tester = new ApplicationTester($application); + + $tester->run(array('command' => 'foo'), array('decorated' => false)); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_escapeslines.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting'); + putenv('COLUMNS=120'); + } + public function testRun() { $application = new Application(); @@ -699,8 +714,12 @@ public function testVerboseValueNotBreakArguments() $input = new ArgvInput(array('cli.php', '-v', 'foo:bar')); $application->run($input, $output); + $this->addToAssertionCount(1); + $input = new ArgvInput(array('cli.php', '--verbose', 'foo:bar')); $application->run($input, $output); + + $this->addToAssertionCount(1); } public function testRunReturnsIntegerExitCode() @@ -1102,31 +1121,6 @@ public function testRunWithDispatcherAddingInputOptions() $this->assertEquals('some test value', $extraValue); } - public function testUpdateInputFromConsoleCommandEvent() - { - $dispatcher = $this->getDispatcher(); - $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) { - $event->getInput()->setOption('extra', 'overriden'); - }); - - $application = new Application(); - $application->setDispatcher($dispatcher); - $application->setAutoExit(false); - - $application - ->register('foo') - ->addOption('extra', null, InputOption::VALUE_REQUIRED) - ->setCode(function (InputInterface $input, OutputInterface $output) { - $output->write('foo.'); - }) - ; - - $tester = new ApplicationTester($application); - $tester->run(array('command' => 'foo', '--extra' => 'original')); - - $this->assertEquals('overriden', $tester->getInput()->getOption('extra')); - } - /** * @group legacy */ diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DummyOutput.php b/src/Symfony/Component/Console/Tests/Fixtures/DummyOutput.php index 0070c0a48676c..866e21437177a 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/DummyOutput.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/DummyOutput.php @@ -26,7 +26,7 @@ class DummyOutput extends BufferedOutput public function getLogs() { $logs = array(); - foreach (explode("\n", trim($this->fetch())) as $message) { + foreach (explode(PHP_EOL, trim($this->fetch())) as $message) { preg_match('/^\[(.*)\] (.*)/', $message, $matches); $logs[] = sprintf('%s %s', $matches[1], $matches[2]); } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt index 8276137bd886a..f41925f52a6ea 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt @@ -1,13 +1,13 @@ - - [Exception] - Third exception comment - + + [Exception] + Third exception comment + - - [Exception] - Second exception comment - + + [Exception] + Second exception comment + [Exception] diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt index b4a7b018af377..5adccdd70245f 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception3decorated.txt @@ -1,17 +1,17 @@ -  - [Exception]  - Third exception comment  -  +  + [Exception]  + Third exception comment  +  -  - [Exception]  - Second exception comment  -  +  + [Exception]  + Second exception comment  +     [Exception]  - First exception 

this is html

  + First exception

this is html

   foo3:bar diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt new file mode 100644 index 0000000000000..cf79b37a92d6e --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception_escapeslines.txt @@ -0,0 +1,9 @@ + + + [Exception] + dont break here < + info>! + + +foo + diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index 2a4b189f8474e..d8a8ff00875b2 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -34,7 +34,7 @@ protected function tearDown() } /** - * @dataProvider testRenderProvider + * @dataProvider renderProvider */ public function testRender($headers, $rows, $style, $expected, $decorated = false) { @@ -50,7 +50,7 @@ public function testRender($headers, $rows, $style, $expected, $decorated = fals } /** - * @dataProvider testRenderProvider + * @dataProvider renderProvider */ public function testRenderAddRows($headers, $rows, $style, $expected, $decorated = false) { @@ -66,7 +66,7 @@ public function testRenderAddRows($headers, $rows, $style, $expected, $decorated } /** - * @dataProvider testRenderProvider + * @dataProvider renderProvider */ public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $decorated = false) { @@ -83,7 +83,7 @@ public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $d $this->assertEquals($expected, $this->getOutputContent($output)); } - public function testRenderProvider() + public function renderProvider() { $books = array( array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'), @@ -511,6 +511,35 @@ public function testRenderProvider() | Dante Alighieri | J. R. R. Tolkien | J. R. R | +-----------------+------------------+---------+ +TABLE + , + true, + ), + 'Row with formatted cells containing a newline' => array( + array(), + array( + array( + new TableCell('Dont break'."\n".'here', array('colspan' => 2)), + ), + new TableSeparator(), + array( + 'foo', + new TableCell('Dont break'."\n".'here', array('rowspan' => 2)), + ), + array( + 'bar', + ), + ), + 'default', + <<<'TABLE' ++-------+------------+ +| Dont break | +| here | ++-------+------------+ +| foo | Dont break | +| bar | here | ++-------+------------+ + TABLE , true, diff --git a/src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php b/src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php index cb9f0e8ea1f5f..342992982aa50 100644 --- a/src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php +++ b/src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php @@ -70,7 +70,7 @@ public function testOutputMapping($logLevel, $outputVerbosity, $isOutput, $addVe $logger = new ConsoleLogger($out, $addVerbosityLevelMap); $logger->log($logLevel, 'foo bar'); $logs = $out->fetch(); - $this->assertEquals($isOutput ? "[$logLevel] foo bar\n" : '', $logs); + $this->assertEquals($isOutput ? "[$logLevel] foo bar".PHP_EOL : '', $logs); } public function provideOutputMappingParams() diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index 2fdd8456fdf76..f2ae4b102e13d 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -83,7 +83,7 @@ public function setHandler(callable $handler = null) /** * Sets the format for links to source files. * - * @param string|FileLinkFormatter $format The format for links to source files + * @param string|FileLinkFormatter $fileLinkFormat The format for links to source files * * @return string The previous file link format */ diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index ef8db76b358a1..6b75414c53237 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -29,7 +29,7 @@ class AutowirePass implements CompilerPassInterface private $definedTypes = array(); private $types; private $ambiguousServiceTypes = array(); - private $usedTypes = array(); + private $autowired = array(); /** * {@inheritdoc} @@ -46,25 +46,15 @@ public function process(ContainerBuilder $container) $this->completeDefinition($id, $definition); } } - - foreach ($this->usedTypes as $type => $id) { - if (isset($this->usedTypes[$type]) && isset($this->ambiguousServiceTypes[$type])) { - $classOrInterface = class_exists($type) ? 'class' : 'interface'; - $matchingServices = implode(', ', $this->ambiguousServiceTypes[$type]); - - throw new RuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". Multiple services exist for this %s (%s).', $type, $id, $classOrInterface, $matchingServices)); - } - } } finally { spl_autoload_unregister($throwingAutoloader); // Free memory and remove circular reference to container - $this->container = null; $this->reflectionClasses = array(); $this->definedTypes = array(); $this->types = null; $this->ambiguousServiceTypes = array(); - $this->usedTypes = array(); + $this->autowired = array(); } } @@ -100,6 +90,10 @@ public static function createResourceForClass(\ReflectionClass $reflectionClass) */ private function completeDefinition($id, Definition $definition) { + if ($definition->getFactory()) { + throw new RuntimeException(sprintf('Service "%s" can use either autowiring or a factory, not both.', $id)); + } + if (!$reflectionClass = $this->getReflectionClass($id, $definition)) { return; } @@ -111,47 +105,56 @@ private function completeDefinition($id, Definition $definition) if (!$constructor = $reflectionClass->getConstructor()) { return; } + $parameters = $constructor->getParameters(); + if (method_exists('ReflectionMethod', 'isVariadic') && $constructor->isVariadic()) { + array_pop($parameters); + } $arguments = $definition->getArguments(); - foreach ($constructor->getParameters() as $index => $parameter) { + foreach ($parameters as $index => $parameter) { if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) { continue; } try { if (!$typeHint = $parameter->getClass()) { + if (isset($arguments[$index])) { + continue; + } + // no default value? Then fail if (!$parameter->isOptional()) { throw new RuntimeException(sprintf('Unable to autowire argument index %d ($%s) for the service "%s". If this is an object, give it a type-hint. Otherwise, specify this argument\'s value explicitly.', $index, $parameter->name, $id)); } - if (!array_key_exists($index, $arguments)) { - // specifically pass the default value - $arguments[$index] = $parameter->getDefaultValue(); - } + // specifically pass the default value + $arguments[$index] = $parameter->getDefaultValue(); continue; } + if (isset($this->autowired[$typeHint->name])) { + return $this->autowired[$typeHint->name] ? new Reference($this->autowired[$typeHint->name]) : null; + } + if (null === $this->types) { $this->populateAvailableTypes(); } if (isset($this->types[$typeHint->name])) { $value = new Reference($this->types[$typeHint->name]); - $this->usedTypes[$typeHint->name] = $id; } else { try { $value = $this->createAutowiredDefinition($typeHint, $id); - $this->usedTypes[$typeHint->name] = $id; } catch (RuntimeException $e) { - if ($parameter->allowsNull()) { - $value = null; - } elseif ($parameter->isDefaultValueAvailable()) { + if ($parameter->isDefaultValueAvailable()) { $value = $parameter->getDefaultValue(); + } elseif ($parameter->allowsNull()) { + $value = null; } else { throw $e; } + $this->autowired[$typeHint->name] = false; } } } catch (\ReflectionException $e) { @@ -167,6 +170,16 @@ private function completeDefinition($id, Definition $definition) $arguments[$index] = $value; } + if ($parameters && !isset($arguments[++$index])) { + while (0 <= --$index) { + $parameter = $parameters[$index]; + if (!$parameter->isDefaultValueAvailable() || $parameter->getDefaultValue() !== $arguments[$index]) { + break; + } + unset($arguments[$index]); + } + } + // it's possible index 1 was set, then index 0, then 2, etc // make sure that we re-order so they're injected as expected ksort($arguments); @@ -275,13 +288,11 @@ private function createAutowiredDefinition(\ReflectionClass $typeHint, $id) throw new RuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". No services were found matching this %s and it cannot be auto-registered.', $typeHint->name, $id, $classOrInterface)); } - $argumentId = sprintf('autowired.%s', $typeHint->name); + $this->autowired[$typeHint->name] = $argumentId = sprintf('autowired.%s', $typeHint->name); $argumentDefinition = $this->container->register($argumentId, $typeHint->name); $argumentDefinition->setPublic(false); - $this->populateAvailableType($argumentId, $argumentDefinition); - try { $this->completeDefinition($argumentId, $argumentDefinition); } catch (RuntimeException $e) { diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index d0c4d00444750..b2a1d77a6dd9f 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -26,6 +26,7 @@ use Symfony\Component\Config\Resource\ResourceInterface; use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface; use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\ExpressionLanguage\Expression; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; @@ -68,7 +69,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface */ private $compiler; - private $trackResources = true; + private $trackResources; /** * @var InstantiatorInterface|null @@ -85,6 +86,13 @@ class ContainerBuilder extends Container implements TaggedContainerInterface */ private $expressionLanguageProviders = array(); + public function __construct(ParameterBagInterface $parameterBag = null) + { + parent::__construct($parameterBag); + + $this->trackResources = interface_exists('Symfony\Component\Config\Resource\ResourceInterface'); + } + /** * @var string[] with tag names used by findTaggedServiceIds */ diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 152605167ecd5..690564703bc95 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -632,7 +632,7 @@ private function addService($id, Definition $definition) } if ($definition->isAutowired()) { - $doc = <<yamlParser) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index 67f313f72283d..8f5c795d4a314 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -440,10 +440,6 @@ public function testOptionalScalarArgsNotPassedIfLast() array( new Reference('a'), new Reference('lille'), - // third arg shouldn't *need* to be passed - // but that's hard to "pull of" with autowiring, so - // this assumes passing the default val is ok - 'some_val', ), $definition->getArguments() ); @@ -513,30 +509,29 @@ public function testEmptyStringIsKept() $this->assertEquals(array(new Reference('a'), '', new Reference('lille')), $container->getDefinition('foo')->getArguments()); } + public function provideAutodiscoveredAutowiringOrder() + { + return array( + array('CannotBeAutowiredForwardOrder'), + array('CannotBeAutowiredReverseOrder'), + ); + } + /** - * @dataProvider provideAutodiscoveredAutowiringOrder - * * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException - * @expectedExceptionMEssage Unable to autowire argument of type "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" for the service "a". Multiple services exist for this interface (autowired.Symfony\Component\DependencyInjection\Tests\Compiler\CollisionA, autowired.Symfony\Component\DependencyInjection\Tests\Compiler\CollisionB). + * @expectedExceptionMessage Service "a" can use either autowiring or a factory, not both. */ - public function testAutodiscoveredAutowiringOrder($class) + public function testWithFactory() { $container = new ContainerBuilder(); - $container->register('a', __NAMESPACE__.'\\'.$class) + $container->register('a', __NAMESPACE__.'\A') + ->setFactory('foo') ->setAutowired(true); $pass = new AutowirePass(); $pass->process($container); } - - public function provideAutodiscoveredAutowiringOrder() - { - return array( - array('CannotBeAutowiredForwardOrder'), - array('CannotBeAutowiredReverseOrder'), - ); - } } class Foo diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php index d894f7ab6f6d0..220348f4fecf2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php @@ -114,6 +114,8 @@ public function testProcessIgnoresMethodCalls() $container->register('b')->addMethodCall('setA', array(new Reference('a'))); $this->process($container); + + $this->addToAssertionCount(1); } protected function process(ContainerBuilder $container) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php index c5f236668cdb6..585bb357669b4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php @@ -48,6 +48,8 @@ public function testProcess() $container->register('d', 'class')->setSynthetic(true); $this->process($container); + + $this->addToAssertionCount(1); } public function testValidTags() @@ -59,6 +61,8 @@ public function testValidTags() $container->register('d', 'class')->addTag('foo', array('bar' => 1.1)); $this->process($container); + + $this->addToAssertionCount(1); } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php index c5f4ec7f95690..65a782a4a83fc 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php @@ -28,6 +28,10 @@ public function testProcess() ->addArgument(new Reference('b')) ; $container->register('b', '\stdClass'); + + $this->process($container); + + $this->addToAssertionCount(1); } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckReferenceValidityPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckReferenceValidityPassTest.php index 5d5204ba5c546..231520cd70c07 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckReferenceValidityPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckReferenceValidityPassTest.php @@ -38,6 +38,8 @@ public function testProcess() $container->register('b'); $this->process($container); + + $this->addToAssertionCount(1); } protected function process(ContainerBuilder $container) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index b56911e0af085..c63d5ec18315c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -351,6 +351,8 @@ public function testCircularReferenceAllowanceForLazyServices() $dumper = new PhpDumper($container); $dumper->dump(); + + $this->addToAssertionCount(1); } public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServices() @@ -388,6 +390,8 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic $dumper->setProxyDumper(new DummyProxyDumper()); $dumper->dump(); + + $this->addToAssertionCount(1); } public function testDumpContainerBuilderWithFrozenConstructorIncludingPrivateServices() diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php index 924f2d99ddf9f..39c85b3e5d9f0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php @@ -141,6 +141,8 @@ public function testCompiledContainerCanBeDumped($containerFile) $container->compile(); $dumper = new XmlDumper($container); $dumper->dump(); + + $this->addToAssertionCount(1); } public function provideCompiledContainerData() diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php index a9724152f8ef1..00f11e925e17d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services24.php @@ -32,6 +32,9 @@ public function __construct() /** * Gets the 'foo' service. * + * This service is shared. + * This method always returns the same instance of the service. + * * This service is autowired. * * @return \Foo A Foo instance diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 1cd561a99ecb0..4c5518e5ec720 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -33,40 +33,33 @@ public static function setUpBeforeClass() require_once self::$fixturesPath.'/includes/ProjectExtension.php'; } - public function testLoadFile() + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessageRegExp /The file ".+" does not exist./ + */ + public function testLoadUnExistFile() { $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/ini')); $r = new \ReflectionObject($loader); $m = $r->getMethod('loadFile'); $m->setAccessible(true); - try { - $m->invoke($loader, 'foo.yml'); - $this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist'); - } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist'); - $this->assertEquals('The service file "foo.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist'); - } - - try { - $m->invoke($loader, 'parameters.ini'); - $this->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file'); - } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file'); - $this->assertEquals('The service file "parameters.ini" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file'); - } + $m->invoke($loader, 'foo.yml'); + } - $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml')); + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessageRegExp /The file ".+" does not contain valid YAML./ + */ + public function testLoadInvalidYamlFile() + { + $path = self::$fixturesPath.'/ini'; + $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator($path)); + $r = new \ReflectionObject($loader); + $m = $r->getMethod('loadFile'); + $m->setAccessible(true); - foreach (array('nonvalid1', 'nonvalid2') as $fixture) { - try { - $m->invoke($loader, $fixture.'.yml'); - $this->fail('->load() throws an InvalidArgumentException if the loaded file does not validate'); - } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not validate'); - $this->assertStringMatchesFormat('The service file "nonvalid%d.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not validate'); - } - } + $m->invoke($loader, $path.'/parameters.ini'); } /** @@ -90,6 +83,8 @@ public function provideInvalidFiles() array('bad_service'), array('bad_calls'), array('bad_format'), + array('nonvalid1'), + array('nonvalid2'), ); } diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index 2c977f4731291..01bfc0066ea25 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -93,7 +93,7 @@ public function getListenerPriority($eventName, $listener) */ public function hasListeners($eventName = null) { - return (bool) count($this->getListeners($eventName)); + return (bool) $this->getListeners($eventName); } /** diff --git a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php index 8af193a1cbf5d..49a2f39507bae 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php @@ -174,14 +174,20 @@ public function testDispatchNested() { $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $loop = 1; + $dispatchedEvents = 0; $dispatcher->addListener('foo', $listener1 = function () use ($dispatcher, &$loop) { ++$loop; if (2 == $loop) { $dispatcher->dispatch('foo'); } }); + $dispatcher->addListener('foo', function () use (&$dispatchedEvents) { + ++$dispatchedEvents; + }); $dispatcher->dispatch('foo'); + + $this->assertSame(2, $dispatchedEvents); } public function testDispatchReusedEventNested() diff --git a/src/Symfony/Component/ExpressionLanguage/Lexer.php b/src/Symfony/Component/ExpressionLanguage/Lexer.php index 26bb51d42e35e..8c10b72d86046 100644 --- a/src/Symfony/Component/ExpressionLanguage/Lexer.php +++ b/src/Symfony/Component/ExpressionLanguage/Lexer.php @@ -59,12 +59,12 @@ public function tokenize($expression) } elseif (false !== strpos(')]}', $expression[$cursor])) { // closing bracket if (empty($brackets)) { - throw new SyntaxError(sprintf('Unexpected "%s"', $expression[$cursor]), $cursor); + throw new SyntaxError(sprintf('Unexpected "%s"', $expression[$cursor]), $cursor, $expression); } list($expect, $cur) = array_pop($brackets); if ($expression[$cursor] != strtr($expect, '([{', ')]}')) { - throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur); + throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur, $expression); } $tokens[] = new Token(Token::PUNCTUATION_TYPE, $expression[$cursor], $cursor + 1); @@ -87,7 +87,7 @@ public function tokenize($expression) $cursor += strlen($match[0]); } else { // unlexable - throw new SyntaxError(sprintf('Unexpected character "%s"', $expression[$cursor]), $cursor); + throw new SyntaxError(sprintf('Unexpected character "%s"', $expression[$cursor]), $cursor, $expression); } } @@ -95,9 +95,9 @@ public function tokenize($expression) if (!empty($brackets)) { list($expect, $cur) = array_pop($brackets); - throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur); + throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur, $expression); } - return new TokenStream($tokens); + return new TokenStream($tokens, $expression); } } diff --git a/src/Symfony/Component/ExpressionLanguage/Parser.php b/src/Symfony/Component/ExpressionLanguage/Parser.php index f8900bfb12916..c75972447dedf 100644 --- a/src/Symfony/Component/ExpressionLanguage/Parser.php +++ b/src/Symfony/Component/ExpressionLanguage/Parser.php @@ -99,7 +99,7 @@ public function parse(TokenStream $stream, $names = array()) $node = $this->parseExpression(); if (!$stream->isEOF()) { - throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s"', $stream->current->type, $stream->current->value), $stream->current->cursor); + throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s"', $stream->current->type, $stream->current->value), $stream->current->cursor, $stream->getExpression()); } return $node; @@ -195,13 +195,13 @@ public function parsePrimaryExpression() default: if ('(' === $this->stream->current->value) { if (false === isset($this->functions[$token->value])) { - throw new SyntaxError(sprintf('The function "%s" does not exist', $token->value), $token->cursor); + throw new SyntaxError(sprintf('The function "%s" does not exist', $token->value), $token->cursor, $this->stream->getExpression()); } $node = new Node\FunctionNode($token->value, $this->parseArguments()); } else { if (!in_array($token->value, $this->names, true)) { - throw new SyntaxError(sprintf('Variable "%s" is not valid', $token->value), $token->cursor); + throw new SyntaxError(sprintf('Variable "%s" is not valid', $token->value), $token->cursor, $this->stream->getExpression()); } // is the name used in the compiled code different @@ -227,7 +227,7 @@ public function parsePrimaryExpression() } elseif ($token->test(Token::PUNCTUATION_TYPE, '{')) { $node = $this->parseHashExpression(); } else { - throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s"', $token->type, $token->value), $token->cursor); + throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s"', $token->type, $token->value), $token->cursor, $this->stream->getExpression()); } } @@ -289,7 +289,7 @@ public function parseHashExpression() } else { $current = $this->stream->current; - throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s"', $current->type, $current->value), $current->cursor); + throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s"', $current->type, $current->value), $current->cursor, $this->stream->getExpression()); } $this->stream->expect(Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)'); @@ -327,7 +327,7 @@ public function parsePostfixExpression($node) // As a result, if $token is NOT an operator OR $token->value is NOT a valid property or method name, an exception shall be thrown. ($token->type !== Token::OPERATOR_TYPE || !preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A', $token->value)) ) { - throw new SyntaxError('Expected name', $token->cursor); + throw new SyntaxError('Expected name', $token->cursor, $this->stream->getExpression()); } $arg = new Node\ConstantNode($token->value, true); diff --git a/src/Symfony/Component/ExpressionLanguage/SyntaxError.php b/src/Symfony/Component/ExpressionLanguage/SyntaxError.php index d149c00768ad8..9373e9980b8f5 100644 --- a/src/Symfony/Component/ExpressionLanguage/SyntaxError.php +++ b/src/Symfony/Component/ExpressionLanguage/SyntaxError.php @@ -13,8 +13,14 @@ class SyntaxError extends \LogicException { - public function __construct($message, $cursor = 0) + public function __construct($message, $cursor = 0, $expression = '') { - parent::__construct(sprintf('%s around position %d.', $message, $cursor)); + $message = sprintf('%s around position %d', $message, $cursor); + if ($expression) { + $message = sprintf('%s for expression `%s`', $message, $expression); + } + $message .= '.'; + + parent::__construct($message); } } diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php index 4292c22359692..87c16f707b92c 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php @@ -18,14 +18,43 @@ class LexerTest extends TestCase { + /** + * @var Lexer + */ + private $lexer; + + protected function setUp() + { + $this->lexer = new Lexer(); + } + /** * @dataProvider getTokenizeData */ public function testTokenize($tokens, $expression) { $tokens[] = new Token('end of expression', null, strlen($expression) + 1); - $lexer = new Lexer(); - $this->assertEquals(new TokenStream($tokens), $lexer->tokenize($expression)); + $this->assertEquals(new TokenStream($tokens, $expression), $this->lexer->tokenize($expression)); + } + + /** + * @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError + * @expectedExceptionMessage Unexpected character "'" around position 33 for expression `service(faulty.expression.example').dummyMethod()`. + */ + public function testTokenizeThrowsErrorWithMessage() + { + $expression = "service(faulty.expression.example').dummyMethod()"; + $this->lexer->tokenize($expression); + } + + /** + * @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError + * @expectedExceptionMessage Unclosed "(" around position 7 for expression `service(unclosed.expression.dummyMethod()`. + */ + public function testTokenizeThrowsErrorOnUnclosedBrace() + { + $expression = 'service(unclosed.expression.dummyMethod()'; + $this->lexer->tokenize($expression); } public function getTokenizeData() diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/ParserTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/ParserTest.php index b8b954afe00f9..13b80cd64fbed 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/ParserTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/ParserTest.php @@ -20,7 +20,7 @@ class ParserTest extends TestCase { /** * @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError - * @expectedExceptionMessage Variable "foo" is not valid around position 1. + * @expectedExceptionMessage Variable "foo" is not valid around position 1 for expression `foo`. */ public function testParseWithInvalidName() { @@ -31,7 +31,7 @@ public function testParseWithInvalidName() /** * @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError - * @expectedExceptionMessage Variable "foo" is not valid around position 1. + * @expectedExceptionMessage Variable "foo" is not valid around position 1 for expression `foo`. */ public function testParseWithZeroInNames() { diff --git a/src/Symfony/Component/ExpressionLanguage/TokenStream.php b/src/Symfony/Component/ExpressionLanguage/TokenStream.php index 6c4af745b2cfe..3c22fc1d46ed3 100644 --- a/src/Symfony/Component/ExpressionLanguage/TokenStream.php +++ b/src/Symfony/Component/ExpressionLanguage/TokenStream.php @@ -22,16 +22,19 @@ class TokenStream private $tokens; private $position = 0; + private $expression; /** * Constructor. * - * @param array $tokens An array of tokens + * @param array $tokens An array of tokens + * @param string $expression */ - public function __construct(array $tokens) + public function __construct(array $tokens, $expression = '') { $this->tokens = $tokens; $this->current = $tokens[0]; + $this->expression = $expression; } /** @@ -50,7 +53,7 @@ public function __toString() public function next() { if (!isset($this->tokens[$this->position])) { - throw new SyntaxError('Unexpected end of expression', $this->current->cursor); + throw new SyntaxError('Unexpected end of expression', $this->current->cursor, $this->expression); } ++$this->position; @@ -69,7 +72,7 @@ public function expect($type, $value = null, $message = null) { $token = $this->current; if (!$token->test($type, $value)) { - throw new SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)', $message ? $message.'. ' : '', $token->type, $token->value, $type, $value ? sprintf(' with value "%s"', $value) : ''), $token->cursor); + throw new SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)', $message ? $message.'. ' : '', $token->type, $token->value, $type, $value ? sprintf(' with value "%s"', $value) : ''), $token->cursor, $this->expression); } $this->next(); } @@ -83,4 +86,14 @@ public function isEOF() { return $this->current->type === Token::EOF_TYPE; } + + /** + * @internal + * + * @return string + */ + public function getExpression() + { + return $this->expression; + } } diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index c7e8586f0df72..b50f5ffe76a18 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -446,6 +446,31 @@ public function makePathRelative($endPath, $startPath) $startPathArr = explode('/', trim($startPath, '/')); $endPathArr = explode('/', trim($endPath, '/')); + if ('/' !== $startPath[0]) { + array_shift($startPathArr); + } + + if ('/' !== $endPath[0]) { + array_shift($endPathArr); + } + + $normalizePathArray = function ($pathSegments) { + $result = array(); + + foreach ($pathSegments as $segment) { + if ('..' === $segment) { + array_pop($result); + } else { + $result[] = $segment; + } + } + + return $result; + }; + + $startPathArr = $normalizePathArray($startPathArr); + $endPathArr = $normalizePathArray($endPathArr); + // Find for which directory the common path stops $index = 0; while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) { diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 5c9a7b39b8fa8..9d82d26dfc6a7 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -442,14 +442,22 @@ public function testChmodChangesFileMode() $this->assertFilePermissions(400, $file); } - public function testChmodWrongMod() + public function testChmodWithWrongModLeavesPreviousPermissionsUntouched() { $this->markAsSkippedIfChmodIsMissing(); + if (defined('HHVM_VERSION')) { + $this->markTestSkipped('chmod() changes permissions even when passing invalid modes on HHVM'); + } + $dir = $this->workspace.DIRECTORY_SEPARATOR.'file'; touch($dir); + $permissions = fileperms($dir); + $this->filesystem->chmod($dir, 'Wrongmode'); + + $this->assertSame($permissions, fileperms($dir)); } public function testChmodRecursive() @@ -536,7 +544,10 @@ public function testChown() $dir = $this->workspace.DIRECTORY_SEPARATOR.'dir'; mkdir($dir); - $this->filesystem->chown($dir, $this->getFileOwner($dir)); + $owner = $this->getFileOwner($dir); + $this->filesystem->chown($dir, $owner); + + $this->assertSame($owner, $this->getFileOwner($dir)); } public function testChownRecursive() @@ -548,7 +559,10 @@ public function testChownRecursive() $file = $dir.DIRECTORY_SEPARATOR.'file'; touch($file); - $this->filesystem->chown($dir, $this->getFileOwner($dir), true); + $owner = $this->getFileOwner($dir); + $this->filesystem->chown($dir, $owner, true); + + $this->assertSame($owner, $this->getFileOwner($file)); } public function testChownSymlink() @@ -562,7 +576,10 @@ public function testChownSymlink() $this->filesystem->symlink($file, $link); - $this->filesystem->chown($link, $this->getFileOwner($link)); + $owner = $this->getFileOwner($link); + $this->filesystem->chown($link, $owner); + + $this->assertSame($owner, $this->getFileOwner($link)); } public function testChownLink() @@ -633,7 +650,10 @@ public function testChgrp() $dir = $this->workspace.DIRECTORY_SEPARATOR.'dir'; mkdir($dir); - $this->filesystem->chgrp($dir, $this->getFileGroup($dir)); + $group = $this->getFileGroup($dir); + $this->filesystem->chgrp($dir, $group); + + $this->assertSame($group, $this->getFileGroup($dir)); } public function testChgrpRecursive() @@ -645,7 +665,10 @@ public function testChgrpRecursive() $file = $dir.DIRECTORY_SEPARATOR.'file'; touch($file); - $this->filesystem->chgrp($dir, $this->getFileGroup($dir), true); + $group = $this->getFileGroup($dir); + $this->filesystem->chgrp($dir, $group, true); + + $this->assertSame($group, $this->getFileGroup($file)); } public function testChgrpSymlink() @@ -659,7 +682,10 @@ public function testChgrpSymlink() $this->filesystem->symlink($file, $link); - $this->filesystem->chgrp($link, $this->getFileGroup($link)); + $group = $this->getFileGroup($link); + $this->filesystem->chgrp($link, $group); + + $this->assertSame($group, $this->getFileGroup($link)); } public function testChgrpLink() @@ -1091,6 +1117,16 @@ public function providePathsForMakePathRelative() array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'), array('/aab/bb', '/aa', '../aab/bb/'), array('/aab', '/aa', '../aab/'), + array('/aa/bb/cc', '/aa/dd/..', 'bb/cc/'), + array('/aa/../bb/cc', '/aa/dd/..', '../bb/cc/'), + array('/aa/bb/../../cc', '/aa/../dd/..', 'cc/'), + array('/../aa/bb/cc', '/aa/dd/..', 'bb/cc/'), + array('/../../aa/../bb/cc', '/aa/dd/..', '../bb/cc/'), + array('C:/aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'), + array('c:/aa/../bb/cc', 'c:/aa/dd/..', '../bb/cc/'), + array('C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'), + array('C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'), + array('C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'), ); if ('\\' === DIRECTORY_SEPARATOR) { diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index 0eb8d31c99241..f4050d1f765e1 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -312,7 +312,7 @@ public function testGetIterator() $finder = $this->buildFinder(); $a = iterator_to_array($finder->directories()->in(self::$tmpDir)); - $a = array_values(array_map(function ($a) { return (string) $a; }, $a)); + $a = array_values(array_map('strval', $a)); sort($a); $this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface'); } diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php index 88531feaa222c..7fc191a054ff4 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php @@ -120,7 +120,7 @@ public function reverseTransform($value) $formatter = $this->getNumberFormatter(); // replace normal spaces so that the formatter can read them - $value = $formatter->parse(str_replace(' ', ' ', $value)); + $value = $formatter->parse(str_replace(' ', "\xc2\xa0", $value)); if (intl_is_failure($formatter->getErrorCode())) { throw new TransformationFailedException($formatter->getErrorMessage()); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 01c99eb538779..b117f70edf265 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -167,8 +167,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) } foreach ($data as $v) { - if (null !== $v && !is_string($v)) { - throw new TransformationFailedException('All choices submitted must be NULL or strings.'); + if (null !== $v && !is_string($v) && !is_int($v)) { + throw new TransformationFailedException('All choices submitted must be NULL, strings or ints.'); } } }, 256); diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index a04a17c90805e..cdbb0fe171824 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -407,6 +407,10 @@ public function getData() } if (!$this->defaultDataSet) { + if ($this->lockSetData) { + throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getData() if the form data has not already been set. You should call getData() on the FormEvent object instead.'); + } + $this->setData($this->config->getData()); } @@ -427,6 +431,10 @@ public function getNormData() } if (!$this->defaultDataSet) { + if ($this->lockSetData) { + throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set.'); + } + $this->setData($this->config->getData()); } @@ -447,6 +455,10 @@ public function getViewData() } if (!$this->defaultDataSet) { + if ($this->lockSetData) { + throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getViewData() if the form data has not already been set.'); + } + $this->setData($this->config->getData()); } diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index 810a0f7fae78f..55d1d74620f06 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -83,6 +83,8 @@ protected function assertMatchesXpath($html, $expression, $count = 1) // strip away and substr($dom->saveHTML(), 6, -8) )); + } else { + $this->addToAssertionCount(1); } } diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index 8ae32124a39e2..684f9215d4408 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -299,6 +299,8 @@ public function testRemoveThrowsExceptionIfAlreadySubmitted() public function testRemoveIgnoresUnknownName() { $this->form->remove('notexisting'); + + $this->assertCount(0, $this->form); } public function testArrayAccess() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 93f370341d319..15e08ae96f91e 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -102,7 +102,7 @@ public function testChoiceLoaderOptionExpectsChoiceLoaderInterface() public function testChoiceListAndChoicesCanBeEmpty() { - $this->factory->create(static::TESTED_TYPE); + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, null, array())); } public function testExpandedChoicesOptionsTurnIntoChildren() @@ -1367,6 +1367,18 @@ public function testSubmitMultipleExpandedObjectChoices() $this->assertNull($form[4]->getViewData()); } + public function testSubmitMultipleChoicesInts() + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'multiple' => true, + 'choices' => array_flip($this->numericChoicesFlipped), + )); + + $form->submit(array(1, 2)); + + $this->assertTrue($form->isSynchronized()); + } + public function testSingleSelectedObjectChoices() { $view = $this->factory->create(static::TESTED_TYPE, $this->objectChoices[3], array( @@ -1693,9 +1705,9 @@ public function testAdjustFullNameForMultipleNonExpanded() // https://github.com/symfony/symfony/issues/3298 public function testInitializeWithEmptyChoices() { - $this->factory->createNamed('name', static::TESTED_TYPE, null, array( + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->createNamed('name', static::TESTED_TYPE, null, array( 'choices' => array(), - )); + ))); } public function testInitializeWithDefaultObjectChoice() @@ -1757,7 +1769,7 @@ public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionDa $form->submit($submissionData); $this->assertFalse($form->isSynchronized()); - $this->assertEquals('All choices submitted must be NULL or strings.', $form->getTransformationFailure()->getMessage()); + $this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage()); } public function invalidNestedValueTestMatrix() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php index e7f91ce4405af..5f9af3e1c1b27 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php @@ -43,11 +43,13 @@ public function testUnknownCountryIsNotIncluded() $choices = $this->factory->create(static::TESTED_TYPE, 'country') ->createView()->vars['choices']; + $countryCodes = array(); + foreach ($choices as $choice) { - if ('ZZ' === $choice->value) { - $this->fail('Should not contain choice "ZZ"'); - } + $countryCodes[] = $choice->value; } + + $this->assertNotContains('ZZ', $countryCodes); } public function testSubmitNull($expected = null, $norm = null, $view = null) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php index 72a14f28f172e..cf55d7d1dbccf 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php @@ -273,7 +273,7 @@ public function testInitializeWithDateTime() { // Throws an exception if "data_class" option is not explicitly set // to null in the type - $this->factory->create(static::TESTED_TYPE, new \DateTime()); + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, new \DateTime())); } public function testSingleTextWidgetShouldUseTheRightInputType() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index c1f95096784fd..326c34c8c7430 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -598,7 +598,7 @@ public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyFilled() )); $form->submit(array( - 'day' => '0', + 'day' => '1', 'month' => '6', 'year' => '2010', )); @@ -711,7 +711,7 @@ public function testInitializeWithDateTime() { // Throws an exception if "data_class" option is not explicitly set // to null in the type - $this->factory->create(static::TESTED_TYPE, new \DateTime()); + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, new \DateTime())); } public function testSingleTextWidgetShouldUseTheRightInputType() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 640c8761c260b..8cf89cd7a45c5 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -141,23 +141,23 @@ public function testPassMaxLengthToView() public function testDataClassMayBeNull() { - $this->factory->createBuilder(static::TESTED_TYPE, null, array( + $this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array( 'data_class' => null, - )); + ))); } public function testDataClassMayBeAbstractClass() { - $this->factory->createBuilder(static::TESTED_TYPE, null, array( + $this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array( 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor', - )); + ))); } public function testDataClassMayBeInterface() { - $this->factory->createBuilder(static::TESTED_TYPE, null, array( + $this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array( 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface', - )); + ))); } /** diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php index a0913e8068084..369ebc0f6cb2c 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php @@ -488,7 +488,7 @@ public function testInitializeWithDateTime() { // Throws an exception if "data_class" option is not explicitly set // to null in the type - $this->factory->create(static::TESTED_TYPE, new \DateTime()); + $this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, new \DateTime())); } public function testSingleTextWidgetShouldUseTheRightInputType() diff --git a/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php index 8895da5b9b7ea..d11cbda564337 100644 --- a/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php @@ -62,21 +62,21 @@ public function testGetTypeExtensions() */ public function testThrowExceptionForInvalidExtendedType() { - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); + $formTypeExtension = $this->createFormTypeExtensionMock('unmatched'); - $typeExtension = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock(); - $typeExtension->expects($this->any()) - ->method('getExtendedType') - ->willReturn('unmatched'); + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container->expects($this->any()) ->method('get') ->with('extension') - ->willReturn($typeExtension); + ->willReturn($formTypeExtension); $extension = new DependencyInjectionExtension($container, array(), array('test' => array('extension')), array()); - $extension->getTypeExtensions('test'); + $extensions = $extension->getTypeExtensions('test'); + + $this->assertCount(1, $extensions); + $this->assertSame($formTypeExtension, $extensions[0]); } public function testGetTypeGuesser() diff --git a/src/Symfony/Component/Form/Tests/FormBuilderTest.php b/src/Symfony/Component/Form/Tests/FormBuilderTest.php index e5ac9ad327a69..2ecd19f5eaabb 100644 --- a/src/Symfony/Component/Form/Tests/FormBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/FormBuilderTest.php @@ -161,6 +161,8 @@ public function testAddButton() { $this->builder->add(new ButtonBuilder('reset')); $this->builder->add(new SubmitButtonBuilder('submit')); + + $this->assertCount(2, $this->builder->all()); } public function testGetUnknown() diff --git a/src/Symfony/Component/Form/Tests/FormConfigTest.php b/src/Symfony/Component/Form/Tests/FormConfigTest.php index 21eabba871d38..bb922bf3d61ff 100644 --- a/src/Symfony/Component/Form/Tests/FormConfigTest.php +++ b/src/Symfony/Component/Form/Tests/FormConfigTest.php @@ -12,9 +12,7 @@ namespace Symfony\Component\Form\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\FormConfigBuilder; -use Symfony\Component\Form\Exception\InvalidArgumentException; /** * @author Bernhard Schussek @@ -24,72 +22,65 @@ class FormConfigTest extends TestCase public function getHtml4Ids() { return array( - array('z0', true), - array('A0', true), - array('A9', true), - array('Z0', true), - array('#', false), - array('a#', false), - array('a$', false), - array('a%', false), - array('a ', false), - array("a\t", false), - array("a\n", false), - array('a-', true), - array('a_', true), - array('a:', true), + array('z0'), + array('A0'), + array('A9'), + array('Z0'), + array('#', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a#', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a$', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a%', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a ', 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array("a\t", 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array("a\n", 'Symfony\Component\Form\Exception\InvalidArgumentException'), + array('a-'), + array('a_'), + array('a:'), // Periods are allowed by the HTML4 spec, but disallowed by us // because they break the generated property paths - array('a.', false), + array('a.', 'Symfony\Component\Form\Exception\InvalidArgumentException'), // Contrary to the HTML4 spec, we allow names starting with a // number, otherwise naming fields by collection indices is not // possible. // For root forms, leading digits will be stripped from the // "id" attribute to produce valid HTML4. - array('0', true), - array('9', true), + array('0'), + array('9'), // Contrary to the HTML4 spec, we allow names starting with an // underscore, since this is already a widely used practice in // Symfony. // For root forms, leading underscores will be stripped from the // "id" attribute to produce valid HTML4. - array('_', true), + array('_'), // Integers are allowed - array(0, true), - array(123, true), + array(0), + array(123), // NULL is allowed - array(null, true), + array(null), // Other types are not - array(1.23, false), - array(5., false), - array(true, false), - array(new \stdClass(), false), + array(1.23, 'Symfony\Component\Form\Exception\UnexpectedTypeException'), + array(5., 'Symfony\Component\Form\Exception\UnexpectedTypeException'), + array(true, 'Symfony\Component\Form\Exception\UnexpectedTypeException'), + array(new \stdClass(), 'Symfony\Component\Form\Exception\UnexpectedTypeException'), ); } /** * @dataProvider getHtml4Ids */ - public function testNameAcceptsOnlyNamesValidAsIdsInHtml4($name, $accepted) + public function testNameAcceptsOnlyNamesValidAsIdsInHtml4($name, $expectedException = null) { $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); - try { - new FormConfigBuilder($name, null, $dispatcher); - if (!$accepted) { - $this->fail(sprintf('The value "%s" should not be accepted', $name)); - } - } catch (UnexpectedTypeException $e) { - // if the value was not accepted, but should be, rethrow exception - if ($accepted) { - throw $e; - } - } catch (InvalidArgumentException $e) { - // if the value was not accepted, but should be, rethrow exception - if ($accepted) { - throw $e; - } + if (null !== $expectedException && method_exists($this, 'expectException')) { + $this->expectException($expectedException); + } elseif (null !== $expectedException) { + $this->setExpectedException($expectedException); } + + $formConfigBuilder = new FormConfigBuilder($name, null, $dispatcher); + + $this->assertSame((string) $name, $formConfigBuilder->getName()); } public function testGetRequestHandlerCreatesNativeRequestHandlerIfNotSet() @@ -109,27 +100,42 @@ public function testGetRequestHandlerReusesNativeRequestHandlerInstance() public function testSetMethodAllowsGet() { - $this->getConfigBuilder()->setMethod('GET'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('GET'); + + self::assertSame('GET', $formConfigBuilder->getMethod()); } public function testSetMethodAllowsPost() { - $this->getConfigBuilder()->setMethod('POST'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('POST'); + + self::assertSame('POST', $formConfigBuilder->getMethod()); } public function testSetMethodAllowsPut() { - $this->getConfigBuilder()->setMethod('PUT'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('PUT'); + + self::assertSame('PUT', $formConfigBuilder->getMethod()); } public function testSetMethodAllowsDelete() { - $this->getConfigBuilder()->setMethod('DELETE'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('DELETE'); + + self::assertSame('DELETE', $formConfigBuilder->getMethod()); } public function testSetMethodAllowsPatch() { - $this->getConfigBuilder()->setMethod('PATCH'); + $formConfigBuilder = $this->getConfigBuilder(); + $formConfigBuilder->setMethod('PATCH'); + + self::assertSame('PATCH', $formConfigBuilder->getMethod()); } /** diff --git a/src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php b/src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php index 052821c39dfec..ba19a6215a7b4 100644 --- a/src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php +++ b/src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php @@ -25,6 +25,8 @@ public function testTranslationFileIsValid($filePath) } else { \PHPUnit\Util\XML::loadfile($filePath, false, false, true); } + + $this->addToAssertionCount(1); } public function provideTranslationFiles() diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index 689f2e8f77ed3..a938a176ccd92 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -896,6 +896,7 @@ public function testViewDataMustBeObjectIfDataClassIsSet() /** * @expectedException \Symfony\Component\Form\Exception\RuntimeException + * @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead. */ public function testSetDataCannotInvokeItself() { @@ -911,10 +912,11 @@ public function testSetDataCannotInvokeItself() public function testSubmittingWrongDataIsIgnored() { + $called = 0; + $child = $this->getBuilder('child', $this->dispatcher); - $child->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { - // child form doesn't receive the wrong data that is submitted on parent - $this->assertNull($event->getData()); + $child->addEventListener(FormEvents::PRE_SUBMIT, function () use (&$called) { + ++$called; }); $parent = $this->getBuilder('parent', new EventDispatcher()) @@ -924,6 +926,8 @@ public function testSubmittingWrongDataIsIgnored() ->getForm(); $parent->submit('not-an-array'); + + $this->assertSame(0, $called, 'PRE_SUBMIT event listeners are not called for wrong data'); } public function testHandleRequestForwardsToRequestHandler() @@ -1026,14 +1030,17 @@ public function testPostSubmitDataIsNullIfInheritData() public function testSubmitIsNeverFiredIfInheritData() { + $called = 0; $form = $this->getBuilder() - ->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { - $this->fail('The SUBMIT event should not be fired'); + ->addEventListener(FormEvents::SUBMIT, function () use (&$called) { + ++$called; }) ->setInheritData(true) ->getForm(); $form->submit('foo'); + + $this->assertSame(0, $called, 'The SUBMIT event is not fired when data are inherited from the parent form'); } public function testInitializeSetsDefaultData() @@ -1062,6 +1069,51 @@ public function testInitializeFailsIfParent() $child->initialize(); } + /** + * @expectedException \Symfony\Component\Form\Exception\RuntimeException + * @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getData() if the form data has not already been set. You should call getData() on the FormEvent object instead. + */ + public function testCannotCallGetDataInPreSetDataListenerIfDataHasNotAlreadyBeenSet() + { + $config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher); + $config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { + $event->getForm()->getData(); + }); + $form = new Form($config); + + $form->setData('foo'); + } + + /** + * @expectedException \Symfony\Component\Form\Exception\RuntimeException + * @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set. + */ + public function testCannotCallGetNormDataInPreSetDataListener() + { + $config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher); + $config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { + $event->getForm()->getNormData(); + }); + $form = new Form($config); + + $form->setData('foo'); + } + + /** + * @expectedException \Symfony\Component\Form\Exception\RuntimeException + * @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getViewData() if the form data has not already been set. + */ + public function testCannotCallGetViewDataInPreSetDataListener() + { + $config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher); + $config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { + $event->getForm()->getViewData(); + }); + $form = new Form($config); + + $form->setData('foo'); + } + protected function createForm() { return $this->getBuilder()->getForm(); diff --git a/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php b/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php index 4328919651efa..89735ea6180c6 100644 --- a/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php +++ b/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php @@ -114,8 +114,11 @@ public function testUnset() public function testUnsetNonExistingSucceeds() { $map = new OrderedHashMap(); + $map['second'] = 2; unset($map['first']); + + $this->assertSame(array('second' => 2), iterator_to_array($map)); } public function testEmptyIteration() diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index adc73d2b83944..e38b5fe32dd2c 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -206,6 +206,15 @@ class Request protected static $requestFactory; + private $isForwardedValid = true; + + private static $forwardedParams = array( + self::HEADER_CLIENT_IP => 'for', + self::HEADER_CLIENT_HOST => 'host', + self::HEADER_CLIENT_PROTO => 'proto', + self::HEADER_CLIENT_PORT => 'host', + ); + /** * Constructor. * @@ -793,41 +802,13 @@ public function setSession(SessionInterface $session) */ public function getClientIps() { - $clientIps = array(); $ip = $this->server->get('REMOTE_ADDR'); if (!$this->isFromTrustedProxy()) { return array($ip); } - $hasTrustedForwardedHeader = self::$trustedHeaders[self::HEADER_FORWARDED] && $this->headers->has(self::$trustedHeaders[self::HEADER_FORWARDED]); - $hasTrustedClientIpHeader = self::$trustedHeaders[self::HEADER_CLIENT_IP] && $this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP]); - - if ($hasTrustedForwardedHeader) { - $forwardedHeader = $this->headers->get(self::$trustedHeaders[self::HEADER_FORWARDED]); - preg_match_all('{(for)=("?\[?)([a-z0-9\.:_\-/]*)}', $forwardedHeader, $matches); - $forwardedClientIps = $matches[3]; - - $forwardedClientIps = $this->normalizeAndFilterClientIps($forwardedClientIps, $ip); - $clientIps = $forwardedClientIps; - } - - if ($hasTrustedClientIpHeader) { - $xForwardedForClientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP]))); - - $xForwardedForClientIps = $this->normalizeAndFilterClientIps($xForwardedForClientIps, $ip); - $clientIps = $xForwardedForClientIps; - } - - if ($hasTrustedForwardedHeader && $hasTrustedClientIpHeader && $forwardedClientIps !== $xForwardedForClientIps) { - throw new ConflictingHeadersException('The request has both a trusted Forwarded header and a trusted Client IP header, conflicting with each other with regards to the originating IP addresses of the request. This is the result of a misconfiguration. You should either configure your proxy only to send one of these headers, or configure Symfony to distrust one of them.'); - } - - if (!$hasTrustedForwardedHeader && !$hasTrustedClientIpHeader) { - return $this->normalizeAndFilterClientIps(array(), $ip); - } - - return $clientIps; + return $this->getTrustedValues(self::HEADER_CLIENT_IP, $ip) ?: array($ip); } /** @@ -953,31 +934,25 @@ public function getScheme() */ public function getPort() { - if ($this->isFromTrustedProxy()) { - if (self::$trustedHeaders[self::HEADER_CLIENT_PORT] && $port = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PORT])) { - return $port; - } - - if (self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && 'https' === $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO], 'http')) { - return 443; - } + if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_PORT)) { + $host = $host[0]; + } elseif ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_HOST)) { + $host = $host[0]; + } elseif (!$host = $this->headers->get('HOST')) { + return $this->server->get('SERVER_PORT'); } - if ($host = $this->headers->get('HOST')) { - if ($host[0] === '[') { - $pos = strpos($host, ':', strrpos($host, ']')); - } else { - $pos = strrpos($host, ':'); - } - - if (false !== $pos) { - return (int) substr($host, $pos + 1); - } + if ($host[0] === '[') { + $pos = strpos($host, ':', strrpos($host, ']')); + } else { + $pos = strrpos($host, ':'); + } - return 'https' === $this->getScheme() ? 443 : 80; + if (false !== $pos) { + return (int) substr($host, $pos + 1); } - return $this->server->get('SERVER_PORT'); + return 'https' === $this->getScheme() ? 443 : 80; } /** @@ -1177,8 +1152,8 @@ public function getQueryString() */ public function isSecure() { - if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && $proto = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO])) { - return in_array(strtolower(current(explode(',', $proto))), array('https', 'on', 'ssl', '1')); + if ($this->isFromTrustedProxy() && $proto = $this->getTrustedValues(self::HEADER_CLIENT_PROTO)) { + return in_array(strtolower($proto[0]), array('https', 'on', 'ssl', '1'), true); } $https = $this->server->get('HTTPS'); @@ -1203,10 +1178,8 @@ public function isSecure() */ public function getHost() { - if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_HOST] && $host = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_HOST])) { - $elements = explode(',', $host); - - $host = $elements[count($elements) - 1]; + if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_HOST)) { + $host = $host[0]; } elseif (!$host = $this->headers->get('HOST')) { if (!$host = $this->server->get('SERVER_NAME')) { $host = $this->server->get('SERVER_ADDR', ''); @@ -1801,6 +1774,9 @@ protected function prepareBaseUrl() // Does the baseUrl have anything in common with the request_uri? $requestUri = $this->getRequestUri(); + if ($requestUri !== '' && $requestUri[0] !== '/') { + $requestUri = '/'.$requestUri; + } if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) { // full $baseUrl matches @@ -1873,9 +1849,12 @@ protected function preparePathInfo() } // Remove the query string from REQUEST_URI - if ($pos = strpos($requestUri, '?')) { + if (false !== $pos = strpos($requestUri, '?')) { $requestUri = substr($requestUri, 0, $pos); } + if ($requestUri !== '' && $requestUri[0] !== '/') { + $requestUri = '/'.$requestUri; + } $pathInfo = substr($requestUri, strlen($baseUrl)); if (null !== $baseUrl && (false === $pathInfo || '' === $pathInfo)) { @@ -1977,8 +1956,48 @@ public function isFromTrustedProxy() return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies); } + private function getTrustedValues($type, $ip = null) + { + $clientValues = array(); + $forwardedValues = array(); + + if (self::$trustedHeaders[$type] && $this->headers->has(self::$trustedHeaders[$type])) { + foreach (explode(',', $this->headers->get(self::$trustedHeaders[$type])) as $v) { + $clientValues[] = (self::HEADER_CLIENT_PORT === $type ? '0.0.0.0:' : '').trim($v); + } + } + + if (self::$trustedHeaders[self::HEADER_FORWARDED] && $this->headers->has(self::$trustedHeaders[self::HEADER_FORWARDED])) { + $forwardedValues = $this->headers->get(self::$trustedHeaders[self::HEADER_FORWARDED]); + $forwardedValues = preg_match_all(sprintf('{(?:%s)=(?:"?\[?)([a-zA-Z0-9\.:_\-/]*+)}', self::$forwardedParams[$type]), $forwardedValues, $matches) ? $matches[1] : array(); + } + + if (null !== $ip) { + $clientValues = $this->normalizeAndFilterClientIps($clientValues, $ip); + $forwardedValues = $this->normalizeAndFilterClientIps($forwardedValues, $ip); + } + + if ($forwardedValues === $clientValues || !$clientValues) { + return $forwardedValues; + } + + if (!$forwardedValues) { + return $clientValues; + } + + if (!$this->isForwardedValid) { + return null !== $ip ? array('0.0.0.0', $ip) : array(); + } + $this->isForwardedValid = false; + + throw new ConflictingHeadersException(sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::$trustedHeaders[self::HEADER_FORWARDED], self::$trustedHeaders[$type])); + } + private function normalizeAndFilterClientIps(array $clientIps, $ip) { + if (!$clientIps) { + return array(); + } $clientIps[] = $ip; // Complete the IP chain with the IP the request actually came from $firstTrustedIp = null; diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index d1dd193f6eae3..c5317b1cc5546 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -242,6 +242,11 @@ public function __construct($content = '', $status = 200, $headers = array()) @trigger_error(sprintf('Extending %s::%s() in %s is deprecated since version 3.2 and won\'t be supported anymore in 4.0 as it will be final.', __CLASS__, $method, $class), E_USER_DEPRECATED); } } + + /* RFC2616 - 14.18 says all Responses need to have a Date */ + if (!$this->headers->has('Date')) { + $this->setDate(new \DateTime(null, new \DateTimeZone('UTC'))); + } } /** @@ -370,6 +375,7 @@ public function sendHeaders() return $this; } + /* RFC2616 - 14.18 says all Responses need to have a Date */ if (!$this->headers->has('Date')) { $this->setDate(\DateTime::createFromFormat('U', time())); } @@ -657,6 +663,11 @@ public function mustRevalidate() */ public function getDate() { + /* + RFC2616 - 14.18 says all Responses need to have a Date. + Make sure we provide one even if it the header + has been removed in the meantime. + */ if (!$this->headers->has('Date')) { $this->setDate(\DateTime::createFromFormat('U', time())); } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php index c26cc1334d6aa..348fd23018a03 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php @@ -58,9 +58,9 @@ class MockArraySessionStorage implements SessionStorageInterface protected $metadataBag; /** - * @var array + * @var array|SessionBagInterface[] */ - protected $bags; + protected $bags = array(); /** * Constructor. diff --git a/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php index 61aa74861ddee..297ee3d8d3542 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php @@ -17,14 +17,14 @@ class IpUtilsTest extends TestCase { /** - * @dataProvider testIpv4Provider + * @dataProvider getIpv4Data */ public function testIpv4($matches, $remoteAddr, $cidr) { $this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr)); } - public function testIpv4Provider() + public function getIpv4Data() { return array( array(true, '192.168.1.1', '192.168.1.1'), @@ -43,7 +43,7 @@ public function testIpv4Provider() } /** - * @dataProvider testIpv6Provider + * @dataProvider getIpv6Data */ public function testIpv6($matches, $remoteAddr, $cidr) { @@ -54,7 +54,7 @@ public function testIpv6($matches, $remoteAddr, $cidr) $this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr)); } - public function testIpv6Provider() + public function getIpv6Data() { return array( array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'), diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php index 6f864d4468fe7..b5d80048ff11e 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php @@ -18,7 +18,7 @@ class RequestMatcherTest extends TestCase { /** - * @dataProvider testMethodFixtures + * @dataProvider getMethodData */ public function testMethod($requestMethod, $matcherMethod, $isMatch) { @@ -32,7 +32,7 @@ public function testMethod($requestMethod, $matcherMethod, $isMatch) $this->assertSame($isMatch, $matcher->matches($request)); } - public function testMethodFixtures() + public function getMethodData() { return array( array('get', 'get', true), @@ -64,7 +64,7 @@ public function testScheme() } /** - * @dataProvider testHostFixture + * @dataProvider getHostData */ public function testHost($pattern, $isMatch) { @@ -78,7 +78,7 @@ public function testHost($pattern, $isMatch) $this->assertSame($isMatch, $matcher->matches($request)); } - public function testHostFixture() + public function getHostData() { return array( array('.*\.example\.com', true), diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index a6efcaff44e4d..77b08c53af721 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -306,6 +306,10 @@ public function testGetFormatFromMimeType($format, $mimeTypes) $request->setFormat($format, $mimeTypes); foreach ($mimeTypes as $mime) { $this->assertEquals($format, $request->getFormat($mime)); + + if (null !== $format) { + $this->assertEquals($mimeTypes[0], $request->getMimeType($format)); + } } } @@ -838,7 +842,7 @@ public function testGetSetMethod() } /** - * @dataProvider testGetClientIpsProvider + * @dataProvider getClientIpsProvider */ public function testGetClientIp($expected, $remoteAddr, $httpForwardedFor, $trustedProxies) { @@ -850,7 +854,7 @@ public function testGetClientIp($expected, $remoteAddr, $httpForwardedFor, $trus } /** - * @dataProvider testGetClientIpsProvider + * @dataProvider getClientIpsProvider */ public function testGetClientIps($expected, $remoteAddr, $httpForwardedFor, $trustedProxies) { @@ -862,7 +866,7 @@ public function testGetClientIps($expected, $remoteAddr, $httpForwardedFor, $tru } /** - * @dataProvider testGetClientIpsForwardedProvider + * @dataProvider getClientIpsForwardedProvider */ public function testGetClientIpsForwarded($expected, $remoteAddr, $httpForwarded, $trustedProxies) { @@ -873,7 +877,7 @@ public function testGetClientIpsForwarded($expected, $remoteAddr, $httpForwarded Request::setTrustedProxies(array()); } - public function testGetClientIpsForwardedProvider() + public function getClientIpsForwardedProvider() { // $expected $remoteAddr $httpForwarded $trustedProxies return array( @@ -886,7 +890,7 @@ public function testGetClientIpsForwardedProvider() ); } - public function testGetClientIpsProvider() + public function getClientIpsProvider() { // $expected $remoteAddr $httpForwardedFor $trustedProxies return array( @@ -943,7 +947,7 @@ public function testGetClientIpsProvider() /** * @expectedException \Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException - * @dataProvider testGetClientIpsWithConflictingHeadersProvider + * @dataProvider getClientIpsWithConflictingHeadersProvider */ public function testGetClientIpsWithConflictingHeaders($httpForwarded, $httpXForwardedFor) { @@ -962,7 +966,7 @@ public function testGetClientIpsWithConflictingHeaders($httpForwarded, $httpXFor $request->getClientIps(); } - public function testGetClientIpsWithConflictingHeadersProvider() + public function getClientIpsWithConflictingHeadersProvider() { // $httpForwarded $httpXForwardedFor return array( @@ -975,9 +979,9 @@ public function testGetClientIpsWithConflictingHeadersProvider() } /** - * @dataProvider testGetClientIpsWithAgreeingHeadersProvider + * @dataProvider getClientIpsWithAgreeingHeadersProvider */ - public function testGetClientIpsWithAgreeingHeaders($httpForwarded, $httpXForwardedFor) + public function testGetClientIpsWithAgreeingHeaders($httpForwarded, $httpXForwardedFor, $expectedIps) { $request = new Request(); @@ -991,21 +995,23 @@ public function testGetClientIpsWithAgreeingHeaders($httpForwarded, $httpXForwar $request->initialize(array(), array(), array(), array(), array(), $server); - $request->getClientIps(); + $clientIps = $request->getClientIps(); Request::setTrustedProxies(array()); + + $this->assertSame($expectedIps, $clientIps); } - public function testGetClientIpsWithAgreeingHeadersProvider() + public function getClientIpsWithAgreeingHeadersProvider() { // $httpForwarded $httpXForwardedFor return array( - array('for="192.0.2.60"', '192.0.2.60'), - array('for=192.0.2.60, for=87.65.43.21', '192.0.2.60,87.65.43.21'), - array('for="[::face]", for=192.0.2.60', '::face,192.0.2.60'), - array('for="192.0.2.60:80"', '192.0.2.60'), - array('for=192.0.2.60;proto=http;by=203.0.113.43', '192.0.2.60'), - array('for="[2001:db8:cafe::17]:4711"', '2001:db8:cafe::17'), + array('for="192.0.2.60"', '192.0.2.60', array('192.0.2.60')), + array('for=192.0.2.60, for=87.65.43.21', '192.0.2.60,87.65.43.21', array('87.65.43.21', '192.0.2.60')), + array('for="[::face]", for=192.0.2.60', '::face,192.0.2.60', array('192.0.2.60', '::face')), + array('for="192.0.2.60:80"', '192.0.2.60', array('192.0.2.60')), + array('for=192.0.2.60;proto=http;by=203.0.113.43', '192.0.2.60', array('192.0.2.60')), + array('for="[2001:db8:cafe::17]:4711"', '2001:db8:cafe::17', array('2001:db8:cafe::17')), ); } @@ -1281,6 +1287,12 @@ public function testGetPathInfo() $request->initialize(array(), array(), array(), array(), array(), $server); $this->assertEquals('/path%20test/info', $request->getPathInfo()); + + $server = array(); + $server['REQUEST_URI'] = '?a=b'; + $request->initialize(array(), array(), array(), array(), array(), $server); + + $this->assertEquals('/', $request->getPathInfo()); } public function testGetParameterPrecedence() @@ -1670,12 +1682,12 @@ private function getRequestInstanceForClientIpsForwardedTests($remoteAddr, $http return $request; } - public function testTrustedProxies() + public function testTrustedProxiesXForwardedFor() { $request = Request::create('http://example.com/'); $request->server->set('REMOTE_ADDR', '3.3.3.3'); $request->headers->set('X_FORWARDED_FOR', '1.1.1.1, 2.2.2.2'); - $request->headers->set('X_FORWARDED_HOST', 'foo.example.com, real.example.com:8080'); + $request->headers->set('X_FORWARDED_HOST', 'foo.example.com:1234, real.example.com:8080'); $request->headers->set('X_FORWARDED_PROTO', 'https'); $request->headers->set('X_FORWARDED_PORT', 443); $request->headers->set('X_MY_FOR', '3.3.3.3, 4.4.4.4'); @@ -1706,7 +1718,7 @@ public function testTrustedProxies() // trusted proxy via setTrustedProxies() Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2')); $this->assertEquals('1.1.1.1', $request->getClientIp()); - $this->assertEquals('real.example.com', $request->getHost()); + $this->assertEquals('foo.example.com', $request->getHost()); $this->assertEquals(443, $request->getPort()); $this->assertTrue($request->isSecure()); @@ -1753,6 +1765,55 @@ public function testTrustedProxies() Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_FORWARDED_PROTO'); } + public function testTrustedProxiesForwarded() + { + $request = Request::create('http://example.com/'); + $request->server->set('REMOTE_ADDR', '3.3.3.3'); + $request->headers->set('FORWARDED', 'for=1.1.1.1, host=foo.example.com:8080, proto=https, for=2.2.2.2, host=real.example.com:8080'); + + // no trusted proxies + $this->assertEquals('3.3.3.3', $request->getClientIp()); + $this->assertEquals('example.com', $request->getHost()); + $this->assertEquals(80, $request->getPort()); + $this->assertFalse($request->isSecure()); + + // disabling proxy trusting + Request::setTrustedProxies(array()); + $this->assertEquals('3.3.3.3', $request->getClientIp()); + $this->assertEquals('example.com', $request->getHost()); + $this->assertEquals(80, $request->getPort()); + $this->assertFalse($request->isSecure()); + + // request is forwarded by a non-trusted proxy + Request::setTrustedProxies(array('2.2.2.2')); + $this->assertEquals('3.3.3.3', $request->getClientIp()); + $this->assertEquals('example.com', $request->getHost()); + $this->assertEquals(80, $request->getPort()); + $this->assertFalse($request->isSecure()); + + // trusted proxy via setTrustedProxies() + Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2')); + $this->assertEquals('1.1.1.1', $request->getClientIp()); + $this->assertEquals('foo.example.com', $request->getHost()); + $this->assertEquals(8080, $request->getPort()); + $this->assertTrue($request->isSecure()); + + // trusted proxy via setTrustedProxies() + Request::setTrustedProxies(array('3.3.3.4', '2.2.2.2')); + $this->assertEquals('3.3.3.3', $request->getClientIp()); + $this->assertEquals('example.com', $request->getHost()); + $this->assertEquals(80, $request->getPort()); + $this->assertFalse($request->isSecure()); + + // check various X_FORWARDED_PROTO header values + Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2')); + $request->headers->set('FORWARDED', 'proto=ssl'); + $this->assertTrue($request->isSecure()); + + $request->headers->set('FORWARDED', 'proto=https, proto=http'); + $this->assertTrue($request->isSecure()); + } + /** * @expectedException \InvalidArgumentException */ @@ -2061,6 +2122,61 @@ public function methodCacheableProvider() array('CONNECT', false), ); } + + public function nonstandardRequestsData() + { + return array( + array('', '', '/', 'http://host:8080/', ''), + array('/', '', '/', 'http://host:8080/', ''), + + array('hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'), + array('/hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'), + + array('', 'a=b', '/', 'http://host:8080/?a=b'), + array('?a=b', 'a=b', '/', 'http://host:8080/?a=b'), + array('/?a=b', 'a=b', '/', 'http://host:8080/?a=b'), + + array('x', 'a=b', '/x', 'http://host:8080/x?a=b'), + array('x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'), + array('/x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'), + + array('hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'), + array('/hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'), + + array('hello/app.php/x', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'), + array('hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'), + array('/hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'), + ); + } + + /** + * @dataProvider nonstandardRequestsData + */ + public function testNonstandardRequests($requestUri, $queryString, $expectedPathInfo, $expectedUri, $expectedBasePath = '', $expectedBaseUrl = null) + { + if (null === $expectedBaseUrl) { + $expectedBaseUrl = $expectedBasePath; + } + + $server = array( + 'HTTP_HOST' => 'host:8080', + 'SERVER_PORT' => '8080', + 'QUERY_STRING' => $queryString, + 'PHP_SELF' => '/hello/app.php', + 'SCRIPT_FILENAME' => '/some/path/app.php', + 'REQUEST_URI' => $requestUri, + ); + + $request = new Request(array(), array(), array(), array(), array(), $server); + + $this->assertEquals($expectedPathInfo, $request->getPathInfo()); + $this->assertEquals($expectedUri, $request->getUri()); + $this->assertEquals($queryString, $request->getQueryString()); + $this->assertEquals(8080, $request->getPort()); + $this->assertEquals('host:8080', $request->getHttpHost()); + $this->assertEquals($expectedBaseUrl, $request->getBaseUrl()); + $this->assertEquals($expectedBasePath, $request->getBasePath()); + } } class RequestContentProxy extends Request diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php index 1a832a1dcba10..961b0bfb4bb25 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php @@ -276,8 +276,10 @@ public function testGetDate() $this->assertEquals($now->getTimestamp(), $date->getTimestamp(), '->getDate() returns the date when the header has been modified'); $response = new Response('', 200); + $now = $this->createDateTimeNow(); $response->headers->remove('Date'); - $this->assertInstanceOf('\DateTime', $response->getDate()); + $date = $response->getDate(); + $this->assertEquals($now->getTimestamp(), $date->getTimestamp(), '->getDate() returns the current Date when the header has previously been removed'); } public function testGetMaxAge() diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php index 4d5d337a3c011..fa93507a41aaf 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php @@ -177,6 +177,8 @@ public function testSave() { $this->session->start(); $this->session->save(); + + $this->assertFalse($this->session->isStarted()); } public function testGetId() diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php index 1f55a2d5c440d..159e62114e1a3 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MetadataBagTest.php @@ -103,6 +103,9 @@ public function testGetLastUsed() public function testClear() { $this->bag->clear(); + + // the clear method has no side effects, we just want to ensure it doesn't trigger any exceptions + $this->addToAssertionCount(1); } public function testSkipLastUsedUpdate() diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php index 99da778b5fd87..82df5543eb540 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/MockArraySessionStorageTest.php @@ -97,6 +97,30 @@ public function testGetId() $this->assertNotEquals('', $this->storage->getId()); } + public function testClearClearsBags() + { + $this->storage->clear(); + + $this->assertSame(array(), $this->storage->getBag('attributes')->all()); + $this->assertSame(array(), $this->storage->getBag('flashes')->peekAll()); + } + + public function testClearStartsSession() + { + $this->storage->clear(); + + $this->assertTrue($this->storage->isStarted()); + } + + public function testClearWithNoBagsStartsSession() + { + $storage = new MockArraySessionStorage(); + + $storage->clear(); + + $this->assertTrue($storage->isStarted()); + } + /** * @expectedException \RuntimeException */ diff --git a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php index f7a99a331e617..1e35eb88b91fa 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php @@ -51,10 +51,12 @@ public function testPrepareWith10Protocol() public function testPrepareWithHeadRequest() { - $response = new StreamedResponse(function () { echo 'foo'; }); + $response = new StreamedResponse(function () { echo 'foo'; }, 200, array('Content-Length' => '123')); $request = Request::create('/', 'HEAD'); $response->prepare($request); + + $this->assertSame('123', $response->headers->get('Content-Length')); } public function testPrepareWithCacheHeaders() diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index 686f0b852c202..297e98a240ac8 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -464,7 +464,7 @@ protected function forward(Request $request, $catch = false, Response $entry = n // make sure HttpCache is a trusted proxy if (!in_array('127.0.0.1', $trustedProxies = Request::getTrustedProxies())) { $trustedProxies[] = '127.0.0.1'; - Request::setTrustedProxies($trustedProxies); + Request::setTrustedProxies($trustedProxies, method_exists('Request', 'getTrustedHeaderSet') ? Request::getTrustedHeaderSet() : -1); } // always a "master" request (as the real master request can be in cache) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Store.php b/src/Symfony/Component/HttpKernel/HttpCache/Store.php index f5574614b839a..c4d961e68f043 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Store.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Store.php @@ -325,10 +325,13 @@ private function getMetadata($key) */ public function purge($url) { - $http = preg_replace('#^https#', 'http', $url); - $https = preg_replace('#^http#', 'https', $url); + $http = preg_replace('#^https:#', 'http:', $url); + $https = preg_replace('#^http:#', 'https:', $url); - return $this->doPurge($http) || $this->doPurge($https); + $purgedHttp = $this->doPurge($http); + $purgedHttps = $this->doPurge($https); + + return $purgedHttp || $purgedHttps; } /** diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index f02c9a9cbde67..3bff41d941456 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -58,11 +58,11 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $startTime; protected $loadClassCache; - const VERSION = '3.2.6'; - const VERSION_ID = 30206; + const VERSION = '3.2.7'; + const VERSION_ID = 30207; const MAJOR_VERSION = 3; const MINOR_VERSION = 2; - const RELEASE_VERSION = 6; + const RELEASE_VERSION = 7; const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '07/2017'; diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/ValidateRequestListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/ValidateRequestListenerTest.php index 8311a76e35a03..d6ac73855763f 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/ValidateRequestListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/ValidateRequestListenerTest.php @@ -30,9 +30,9 @@ public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps() $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); $request = new Request(); - $request->setTrustedProxies(array('1.1.1.1')); + $request->setTrustedProxies(array('1.1.1.1'), -1); $request->server->set('REMOTE_ADDR', '1.1.1.1'); - $request->headers->set('FORWARDED', '2.2.2.2'); + $request->headers->set('FORWARDED', 'for=2.2.2.2'); $request->headers->set('X_FORWARDED_FOR', '3.3.3.3'); $dispatcher->addListener(KernelEvents::REQUEST, array(new ValidateRequestListener(), 'onKernelRequest')); diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php index 4864cfb74899f..4a665adadc60d 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php @@ -25,6 +25,18 @@ class InlineFragmentRendererTest extends TestCase { + private $originalTrustedHeaderName; + + protected function setUp() + { + $this->originalTrustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP); + } + + protected function tearDown() + { + Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $this->originalTrustedHeaderName); + } + public function testRender() { $strategy = new InlineFragmentRenderer($this->getKernel($this->returnValue(new Response('foo')))); @@ -50,7 +62,7 @@ public function testRenderWithObjectsAsAttributes() $strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($subRequest)); - $strategy->render(new ControllerReference('main_controller', array('object' => $object), array()), Request::create('/')); + $this->assertSame('foo', $strategy->render(new ControllerReference('main_controller', array('object' => $object), array()), Request::create('/'))->getContent()); } /** @@ -97,14 +109,10 @@ public function testRenderWithObjectsAsAttributesPassedAsObjectsInTheController( public function testRenderWithTrustedHeaderDisabled() { - $trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP); - Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, ''); $strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest(Request::create('/'))); - $strategy->render('/', Request::create('/')); - - Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $trustedHeaderName); + $this->assertSame('foo', $strategy->render('/', Request::create('/'))->getContent()); } /** @@ -152,22 +160,6 @@ private function getKernel($returnValue) return $kernel; } - /** - * Creates a Kernel expecting a request equals to $request - * Allows delta in comparison in case REQUEST_TIME changed by 1 second. - */ - private function getKernelExpectingRequest(Request $request) - { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); - $kernel - ->expects($this->any()) - ->method('handle') - ->with($this->equalTo($request, 1)) - ; - - return $kernel; - } - public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() { $controllerResolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock(); @@ -240,6 +232,22 @@ public function testHeadersPossiblyResultingIn304AreNotAssignedToSubrequest() $request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_IF_MODIFIED_SINCE' => 'Fri, 01 Jan 2016 00:00:00 GMT', 'HTTP_IF_NONE_MATCH' => '*')); $strategy->render('/', $request); } + + /** + * Creates a Kernel expecting a request equals to $request + * Allows delta in comparison in case REQUEST_TIME changed by 1 second. + */ + private function getKernelExpectingRequest(Request $request, $strict = false) + { + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel + ->expects($this->once()) + ->method('handle') + ->with($this->equalTo($request, 1)) + ->willReturn(new Response('foo')); + + return $kernel; + } } class Bar diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php index d5cf8ca7ae70d..5e03bc7a2a878 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php @@ -849,6 +849,40 @@ public function testValidatesCachedResponsesWithETagAndNoFreshnessInformation() $this->assertTraceNotContains('miss'); } + public function testServesResponseWhileFreshAndRevalidatesWithLastModifiedInformation() + { + $time = \DateTime::createFromFormat('U', time()); + + $this->setNextResponse(200, array(), 'Hello World', function (Request $request, Response $response) use ($time) { + $response->setSharedMaxAge(10); + $response->headers->set('Last-Modified', $time->format(DATE_RFC2822)); + }); + + // prime the cache + $this->request('GET', '/'); + + // next request before s-maxage has expired: Serve from cache + // without hitting the backend + $this->request('GET', '/'); + $this->assertHttpKernelIsNotCalled(); + $this->assertEquals(200, $this->response->getStatusCode()); + $this->assertEquals('Hello World', $this->response->getContent()); + $this->assertTraceContains('fresh'); + + sleep(15); // expire the cache + + $this->setNextResponse(304, array(), '', function (Request $request, Response $response) use ($time) { + $this->assertEquals($time->format(DATE_RFC2822), $request->headers->get('IF_MODIFIED_SINCE')); + }); + + $this->request('GET', '/'); + $this->assertHttpKernelIsCalled(); + $this->assertEquals(200, $this->response->getStatusCode()); + $this->assertEquals('Hello World', $this->response->getContent()); + $this->assertTraceContains('stale'); + $this->assertTraceContains('valid'); + } + public function testReplacesCachedResponsesWhenValidationResultsInNon304Response() { $time = \DateTime::createFromFormat('U', time()); @@ -1184,7 +1218,7 @@ public function testClientIpIsAlwaysLocalhostForForwardedRequests() */ public function testHttpCacheIsSetAsATrustedProxy(array $existing, array $expected) { - Request::setTrustedProxies($existing); + Request::setTrustedProxies($existing, -1); $this->setNextResponse(); $this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1')); diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/StoreTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/StoreTest.php index 8b9e52b03ea9a..cef019167a4ef 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/StoreTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/StoreTest.php @@ -236,6 +236,33 @@ public function testLocking() $this->assertFalse($this->store->isLocked($req)); } + public function testPurgeHttps() + { + $request = Request::create('https://example.com/foo'); + $this->store->write($request, new Response('foo')); + + $this->assertNotEmpty($this->getStoreMetadata($request)); + + $this->assertTrue($this->store->purge('https://example.com/foo')); + $this->assertEmpty($this->getStoreMetadata($request)); + } + + public function testPurgeHttpAndHttps() + { + $requestHttp = Request::create('https://example.com/foo'); + $this->store->write($requestHttp, new Response('foo')); + + $requestHttps = Request::create('http://example.com/foo'); + $this->store->write($requestHttps, new Response('foo')); + + $this->assertNotEmpty($this->getStoreMetadata($requestHttp)); + $this->assertNotEmpty($this->getStoreMetadata($requestHttps)); + + $this->assertTrue($this->store->purge('http://example.com/foo')); + $this->assertEmpty($this->getStoreMetadata($requestHttp)); + $this->assertEmpty($this->getStoreMetadata($requestHttps)); + } + protected function storeSimpleEntry($path = null, $headers = array()) { if (null === $path) { diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index b58a251a5938d..74a808c15e897 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -309,9 +309,9 @@ public function testVerifyRequestStackPushPopDuringHandle() public function testInconsistentClientIpsOnMasterRequests() { $request = new Request(); - $request->setTrustedProxies(array('1.1.1.1')); + $request->setTrustedProxies(array('1.1.1.1'), -1); $request->server->set('REMOTE_ADDR', '1.1.1.1'); - $request->headers->set('FORWARDED', '2.2.2.2'); + $request->headers->set('FORWARDED', 'for=2.2.2.2'); $request->headers->set('X_FORWARDED_FOR', '3.3.3.3'); $dispatcher = new EventDispatcher(); diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php index da223bd205fa6..d09dece33cc8b 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php @@ -1102,7 +1102,7 @@ public function testFailIfCyclicDependencyBetweenNormalizerAndLazyOption() $this->resolver->resolve(); } - public function testCatchedExceptionFromNormalizerDoesNotCrashOptionResolver() + public function testCaughtExceptionFromNormalizerDoesNotCrashOptionResolver() { $throw = true; @@ -1116,7 +1116,7 @@ public function testCatchedExceptionFromNormalizerDoesNotCrashOptionResolver() } }); - $this->resolver->setNormalizer('thrower', function (Options $options) use (&$throw) { + $this->resolver->setNormalizer('thrower', function () use (&$throw) { if ($throw) { $throw = false; throw new \UnexpectedValueException('throwing'); @@ -1125,10 +1125,10 @@ public function testCatchedExceptionFromNormalizerDoesNotCrashOptionResolver() return true; }); - $this->resolver->resolve(); + $this->assertSame(array('catcher' => false, 'thrower' => true), $this->resolver->resolve()); } - public function testCatchedExceptionFromLazyDoesNotCrashOptionResolver() + public function testCaughtExceptionFromLazyDoesNotCrashOptionResolver() { $throw = true; @@ -1149,7 +1149,7 @@ public function testCatchedExceptionFromLazyDoesNotCrashOptionResolver() return true; }); - $this->resolver->resolve(); + $this->assertSame(array('catcher' => false, 'thrower' => true), $this->resolver->resolve()); } public function testInvokeEachNormalizerOnlyOnce() diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 504b4c3bc567d..bd00e1761c574 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -277,7 +277,7 @@ public function start(callable $callback = null) } foreach ($env as $k => $v) { - $envBackup[$k] = getenv($v); + $envBackup[$k] = getenv($k); putenv(false === $v || null === $v ? $k : "$k=$v"); } $env = null; diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index c51a116e7319f..379dae2df717a 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -1403,6 +1403,20 @@ public function testSetBadEnv() $this->assertSame('', $process->getErrorOutput()); } + public function testEnvBackupDoesNotDeleteExistingVars() + { + putenv('existing_var=foo'); + $process = $this->getProcess('php -r "echo getenv(\'new_test_var\');"'); + $process->setEnv(array('existing_var' => 'bar', 'new_test_var' => 'foo')); + $process->inheritEnvironmentVariables(); + + $process->run(); + + $this->assertSame('foo', $process->getOutput()); + $this->assertSame('foo', getenv('existing_var')); + $this->assertFalse(getenv('new_test_var')); + } + public function testInheritEnvEnabled() { $process = $this->getProcess(self::$phpBin.' -r '.escapeshellarg('echo serialize($_SERVER);'), null, array('BAR' => 'BAZ')); diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php index 5e3a06a4b4d85..6c5c6b22a2b06 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php @@ -87,7 +87,9 @@ public function testPathCannotBeFalse() public function testZeroIsValidPropertyPath() { - new PropertyPath('0'); + $propertyPath = new PropertyPath('0'); + + $this->assertSame('0', (string) $propertyPath); } public function testGetParentWithDot() diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php index f7e4aa871e3cf..4e503ce053960 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php @@ -211,7 +211,7 @@ private function getDocBlockFromProperty($class, $property) * @param string $ucFirstProperty * @param int $type * - * @return array + * @return array|null */ private function getDocBlockFromMethod($class, $ucFirstProperty, $type) { diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index 96c2e9b48ef5f..a400606e7fbe6 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -81,7 +81,7 @@ public function getProperties($class, array $context = array()) if (!$propertyName || isset($properties[$propertyName])) { continue; } - if (!preg_match('/^[A-Z]{2,}/', $propertyName)) { + if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) { $propertyName = lcfirst($propertyName); } $properties[$propertyName] = true; diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php index 8aa508e3c2524..d0eb3eed06c49 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php @@ -68,6 +68,7 @@ public function typesProvider() array('d', array(new Type(Type::BUILTIN_TYPE_BOOL)), null, null), array('e', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_RESOURCE))), null, null), array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime'))), null, null), + array('g', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)), 'Nullable array.', null), array('donotexist', null, null, null), array('staticGetter', null, null, null), array('staticSetter', null, null, null), diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php index f8a5e45360166..23de86bdae210 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php @@ -39,6 +39,8 @@ public function testGetProperties() 'parent', 'collection', 'B', + 'Guid', + 'g', 'foo', 'foo2', 'foo3', @@ -47,6 +49,7 @@ public function testGetProperties() 'files', 'a', 'DOB', + 'Id', 'c', 'd', 'e', @@ -129,6 +132,10 @@ public function testIsReadable() $this->assertTrue($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'd', array())); $this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'e', array())); $this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'f', array())); + $this->assertTrue($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'Id', array())); + $this->assertTrue($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'id', array())); + $this->assertTrue($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'Guid', array())); + $this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'guid', array())); } public function testIsWritable() @@ -142,6 +149,9 @@ public function testIsWritable() $this->assertFalse($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'd', array())); $this->assertTrue($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'e', array())); $this->assertTrue($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'f', array())); + $this->assertFalse($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'Id', array())); + $this->assertTrue($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'Guid', array())); + $this->assertFalse($this->extractor->isWritable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'guid', array())); } public function testSingularize() diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php index 96cb87db4a8fa..2f6fc11b0de5a 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php @@ -51,6 +51,23 @@ class Dummy extends ParentDummy */ public $B; + /** + * @var int + */ + protected $Id; + + /** + * @var string + */ + public $Guid; + + /** + * Nullable array. + * + * @var array|null + */ + public $g; + public static function getStatic() { } @@ -92,4 +109,11 @@ public function setB(ParentDummy $parent = null) public function getDOB() { } + + /** + * @return int + */ + public function getId() + { + } } diff --git a/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php b/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php index b374a5dcba7eb..bc14cd8b69b1b 100644 --- a/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php +++ b/src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php @@ -101,10 +101,10 @@ private function createType($docType, $nullable) $collectionValueType = null; } else { $collectionKeyType = new Type(Type::BUILTIN_TYPE_INT); - $collectionValueType = new Type($phpType, false, $class); + $collectionValueType = new Type($phpType, $nullable, $class); } - return new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, $collectionKeyType, $collectionValueType); + return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, $collectionKeyType, $collectionValueType); } return new Type($phpType, $nullable, $class); diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php index 2e9c0f34b4b5d..0eee6d94a41c6 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php @@ -150,7 +150,7 @@ public function serialize() array( is_object($this->user) ? clone $this->user : $this->user, $this->authenticated, - $this->roles, + array_map(function ($role) { return clone $role; }, $this->roles), $this->attributes, ) ); diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php index 50990b7e465fd..da6136f22151f 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php @@ -221,7 +221,7 @@ public function testAuthenticateWithPreservingRoleSwitchUserRole() $this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $authToken); $this->assertSame($user, $authToken->getUser()); $this->assertContains(new Role('ROLE_FOO'), $authToken->getRoles(), '', false, false); - $this->assertContains($switchUserRole, $authToken->getRoles()); + $this->assertContains($switchUserRole, $authToken->getRoles(), '', false, false); $this->assertEquals('foo', $authToken->getCredentials()); $this->assertEquals(array('foo' => 'bar'), $authToken->getAttributes(), '->authenticate() copies token attributes'); } diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php index 57ebf184f2df6..4cdf98267600a 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Security\Core\Authentication\Token\AbstractToken; use Symfony\Component\Security\Core\Role\Role; use Symfony\Component\Security\Core\Role\SwitchUserRole; +use Symfony\Component\Security\Core\User\User; class TestUser { @@ -89,7 +90,7 @@ public function testEraseCredentials() public function testSerialize() { - $token = $this->getToken(array('ROLE_FOO')); + $token = $this->getToken(array('ROLE_FOO', new Role('ROLE_BAR'))); $token->setAttributes(array('foo' => 'bar')); $uToken = unserialize(serialize($token)); @@ -98,6 +99,19 @@ public function testSerialize() $this->assertEquals($token->getAttributes(), $uToken->getAttributes()); } + public function testSerializeWithRoleObjects() + { + $user = new User('name', 'password', array(new Role('ROLE_FOO'), new Role('ROLE_BAR'))); + $token = new ConcreteToken($user, $user->getRoles()); + + $serialized = serialize($token); + $unserialized = unserialize($serialized); + + $roles = $unserialized->getRoles(); + + $this->assertEquals($roles, $user->getRoles()); + } + public function testSerializeParent() { $user = new TestUser('fabien'); diff --git a/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php b/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php index 10c8da692a6fd..b6b6ab8c8015d 100644 --- a/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Encoder/BCryptPasswordEncoderTest.php @@ -39,11 +39,20 @@ public function testCostAboveRange() new BCryptPasswordEncoder(32); } - public function testCostInRange() + /** + * @dataProvider validRangeData + */ + public function testCostInRange($cost) + { + $this->assertInstanceOf('Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder', new BCryptPasswordEncoder($cost)); + } + + public function validRangeData() { - for ($cost = 4; $cost <= 31; ++$cost) { - new BCryptPasswordEncoder($cost); - } + $costs = range(4, 31); + array_walk($costs, function (&$cost) { $cost = array($cost); }); + + return $costs; } public function testResultLength() diff --git a/src/Symfony/Component/Security/Core/Tests/Resources/TranslationFilesTest.php b/src/Symfony/Component/Security/Core/Tests/Resources/TranslationFilesTest.php index 6588c32fdfa3c..96a1307ed056b 100644 --- a/src/Symfony/Component/Security/Core/Tests/Resources/TranslationFilesTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Resources/TranslationFilesTest.php @@ -25,6 +25,8 @@ public function testTranslationFileIsValid($filePath) } else { \PHPUnit\Util\XML::loadfile($filePath, false, false, true); } + + $this->addToAssertionCount(1); } public function provideTranslationFiles() diff --git a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php index c22105b97ef8a..a462b5818b571 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php +++ b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php @@ -319,6 +319,6 @@ protected function isRememberMeRequested(Request $request) $this->logger->debug('Did not send remember-me cookie.', array('parameter' => $this->options['remember_me_parameter'])); } - return $parameter === 'true' || $parameter === 'on' || $parameter === '1' || $parameter === 'yes'; + return $parameter === 'true' || $parameter === 'on' || $parameter === '1' || $parameter === 'yes' || $parameter === true; } } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/DigestDataTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/DigestDataTest.php index 2238a74188853..7317e2f83c7cc 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/DigestDataTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/DigestDataTest.php @@ -100,6 +100,9 @@ public function testGetUsernameWithEscape() $this->assertEquals('"u\\ser"', $digestAuth->getUsername()); } + /** + * @group time-sensitive + */ public function testValidateAndDecode() { $time = microtime(true); @@ -112,11 +115,11 @@ public function testValidateAndDecode() 'response="b52938fc9e6d7c01be7702ece9031b42"' ); - try { - $digestAuth->validateAndDecode($key, 'Welcome, robot!'); - } catch (\Exception $e) { - $this->fail(sprintf('testValidateAndDecode fail with message: %s', $e->getMessage())); - } + $digestAuth->validateAndDecode($key, 'Welcome, robot!'); + + sleep(1); + + $this->assertTrue($digestAuth->isNonceExpired()); } public function testCalculateServerDigest() diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php index 2c05ef75cab25..43013520c36ba 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php @@ -12,6 +12,13 @@ namespace Symfony\Component\Security\Http\Tests\Firewall; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Symfony\Component\Security\Core\Role\SwitchUserRole; +use Symfony\Component\Security\Core\User\User; use Symfony\Component\Security\Http\Event\SwitchUserEvent; use Symfony\Component\Security\Http\Firewall\SwitchUserListener; use Symfony\Component\Security\Http\SecurityEvents; @@ -32,14 +39,12 @@ class SwitchUserListenerTest extends TestCase protected function setUp() { - $this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); + $this->tokenStorage = new TokenStorage(); $this->userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock(); $this->userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock(); $this->accessDecisionManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock(); - $this->request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock(); - $this->request->query = $this->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag')->getMock(); - $this->request->server = $this->getMockBuilder('Symfony\Component\HttpFoundation\ServerBag')->getMock(); - $this->event = $this->getEvent($this->request); + $this->request = new Request(); + $this->event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $this->request, HttpKernelInterface::MASTER_REQUEST); } /** @@ -53,13 +58,11 @@ public function testProviderKeyIsRequired() public function testEventIsIgnoredIfUsernameIsNotPassedWithTheRequest() { - $this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue(null)); - - $this->event->expects($this->never())->method('setResponse'); - $this->tokenStorage->expects($this->never())->method('setToken'); - $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); $listener->handle($this->event); + + $this->assertNull($this->event->getResponse()); + $this->assertNull($this->tokenStorage->getToken()); } /** @@ -67,10 +70,10 @@ public function testEventIsIgnoredIfUsernameIsNotPassedWithTheRequest() */ public function testExitUserThrowsAuthenticationExceptionIfOriginalTokenCannotBeFound() { - $token = $this->getToken(array($this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleInterface')->getMock())); + $token = new UsernamePasswordToken('username', '', 'key', array('ROLE_FOO')); - $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token)); - $this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('_exit')); + $this->tokenStorage->setToken($token); + $this->request->query->set('_switch_user', '_exit'); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); $listener->handle($this->event); @@ -78,29 +81,19 @@ public function testExitUserThrowsAuthenticationExceptionIfOriginalTokenCannotBe public function testExitUserUpdatesToken() { - $originalToken = $this->getToken(); - $role = $this->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole') - ->disableOriginalConstructor() - ->getMock(); - $role->expects($this->any())->method('getSource')->will($this->returnValue($originalToken)); - - $this->tokenStorage->expects($this->any()) - ->method('getToken') - ->will($this->returnValue($this->getToken(array($role)))); - - $this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('_exit')); - $this->request->expects($this->any())->method('getUri')->will($this->returnValue('/')); - $this->request->query->expects($this->once())->method('remove', '_switch_user'); - $this->request->query->expects($this->any())->method('all')->will($this->returnValue(array())); - $this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', ''); - - $this->tokenStorage->expects($this->once()) - ->method('setToken')->with($originalToken); - $this->event->expects($this->once()) - ->method('setResponse')->with($this->isInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse')); + $originalToken = new UsernamePasswordToken('username', '', 'key', array()); + $this->tokenStorage->setToken(new UsernamePasswordToken('username', '', 'key', array(new SwitchUserRole('ROLE_PREVIOUS', $originalToken)))); + + $this->request->query->set('_switch_user', '_exit'); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); $listener->handle($this->event); + + $this->assertSame(array(), $this->request->query->all()); + $this->assertSame('', $this->request->server->get('QUERY_STRING')); + $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $this->event->getResponse()); + $this->assertSame($this->request->getUri(), $this->event->getResponse()->getTargetUrl()); + $this->assertSame($originalToken, $this->tokenStorage->getToken()); } public function testExitUserDispatchesEventWithRefreshedUser() @@ -113,38 +106,9 @@ public function testExitUserDispatchesEventWithRefreshedUser() ->method('refreshUser') ->with($originalUser) ->willReturn($refreshedUser); - $originalToken = $this->getToken(); - $originalToken - ->expects($this->any()) - ->method('getUser') - ->willReturn($originalUser); - $role = $this - ->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole') - ->disableOriginalConstructor() - ->getMock(); - $role->expects($this->any())->method('getSource')->willReturn($originalToken); - $this - ->tokenStorage - ->expects($this->any()) - ->method('getToken') - ->willReturn($this->getToken(array($role))); - $this - ->request - ->expects($this->any()) - ->method('get') - ->with('_switch_user') - ->willReturn('_exit'); - $this - ->request - ->expects($this->any()) - ->method('getUri') - ->willReturn('/'); - $this - ->request - ->query - ->expects($this->any()) - ->method('all') - ->will($this->returnValue(array())); + $originalToken = new UsernamePasswordToken($originalUser, '', 'key'); + $this->tokenStorage->setToken(new UsernamePasswordToken('username', '', 'key', array(new SwitchUserRole('ROLE_PREVIOUS', $originalToken)))); + $this->request->query->set('_switch_user', '_exit'); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); $dispatcher @@ -166,41 +130,9 @@ public function testExitUserDoesNotDispatchEventWithStringUser() ->userProvider ->expects($this->never()) ->method('refreshUser'); - $originalToken = $this->getToken(); - $originalToken - ->expects($this->any()) - ->method('getUser') - ->willReturn($originalUser); - $role = $this - ->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole') - ->disableOriginalConstructor() - ->getMock(); - $role - ->expects($this->any()) - ->method('getSource') - ->willReturn($originalToken); - $this - ->tokenStorage - ->expects($this->any()) - ->method('getToken') - ->willReturn($this->getToken(array($role))); - $this - ->request - ->expects($this->any()) - ->method('get') - ->with('_switch_user') - ->willReturn('_exit'); - $this - ->request - ->query - ->expects($this->any()) - ->method('all') - ->will($this->returnValue(array())); - $this - ->request - ->expects($this->any()) - ->method('getUri') - ->willReturn('/'); + $originalToken = new UsernamePasswordToken($originalUser, '', 'key'); + $this->tokenStorage->setToken(new UsernamePasswordToken('username', '', 'key', array(new SwitchUserRole('ROLE_PREVIOUS', $originalToken)))); + $this->request->query->set('_switch_user', '_exit'); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); $dispatcher @@ -217,10 +149,10 @@ public function testExitUserDoesNotDispatchEventWithStringUser() */ public function testSwitchUserIsDisallowed() { - $token = $this->getToken(array($this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleInterface')->getMock())); + $token = new UsernamePasswordToken('username', '', 'key', array('ROLE_FOO')); - $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token)); - $this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba')); + $this->tokenStorage->setToken($token); + $this->request->query->set('_switch_user', 'kuba'); $this->accessDecisionManager->expects($this->once()) ->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH')) @@ -232,17 +164,11 @@ public function testSwitchUserIsDisallowed() public function testSwitchUser() { - $token = $this->getToken(array($this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleInterface')->getMock())); - $user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(); - $user->expects($this->any())->method('getRoles')->will($this->returnValue(array())); + $token = new UsernamePasswordToken('username', '', 'key', array('ROLE_FOO')); + $user = new User('username', 'password', array()); - $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token)); - $this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba')); - $this->request->query->expects($this->once())->method('remove', '_switch_user'); - $this->request->query->expects($this->any())->method('all')->will($this->returnValue(array())); - - $this->request->expects($this->any())->method('getUri')->will($this->returnValue('/')); - $this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', ''); + $this->tokenStorage->setToken($token); + $this->request->query->set('_switch_user', 'kuba'); $this->accessDecisionManager->expects($this->once()) ->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH')) @@ -253,25 +179,26 @@ public function testSwitchUser() ->will($this->returnValue($user)); $this->userChecker->expects($this->once()) ->method('checkPostAuth')->with($user); - $this->tokenStorage->expects($this->once()) - ->method('setToken')->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken')); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); $listener->handle($this->event); + + $this->assertSame(array(), $this->request->query->all()); + $this->assertSame('', $this->request->server->get('QUERY_STRING')); + $this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken()); } public function testSwitchUserKeepsOtherQueryStringParameters() { - $token = $this->getToken(array($this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleInterface')->getMock())); - $user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(); - $user->expects($this->any())->method('getRoles')->will($this->returnValue(array())); + $token = new UsernamePasswordToken('username', '', 'key', array('ROLE_FOO')); + $user = new User('username', 'password', array()); - $this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token)); - $this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba')); - $this->request->query->expects($this->once())->method('remove', '_switch_user'); - $this->request->query->expects($this->any())->method('all')->will($this->returnValue(array('page' => 3, 'section' => 2))); - $this->request->expects($this->any())->method('getUri')->will($this->returnValue('/')); - $this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', 'page=3§ion=2'); + $this->tokenStorage->setToken($token); + $this->request->query->replace(array( + '_switch_user' => 'kuba', + 'page' => 3, + 'section' => 2, + )); $this->accessDecisionManager->expects($this->once()) ->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH')) @@ -282,33 +209,11 @@ public function testSwitchUserKeepsOtherQueryStringParameters() ->will($this->returnValue($user)); $this->userChecker->expects($this->once()) ->method('checkPostAuth')->with($user); - $this->tokenStorage->expects($this->once()) - ->method('setToken')->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken')); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); $listener->handle($this->event); - } - - private function getEvent($request) - { - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') - ->disableOriginalConstructor() - ->getMock(); - - $event->expects($this->any()) - ->method('getRequest') - ->will($this->returnValue($request)); - - return $event; - } - - private function getToken(array $roles = array()) - { - $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); - $token->expects($this->any()) - ->method('getRoles') - ->will($this->returnValue($roles)); - return $token; + $this->assertSame('page=3§ion=2', $this->request->server->get('QUERY_STRING')); + $this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken()); } } diff --git a/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php b/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php index eb0379f97b4f5..3d0e63b6fe1b9 100644 --- a/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php +++ b/src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php @@ -144,7 +144,7 @@ public function testCheckRequestPath() // Plus must not decoded to space $this->assertTrue($utils->checkRequestPath($this->getRequest('/foo+bar'), '/foo+bar')); // Checking unicode - $this->assertTrue($utils->checkRequestPath($this->getRequest(urlencode('/вход')), '/вход')); + $this->assertTrue($utils->checkRequestPath($this->getRequest('/'.urlencode('вход')), '/вход')); } public function testCheckRequestPathWithUrlMatcherAndResourceNotFound() diff --git a/src/Symfony/Component/Security/Http/Tests/RememberMe/AbstractRememberMeServicesTest.php b/src/Symfony/Component/Security/Http/Tests/RememberMe/AbstractRememberMeServicesTest.php index c480435b02b40..886743c1d3554 100644 --- a/src/Symfony/Component/Security/Http/Tests/RememberMe/AbstractRememberMeServicesTest.php +++ b/src/Symfony/Component/Security/Http/Tests/RememberMe/AbstractRememberMeServicesTest.php @@ -251,6 +251,7 @@ public function getPositiveRememberMeParameterValues() array('1'), array('on'), array('yes'), + array(true), ); } diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 8145b32c52506..7990a49be40aa 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -95,14 +95,16 @@ public function decode($data, $format, array $context = array()) throw new UnexpectedValueException($error->message); } + $rootNode = null; foreach ($dom->childNodes as $child) { if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { throw new UnexpectedValueException('Document types are not allowed.'); } + if (!$rootNode && $child->nodeType !== XML_PI_NODE) { + $rootNode = $child; + } } - $rootNode = $dom->firstChild; - // todo: throw an exception if the root node name is not correctly configured (bc) if ($rootNode->hasChildNodes()) { @@ -332,6 +334,10 @@ private function parseXmlValue(\DOMNode $node) $value = array(); foreach ($node->childNodes as $subnode) { + if ($subnode->nodeType === XML_PI_NODE) { + continue; + } + $val = $this->parseXml($subnode); if ('item' === $subnode->nodeName && isset($val['@key'])) { diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php index 4e83f3464f200..e036fbbaf486b 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php @@ -17,7 +17,6 @@ use Symfony\Component\Serializer\Tests\Fixtures\ScalarDummy; use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Serializer; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\CustomNormalizer; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -371,6 +370,44 @@ public function testDecodeArray() $this->assertEquals($expected, $this->encoder->decode($source, 'xml')); } + public function testDecodeXMLWithProcessInstruction() + { + $source = <<<'XML' + + + + + + foo + + a + b + + val + val + bar + + title1 + + + + title2 + + + + Ed + + + + 1 + + ?> +XML; + $obj = $this->getObject(); + + $this->assertEquals(get_object_vars($obj), $this->encoder->decode($source, 'xml')); + } + public function testDecodeIgnoreWhiteSpace() { $source = <<<'XML' @@ -435,23 +472,12 @@ public function testDecodeInvalidXml() $this->encoder->decode('', 'xml'); } + /** + * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException + */ public function testPreventsComplexExternalEntities() { - $oldCwd = getcwd(); - chdir(__DIR__); - - try { - $this->encoder->decode(']>&test;', 'xml'); - chdir($oldCwd); - - $this->fail('No exception was thrown.'); - } catch (\Exception $e) { - chdir($oldCwd); - - if (!$e instanceof UnexpectedValueException) { - $this->fail('Expected UnexpectedValueException'); - } - } + $this->encoder->decode(']>&test;', 'xml'); } public function testDecodeEmptyXml() diff --git a/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php b/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php index 8e499fd6edace..8a6723ea9cb1a 100644 --- a/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php +++ b/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php @@ -65,7 +65,6 @@ public function successLangcodes() array('2', array('nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM')), array('3', array('be', 'bs', 'cs', 'hr')), array('4', array('cy', 'mt', 'sl')), - array('5', array()), array('6', array('ar')), ); } @@ -86,7 +85,6 @@ public function failingLangcodes() array('3', array('cbs')), array('4', array('gd', 'kw')), array('5', array('ga')), - array('6', array()), ); } diff --git a/src/Symfony/Component/Translation/Tests/TranslatorTest.php b/src/Symfony/Component/Translation/Tests/TranslatorTest.php index 25db5752c0e71..2394fdb4320b1 100644 --- a/src/Symfony/Component/Translation/Tests/TranslatorTest.php +++ b/src/Symfony/Component/Translation/Tests/TranslatorTest.php @@ -156,6 +156,7 @@ public function testSetFallbackValidLocales($locale) $translator = new Translator($locale, new MessageSelector()); $translator->setFallbackLocales(array('fr', $locale)); // no assertion. this method just asserts that no exception is thrown + $this->addToAssertionCount(1); } public function testTransWithFallbackLocale() @@ -187,6 +188,7 @@ public function testAddResourceValidLocales($locale) $translator = new Translator('fr', new MessageSelector()); $translator->addResource('array', array('foo' => 'foofoo'), $locale); // no assertion. this method just asserts that no exception is thrown + $this->addToAssertionCount(1); } public function testAddResourceAfterTrans() @@ -390,6 +392,7 @@ public function testTransChoiceValidLocale($locale) $translator->transChoice('foo', 1, array(), '', $locale); // no assertion. this method just asserts that no exception is thrown + $this->addToAssertionCount(1); } public function getTransFileTests() diff --git a/src/Symfony/Component/Validator/Constraints/Composite.php b/src/Symfony/Component/Validator/Constraints/Composite.php index ab8466bcfcbc4..d1391bb0724af 100644 --- a/src/Symfony/Component/Validator/Constraints/Composite.php +++ b/src/Symfony/Component/Validator/Constraints/Composite.php @@ -67,6 +67,10 @@ public function __construct($options = null) foreach ($nestedConstraints as $constraint) { if (!$constraint instanceof Constraint) { + if (is_object($constraint)) { + $constraint = get_class($constraint); + } + throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, get_class($this))); } diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 7c998f530dab2..e580e06b01e23 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -33,7 +33,9 @@ class UrlValidator extends ConstraintValidator \] # an IPv6 address ) (:[0-9]+)? # a port (optional) - (/?|/\S+|\?\S*|\#\S*) # a /, nothing, a / with something, a query or a fragment + (?:/ (?:[\pL\pN\-._\~!$&\'()*+,;=:@]|%%[0-9A-Fa-f]{2})* )* # a path + (?:\? (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a query (optional) + (?:\# (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a fragment (optional) $~ixu'; /** diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php index b392bbd31ec8e..af32dae4ae8e8 100644 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php @@ -257,9 +257,8 @@ public function addPropertyConstraints($property, array $constraints) * The name of the getter is assumed to be the name of the property with an * uppercased first letter and either the prefix "get" or "is". * - * @param string $property The name of the property - * @param Constraint $constraint The constraint - * @param string|null $method The method that is called to retrieve the value being validated (null for auto-detection) + * @param string $property The name of the property + * @param Constraint $constraint The constraint * * @return $this */ diff --git a/src/Symfony/Component/Validator/Tests/ConstraintTest.php b/src/Symfony/Component/Validator/Tests/ConstraintTest.php index 1b1219664402b..a05741490fdde 100644 --- a/src/Symfony/Component/Validator/Tests/ConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/ConstraintTest.php @@ -115,7 +115,9 @@ public function testRequiredOptionsMustBeDefined() public function testRequiredOptionsPassed() { - new ConstraintC(array('option1' => 'default')); + $constraint = new ConstraintC(array('option1' => 'default')); + + $this->assertSame('default', $constraint->option1); } public function testGroupsAreConvertedToArray() @@ -140,7 +142,9 @@ public function testAllowsSettingZeroRequiredPropertyValue() public function testCanCreateConstraintWithNoDefaultOptionAndEmptyArray() { - new ConstraintB(array()); + $constraint = new ConstraintB(array()); + + $this->assertSame(array(Constraint::PROPERTY_CONSTRAINT, Constraint::CLASS_CONSTRAINT), $constraint->getTargets()); } public function testGetTargetsCanBeString() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php index 200c69071fe88..cb1b5c7b012c2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php @@ -211,7 +211,9 @@ public function testConstraintGetTargets() // Should succeed. Needed when defining constraints as annotations. public function testNoConstructorArguments() { - new Callback(); + $constraint = new Callback(); + + $this->assertSame(array(Constraint::CLASS_CONSTRAINT, Constraint::PROPERTY_CONSTRAINT), $constraint->getTargets()); } public function testAnnotationInvocationSingleValued() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CompositeTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CompositeTest.php index 6a8530723fb05..df4255007c5ca 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CompositeTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CompositeTest.php @@ -125,6 +125,17 @@ public function testFailIfNoConstraint() )); } + /** + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + */ + public function testFailIfNoConstraintObject() + { + new ConcreteComposite(array( + new NotNull(array('groups' => 'Default')), + new \ArrayObject(), + )); + } + /** * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index 37dcd634530a8..c48d45a2e575e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -123,6 +123,7 @@ public function getValidUrls() array('http://symfony.com#'), array('http://symfony.com#fragment'), array('http://symfony.com/#fragment'), + array('http://symfony.com/#one_more%20test'), ); } @@ -163,6 +164,9 @@ public function getInvalidUrls() array('http://:password@@symfony.com'), array('http://username:passwordsymfony.com'), array('http://usern@me:password@symfony.com'), + array('http://example.com/exploit.html?'), + array('http://example.com/exploit.html?hel lo'), + array('http://example.com/exploit.html?not_a%hex'), ); } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php index 8ca3c9fbcb606..9a23e8cf355a0 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php @@ -245,19 +245,23 @@ public function testSerialize() public function testGroupSequencesWorkIfContainingDefaultGroup() { $this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup())); + + $this->assertInstanceOf('Symfony\Component\Validator\Constraints\GroupSequence', $this->metadata->getGroupSequence()); } + /** + * @expectedException \Symfony\Component\Validator\Exception\GroupDefinitionException + */ public function testGroupSequencesFailIfNotContainingDefaultGroup() { - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\GroupDefinitionException'); - $this->metadata->setGroupSequence(array('Foo', 'Bar')); } + /** + * @expectedException \Symfony\Component\Validator\Exception\GroupDefinitionException + */ public function testGroupSequencesFailIfContainingDefault() { - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Validator\Exception\GroupDefinitionException'); - $this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup(), Constraint::DEFAULT_GROUP)); } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php index 1ebce65cc2029..b5d1a9dc84d4d 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php @@ -167,7 +167,11 @@ public function testMetadataCacheWithRuntimeConstraint() $metadata = $factory->getMetadataFor(self::PARENT_CLASS); $metadata->addConstraint(new Callback(function () {})); + $this->assertCount(3, $metadata->getConstraints()); + $metadata = $factory->getMetadataFor(self::CLASS_NAME); + + $this->assertCount(6, $metadata->getConstraints()); } public function testGroupsFromParent() diff --git a/src/Symfony/Component/Validator/Tests/Resources/TranslationFilesTest.php b/src/Symfony/Component/Validator/Tests/Resources/TranslationFilesTest.php index d33351352777c..96311cfeff326 100644 --- a/src/Symfony/Component/Validator/Tests/Resources/TranslationFilesTest.php +++ b/src/Symfony/Component/Validator/Tests/Resources/TranslationFilesTest.php @@ -25,6 +25,8 @@ public function testTranslationFileIsValid($filePath) } else { \PHPUnit\Util\XML::loadfile($filePath, false, false, true); } + + $this->addToAssertionCount(1); } public function provideTranslationFiles() diff --git a/src/Symfony/Component/VarDumper/Caster/Caster.php b/src/Symfony/Component/VarDumper/Caster/Caster.php index 5428fecc2b27b..5749e0762a684 100644 --- a/src/Symfony/Component/VarDumper/Caster/Caster.php +++ b/src/Symfony/Component/VarDumper/Caster/Caster.php @@ -132,8 +132,10 @@ public static function filter(array $a, $filter, array $listedProperties = array public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, $isNested) { - $stub->class .= '('.$a['__PHP_Incomplete_Class_Name'].')'; - unset($a['__PHP_Incomplete_Class_Name']); + if (isset($a['__PHP_Incomplete_Class_Name'])) { + $stub->class .= '('.$a['__PHP_Incomplete_Class_Name'].')'; + unset($a['__PHP_Incomplete_Class_Name']); + } return $a; } diff --git a/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php b/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php index aa32d8b90bb98..6a9fc101c2d28 100644 --- a/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php @@ -67,7 +67,7 @@ public static function castThrowingCasterException(ThrowingCasterException $e, a $prefix = Caster::PREFIX_PROTECTED; $xPrefix = "\0Exception\0"; - if (isset($a[$xPrefix.'previous'], $a[$xPrefix.'trace'])) { + if (isset($a[$xPrefix.'previous'], $a[$xPrefix.'trace']) && $a[$xPrefix.'previous'] instanceof \Exception) { $b = (array) $a[$xPrefix.'previous']; self::traceUnshift($b[$xPrefix.'trace'], get_class($a[$xPrefix.'previous']), $b[$prefix.'file'], $b[$prefix.'line']); $a[$xPrefix.'trace'] = new TraceStub($b[$xPrefix.'trace'], false, 0, -1 - count($a[$xPrefix.'trace']->value)); @@ -218,7 +218,9 @@ private static function filterExceptionArray($xClass, array $a, $xPrefix, $filte } if (!($filter & Caster::EXCLUDE_VERBOSE)) { - self::traceUnshift($trace, $xClass, $a[Caster::PREFIX_PROTECTED.'file'], $a[Caster::PREFIX_PROTECTED.'line']); + if (isset($a[Caster::PREFIX_PROTECTED.'file'], $a[Caster::PREFIX_PROTECTED.'line'])) { + self::traceUnshift($trace, $xClass, $a[Caster::PREFIX_PROTECTED.'file'], $a[Caster::PREFIX_PROTECTED.'line']); + } $a[$xPrefix.'trace'] = new TraceStub($trace, self::$traceArgs); } if (empty($a[$xPrefix.'previous'])) { @@ -226,7 +228,9 @@ private static function filterExceptionArray($xClass, array $a, $xPrefix, $filte } unset($a[$xPrefix.'string'], $a[Caster::PREFIX_DYNAMIC.'xdebug_message'], $a[Caster::PREFIX_DYNAMIC.'__destructorException']); - $a[Caster::PREFIX_PROTECTED.'file'] = new LinkStub($a[Caster::PREFIX_PROTECTED.'file'], $a[Caster::PREFIX_PROTECTED.'line']); + if (isset($a[Caster::PREFIX_PROTECTED.'file'], $a[Caster::PREFIX_PROTECTED.'line'])) { + $a[Caster::PREFIX_PROTECTED.'file'] = new LinkStub($a[Caster::PREFIX_PROTECTED.'file'], $a[Caster::PREFIX_PROTECTED.'line']); + } return $a; } diff --git a/src/Symfony/Component/VarDumper/Caster/RedisCaster.php b/src/Symfony/Component/VarDumper/Caster/RedisCaster.php index 7275a7d2c7f88..07a3a1b091126 100644 --- a/src/Symfony/Component/VarDumper/Caster/RedisCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/RedisCaster.php @@ -31,8 +31,10 @@ public static function castRedis(\Redis $c, array $a, Stub $stub, $isNested) $prefix = Caster::PREFIX_VIRTUAL; if (defined('HHVM_VERSION_ID')) { - $ser = $a[Caster::PREFIX_PROTECTED.'serializer']; - $a[Caster::PREFIX_PROTECTED.'serializer'] = isset(self::$serializer[$ser]) ? new ConstStub(self::$serializer[$ser], $ser) : $ser; + if (isset($a[Caster::PREFIX_PROTECTED.'serializer'])) { + $ser = $a[Caster::PREFIX_PROTECTED.'serializer']; + $a[Caster::PREFIX_PROTECTED.'serializer'] = isset(self::$serializer[$ser]) ? new ConstStub(self::$serializer[$ser], $ser) : $ser; + } return $a; } diff --git a/src/Symfony/Component/Workflow/DefinitionBuilder.php b/src/Symfony/Component/Workflow/DefinitionBuilder.php index 34d27aa5e9d0d..47980004cdec7 100644 --- a/src/Symfony/Component/Workflow/DefinitionBuilder.php +++ b/src/Symfony/Component/Workflow/DefinitionBuilder.php @@ -54,11 +54,17 @@ public function reset() $this->initialPlace = null; } + /** + * @param string $place + */ public function setInitialPlace($place) { $this->initialPlace = $place; } + /** + * @param string $place + */ public function addPlace($place) { if (!preg_match('{^[\w\d_-]+$}', $place)) { @@ -72,6 +78,9 @@ public function addPlace($place) $this->places[$place] = $place; } + /** + * @param string[] $places + */ public function addPlaces(array $places) { foreach ($places as $place) { diff --git a/src/Symfony/Component/Workflow/README.md b/src/Symfony/Component/Workflow/README.md index d0a1a4d3a9aef..068bd887689f2 100644 --- a/src/Symfony/Component/Workflow/README.md +++ b/src/Symfony/Component/Workflow/README.md @@ -4,7 +4,7 @@ Workflow Component Resources --------- - * [Documentation](https://symfony.com/doc/master/components/workflow.html) + * [Documentation](https://symfony.com/doc/current/components/workflow.html) * [Contributing](https://symfony.com/doc/current/contributing/index.html) * [Report issues](https://github.com/symfony/symfony/issues) and [send Pull Requests](https://github.com/symfony/symfony/pulls) diff --git a/src/Symfony/Component/Workflow/Tests/Validator/StateMachineValidatorTest.php b/src/Symfony/Component/Workflow/Tests/Validator/StateMachineValidatorTest.php index 149d7d58f8e30..dccbf383049ad 100644 --- a/src/Symfony/Component/Workflow/Tests/Validator/StateMachineValidatorTest.php +++ b/src/Symfony/Component/Workflow/Tests/Validator/StateMachineValidatorTest.php @@ -94,6 +94,9 @@ public function testValid() (new StateMachineValidator())->validate($definition, 'foo'); + // the test simply ensures that the validation does not fail (i.e. it does not throw any exceptions) + $this->addToAssertionCount(1); + // The graph looks like: // // +----+ +----+ +---+ diff --git a/src/Symfony/Component/Workflow/Tests/Validator/WorkflowValidatorTest.php b/src/Symfony/Component/Workflow/Tests/Validator/WorkflowValidatorTest.php index 60b2c7150e489..245617b682f54 100644 --- a/src/Symfony/Component/Workflow/Tests/Validator/WorkflowValidatorTest.php +++ b/src/Symfony/Component/Workflow/Tests/Validator/WorkflowValidatorTest.php @@ -28,6 +28,9 @@ public function testSinglePlaceWorkflowValidatorAndSimpleWorkflow() $definition = $this->createSimpleWorkflowDefinition(); (new WorkflowValidator(true))->validate($definition, 'foo'); + + // the test simply ensures that the validation does not fail (i.e. it does not throw any exceptions) + $this->addToAssertionCount(1); } /** @@ -60,5 +63,8 @@ public function testSameTransitionNameButNotSamePlace() $definition = new Definition($places, $transitions); (new WorkflowValidator())->validate($definition, 'foo'); + + // the test simply ensures that the validation does not fail (i.e. it does not throw any exceptions) + $this->addToAssertionCount(1); } } diff --git a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php index ab8c767b59c17..c1efb0182765a 100644 --- a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php +++ b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php @@ -104,6 +104,23 @@ public function testCan() $this->assertTrue($workflow->can($subject, 't1')); $this->assertFalse($workflow->can($subject, 't2')); + + $subject->marking = array('b' => 1); + + $this->assertFalse($workflow->can($subject, 't1')); + // In a workflow net, all "from" places should contain a token to enable + // the transition. + $this->assertFalse($workflow->can($subject, 't2')); + + $subject->marking = array('b' => 1, 'c' => 1); + + $this->assertFalse($workflow->can($subject, 't1')); + $this->assertTrue($workflow->can($subject, 't2')); + + $subject->marking = array('f' => 1); + + $this->assertFalse($workflow->can($subject, 't5')); + $this->assertTrue($workflow->can($subject, 't6')); } public function testCanWithGuard() diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 2109f08bb370c..eb3ffed6f3690 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -210,9 +210,9 @@ public static function dump($value, $flags = 0) case Escaper::requiresDoubleQuoting($value): return Escaper::escapeWithDoubleQuotes($value); case Escaper::requiresSingleQuoting($value): - case preg_match('{^[0-9]+[_0-9]*$}', $value): - case preg_match(self::getHexRegex(), $value): - case preg_match(self::getTimestampRegex(), $value): + case Parser::preg_match('{^[0-9]+[_0-9]*$}', $value): + case Parser::preg_match(self::getHexRegex(), $value): + case Parser::preg_match(self::getTimestampRegex(), $value): return Escaper::escapeWithSingleQuotes($value); default: return $value; @@ -306,10 +306,10 @@ public static function parseScalar($scalar, $flags = 0, $delimiters = null, $str $i += strlen($output); // remove comments - if (preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) { + if (Parser::preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) { $output = substr($output, 0, $match[0][1]); } - } elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) { + } elseif (Parser::preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) { $output = $match[1]; $i += strlen($output); } else { @@ -345,7 +345,7 @@ public static function parseScalar($scalar, $flags = 0, $delimiters = null, $str */ private static function parseQuotedScalar($scalar, &$i) { - if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) { + if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) { throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i))); } @@ -614,7 +614,7 @@ private static function evaluateScalar($scalar, $flags, $references = array()) return; case 0 === strpos($scalar, '!!float '): return (float) substr($scalar, 8); - case preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar): + case Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar): $scalar = str_replace('_', '', (string) $scalar); // omitting the break / return as integers are handled in the next case case ctype_digit($scalar): @@ -628,7 +628,7 @@ private static function evaluateScalar($scalar, $flags, $references = array()) return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw); case is_numeric($scalar): - case preg_match(self::getHexRegex(), $scalar): + case Parser::preg_match(self::getHexRegex(), $scalar): $scalar = str_replace('_', '', $scalar); return '0x' === $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar; @@ -639,14 +639,14 @@ private static function evaluateScalar($scalar, $flags, $references = array()) return log(0); case 0 === strpos($scalar, '!!binary '): return self::evaluateBinaryScalar(substr($scalar, 9)); - case preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9_]+)?$/', $scalar): - case preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar): + case Parser::preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9_]+)?$/', $scalar): + case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar): if (false !== strpos($scalar, ',')) { @trigger_error('Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED); } return (float) str_replace(array(',', '_'), '', $scalar); - case preg_match(self::getTimestampRegex(), $scalar): + case Parser::preg_match(self::getTimestampRegex(), $scalar): if (Yaml::PARSE_DATETIME & $flags) { // When no timezone is provided in the parsed date, YAML spec says we must assume UTC. return new \DateTime($scalar, new \DateTimeZone('UTC')); @@ -679,7 +679,7 @@ public static function evaluateBinaryScalar($scalar) throw new ParseException(sprintf('The normalized base64 encoded data (data without whitespace characters) length must be a multiple of four (%d bytes given).', strlen($parsedBinaryData))); } - if (!preg_match('#^[A-Z0-9+/]+={0,2}$#i', $parsedBinaryData)) { + if (!Parser::preg_match('#^[A-Z0-9+/]+={0,2}$#i', $parsedBinaryData)) { throw new ParseException(sprintf('The base64 encoded data (%s) contains invalid characters.', $parsedBinaryData)); } diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index b3dbad067d7b0..5746a138f16d5 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -84,7 +84,7 @@ public function parse($value, $flags = 0) } } - if (!preg_match('//u', $value)) { + if (false === preg_match('//u', $value)) { throw new ParseException('The YAML value does not appear to be valid UTF-8.'); } $this->currentLineNb = -1; @@ -115,13 +115,13 @@ public function parse($value, $flags = 0) } $isRef = $mergeNode = false; - if (preg_match('#^\-((?P\s+)(?P.+?))?\s*$#u', $this->currentLine, $values)) { + if (self::preg_match('#^\-((?P\s+)(?P.+))?$#u', rtrim($this->currentLine), $values)) { if ($context && 'mapping' == $context) { throw new ParseException('You cannot define a sequence item when in a mapping', $this->getRealCurrentLineNb() + 1, $this->currentLine); } $context = 'sequence'; - if (isset($values['value']) && preg_match('#^&(?P[^ ]+) *(?P.*)#u', $values['value'], $matches)) { + if (isset($values['value']) && self::preg_match('#^&(?P[^ ]+) *(?P.*)#u', $values['value'], $matches)) { $isRef = $matches['ref']; $values['value'] = $matches['value']; } @@ -131,7 +131,7 @@ public function parse($value, $flags = 0) $data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags); } else { if (isset($values['leadspaces']) - && preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P.+?))?\s*$#u', $values['value'], $matches) + && self::preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P.+))?$#u', rtrim($values['value']), $matches) ) { // this is a compact notation element, add to next block and parse $block = $values['value']; @@ -147,7 +147,10 @@ public function parse($value, $flags = 0) if ($isRef) { $this->refs[$isRef] = end($data); } - } elseif (preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P.+?))?\s*$#u', $this->currentLine, $values) && (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))) { + } elseif ( + self::preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P.+))?$#u', rtrim($this->currentLine), $values) + && (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'"))) + ) { if ($context && 'sequence' == $context) { throw new ParseException('You cannot define a mapping item when in a sequence', $this->currentLineNb + 1, $this->currentLine); } @@ -215,7 +218,7 @@ public function parse($value, $flags = 0) $data += $parsed; // array union } } - } elseif (isset($values['value']) && preg_match('#^&(?P[^ ]+) *(?P.*)#u', $values['value'], $matches)) { + } elseif (isset($values['value']) && self::preg_match('#^&(?P[^ ]+) *(?P.*)#u', $values['value'], $matches)) { $isRef = $matches['ref']; $values['value'] = $matches['value']; } @@ -283,27 +286,7 @@ public function parse($value, $flags = 0) return $value; } - switch (preg_last_error()) { - case PREG_INTERNAL_ERROR: - $error = 'Internal PCRE error.'; - break; - case PREG_BACKTRACK_LIMIT_ERROR: - $error = 'pcre.backtrack_limit reached.'; - break; - case PREG_RECURSION_LIMIT_ERROR: - $error = 'pcre.recursion_limit reached.'; - break; - case PREG_BAD_UTF8_ERROR: - $error = 'Malformed UTF-8 data.'; - break; - case PREG_BAD_UTF8_OFFSET_ERROR: - $error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point.'; - break; - default: - $error = 'Unable to parse.'; - } - - throw new ParseException($error, $this->getRealCurrentLineNb() + 1, $this->currentLine); + throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } } @@ -546,7 +529,7 @@ private function parseValue($value, $flags, $context) return $this->refs[$value]; } - if (preg_match('/^'.self::TAG_PATTERN.self::BLOCK_SCALAR_HEADER_PATTERN.'$/', $value, $matches)) { + if (self::preg_match('/^'.self::TAG_PATTERN.self::BLOCK_SCALAR_HEADER_PATTERN.'$/', $value, $matches)) { $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : ''; $data = $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers)); @@ -628,7 +611,7 @@ private function parseBlockScalar($style, $chomping = '', $indentation = 0) // determine indentation if not specified if (0 === $indentation) { - if (preg_match('/^ +/', $this->currentLine, $matches)) { + if (self::preg_match('/^ +/', $this->currentLine, $matches)) { $indentation = strlen($matches[0]); } } @@ -639,7 +622,7 @@ private function parseBlockScalar($style, $chomping = '', $indentation = 0) while ( $notEOF && ( $isCurrentLineBlank || - preg_match($pattern, $this->currentLine, $matches) + self::preg_match($pattern, $this->currentLine, $matches) ) ) { if ($isCurrentLineBlank && strlen($this->currentLine) > $indentation) { @@ -727,10 +710,7 @@ private function isNextLineIndented() return false; } - $ret = false; - if ($this->getCurrentLineIndentation() > $currentIndentation) { - $ret = true; - } + $ret = $this->getCurrentLineIndentation() > $currentIndentation; $this->moveToPreviousLine(); @@ -831,14 +811,7 @@ private function isNextLineUnIndentedCollection() return false; } - $ret = false; - if ( - $this->getCurrentLineIndentation() == $currentIndentation - && - $this->isStringUnIndentedCollectionItem() - ) { - $ret = true; - } + $ret = $this->getCurrentLineIndentation() === $currentIndentation && $this->isStringUnIndentedCollectionItem(); $this->moveToPreviousLine(); @@ -862,6 +835,48 @@ private function isStringUnIndentedCollectionItem() */ private function isBlockScalarHeader() { - return (bool) preg_match('~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~', $this->currentLine); + return (bool) self::preg_match('~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~', $this->currentLine); + } + + /** + * A local wrapper for `preg_match` which will throw a ParseException if there + * is an internal error in the PCRE engine. + * + * This avoids us needing to check for "false" every time PCRE is used + * in the YAML engine + * + * @throws ParseException on a PCRE internal error + * + * @see preg_last_error() + * + * @internal + */ + public static function preg_match($pattern, $subject, &$matches = null, $flags = 0, $offset = 0) + { + if (false === $ret = preg_match($pattern, $subject, $matches, $flags, $offset)) { + switch (preg_last_error()) { + case PREG_INTERNAL_ERROR: + $error = 'Internal PCRE error.'; + break; + case PREG_BACKTRACK_LIMIT_ERROR: + $error = 'pcre.backtrack_limit reached.'; + break; + case PREG_RECURSION_LIMIT_ERROR: + $error = 'pcre.recursion_limit reached.'; + break; + case PREG_BAD_UTF8_ERROR: + $error = 'Malformed UTF-8 data.'; + break; + case PREG_BAD_UTF8_OFFSET_ERROR: + $error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point.'; + break; + default: + $error = 'Error.'; + } + + throw new ParseException($error); + } + + return $ret; } } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 5328b27b36808..956b71ad9cc8a 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -18,6 +18,7 @@ class ParserTest extends TestCase { + /** @var Parser */ protected $parser; protected function setUp() @@ -1478,6 +1479,17 @@ public function testParseMultiLineUnquotedString() $this->assertSame(array('foo' => 'bar baz foobar foo', 'bar' => 'baz'), $this->parser->parse($yaml)); } + + public function testCanParseVeryLongValue() + { + $longStringWithSpaces = str_repeat('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ', 20000); + $trickyVal = array('x' => $longStringWithSpaces); + + $yamlString = Yaml::dump($trickyVal); + $arrayFromYaml = $this->parser->parse($yamlString); + + $this->assertEquals($trickyVal, $arrayFromYaml); + } } class B