Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0801a3a

Browse files
committed
Merge branch '2.4' into 2.5
* 2.4: [Validator] Backported constraint validator tests from 2.5 [Validator] Backported constraint validator tests from 2.5 Fix toolbar vertical alignment. [HttpFoundation] MongoDbSessionHandler supports auto expiry via configurable expiry_field [FrameworkBundle] add missing attribute to XSD Allow basic auth in url. Improve regex. Add tests. fix typos and syntax in Profiler controller method comments remove volatile tests [Console] fixed style creation when providing an unknown tag option [Validator] Convert objects to string in comparison validators. Reapplies 6cf5e08 [HttpFoundation] Update QUERY_STRING when overrideGlobals Conflicts: src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php src/Symfony/Component/Validator/Constraints/AllValidator.php src/Symfony/Component/Validator/Constraints/ChoiceValidator.php src/Symfony/Component/Validator/Constraints/CollectionValidator.php src/Symfony/Component/Validator/Constraints/ExpressionValidator.php src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/AllValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/GroupSequenceTest.php src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/IssnValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php src/Symfony/Component/Validator/Tests/Fixtures/StubGlobalExecutionContext.php
2 parents 35994bf + 16c94d2 commit 0801a3a

File tree

29 files changed

+219
-119
lines changed

29 files changed

+219
-119
lines changed

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
use Doctrine\Common\Persistence\ObjectRepository;
1717
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
1818
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity;
19-
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
2019
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
2120
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity;
2221
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
2322
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
2423
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
24+
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
2525
use Symfony\Component\Validator\Validation;
2626
use Symfony\Component\Validator\Validator;
2727
use Doctrine\ORM\Tools\SchemaTool;

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
<xsd:attribute name="assets-version" type="xsd:string" />
137137
<xsd:attribute name="assets-version-format" type="xsd:string" />
138138
<xsd:attribute name="cache" type="xsd:string" />
139+
<xsd:attribute name="hinclude-default-template" type="xsd:string" />
139140
</xsd:complexType>
140141

141142
<xsd:complexType name="form-resources">

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'form' => array(
5757
'resources' => array('theme1', 'theme2')
5858
),
59+
'hinclude_default_template' => 'global_hinclude_template',
5960
),
6061
'translator' => array(
6162
'enabled' => true,

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<framework:mime-type>application/pdf</framework:mime-type>
2323
</framework:format>
2424
</framework:request>
25-
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >
25+
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" hinclude-default-template="global_hinclude_template">
2626
<framework:loader>loader.foo</framework:loader>
2727
<framework:loader>loader.bar</framework:loader>
2828
<framework:engine>php</framework:engine>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ framework:
4444
base_urls: ["http://images1.example.com", "http://images2.example.com"]
4545
form:
4646
resources: [theme1, theme2]
47+
hinclude_default_template: global_hinclude_template
4748
translator:
4849
enabled: true
4950
fallback: fr

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public function testTemplating()
198198
$this->assertEquals(array('php', 'twig'), $container->getParameter('templating.engines'), '->registerTemplatingConfiguration() sets a templating.engines parameter');
199199

200200
$this->assertEquals(array('FrameworkBundle:Form', 'theme1', 'theme2'), $container->getParameter('templating.helper.form.resources'), '->registerTemplatingConfiguration() registers the theme and adds the base theme');
201+
$this->assertEquals('global_hinclude_template', $container->getParameter('fragment.renderer.hinclude.global_template'), '->registerTemplatingConfiguration() registers the global hinclude.js template');
201202
}
202203

203204
public function testTemplatingAssetsHelperScopeDependsOnPackageArgumentScopes()

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public function searchBarAction(Request $request)
310310
}
311311

312312
/**
313-
* Search results.
313+
* Renders the search results.
314314
*
315315
* @param Request $request The current HTTP Request
316316
* @param string $token The token
@@ -351,7 +351,7 @@ public function searchResultsAction(Request $request, $token)
351351
}
352352

353353
/**
354-
* Narrow the search bar.
354+
* Narrows the search bar.
355355
*
356356
* @param Request $request The current HTTP Request
357357
*

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
-webkit-box-sizing: content-box;
2323
-moz-box-sizing: content-box;
2424
box-sizing: content-box;
25+
vertical-align: baseline;
2526
}
2627

2728
.sf-toolbarreset {

src/Symfony/Component/Console/Formatter/OutputFormatter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ private function createStyleFromString($string)
215215
} elseif ('bg' == $match[0]) {
216216
$style->setBackground($match[1]);
217217
} else {
218-
$style->setOption($match[1]);
218+
try {
219+
$style->setOption($match[1]);
220+
} catch (\InvalidArgumentException $e) {
221+
return false;
222+
}
219223
}
220224
}
221225

src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function testNonStyleTag()
151151
{
152152
$formatter = new OutputFormatter(true);
153153

154-
$this->assertEquals("\033[32msome \033[39m\033[32m<tag>\033[39m\033[32m styled \033[39m\033[32m<p>\033[39m\033[32msingle-char tag\033[39m\033[32m</p>\033[39m", $formatter->format('<info>some <tag> styled <p>single-char tag</p></info>'));
154+
$this->assertEquals("\033[32msome \033[39m\033[32m<tag>\033[39m\033[32m \033[39m\033[32m<setting=value>\033[39m\033[32m styled \033[39m\033[32m<p>\033[39m\033[32msingle-char tag\033[39m\033[32m</p>\033[39m", $formatter->format('<info>some <tag> <setting=value> styled <p>single-char tag</p></info>'));
155155
}
156156

157157
public function testFormatLongString()

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -831,25 +831,4 @@ public function testMultipleLocationsWithSubDirectories()
831831
$this->assertIterator($expected, $finder);
832832
$this->assertIteratorInForeach($expected, $finder);
833833
}
834-
835-
public function testNonSeekableStream()
836-
{
837-
if (!in_array('ftp', stream_get_wrappers())) {
838-
$this->markTestSkipped(sprintf('Unavailable stream "%s".', 'ftp'));
839-
}
840-
841-
try {
842-
$i = Finder::create()->in('ftp://ftp.mozilla.org/')->depth(0)->getIterator();
843-
} catch (\UnexpectedValueException $e) {
844-
$this->markTestSkipped(sprintf('Unsupported stream "%s".', 'ftp'));
845-
}
846-
847-
$contains = array(
848-
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'README',
849-
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'index.html',
850-
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'pub',
851-
);
852-
853-
$this->assertIteratorInForeach($contains, $i);
854-
}
855834
}

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ public function __toString()
502502
*/
503503
public function overrideGlobals()
504504
{
505+
$this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), null, '&')));
506+
505507
$_GET = $this->query->all();
506508
$_POST = $this->request->all();
507509
$_SERVER = $this->server->all();

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ public function __construct($mongo, array $options)
6262
$this->mongo = $mongo;
6363

6464
$this->options = array_merge(array(
65-
'id_field' => '_id',
66-
'data_field' => 'data',
67-
'time_field' => 'time',
65+
'id_field' => '_id',
66+
'data_field' => 'data',
67+
'time_field' => 'time',
68+
'expiry_field' => false,
6869
), $options);
6970
}
7071

@@ -109,6 +110,9 @@ public function gc($maxlifetime)
109110
*
110111
* See: http://docs.mongodb.org/manual/tutorial/expire-data/
111112
*/
113+
if (false !== $this->options['expiry_field']) {
114+
return true;
115+
}
112116
$time = new \MongoDate(time() - $maxlifetime);
113117

114118
$this->getCollection()->remove(array(
@@ -123,12 +127,27 @@ public function gc($maxlifetime)
123127
*/
124128
public function write($sessionId, $data)
125129
{
130+
$fields = array(
131+
$this->options['data_field'] => new \MongoBinData($data, \MongoBinData::BYTE_ARRAY),
132+
$this->options['time_field'] => new \MongoDate(),
133+
);
134+
135+
/* Note: As discussed in the gc method of this class. You can utilise
136+
* TTL collections in MongoDB 2.2+
137+
* We are setting the "expiry_field" as part of the write operation here
138+
* You will need to create the index on your collection that expires documents
139+
* at that time
140+
* e.g.
141+
* db.MySessionCollection.ensureIndex( { "expireAt": 1 }, { expireAfterSeconds: 0 } )
142+
*/
143+
if (false !== $this->options['expiry_field']) {
144+
$expiry = new \MongoDate(time() + (int) ini_get('session.gc_maxlifetime'));
145+
$fields[$this->options['expiry_field']] = $expiry;
146+
}
147+
126148
$this->getCollection()->update(
127149
array($this->options['id_field'] => $sessionId),
128-
array('$set' => array(
129-
$this->options['data_field'] => new \MongoBinData($data, \MongoBinData::BYTE_ARRAY),
130-
$this->options['time_field'] => new \MongoDate(),
131-
)),
150+
array('$set' => $fields),
132151
array('upsert' => true, 'multiple' => false)
133152
);
134153

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,10 +1012,21 @@ public function testOverrideGlobals()
10121012

10131013
$request->headers->set('CONTENT_TYPE', 'multipart/form-data');
10141014
$request->headers->set('CONTENT_LENGTH', 12345);
1015+
10151016
$request->overrideGlobals();
1017+
10161018
$this->assertArrayHasKey('CONTENT_TYPE', $_SERVER);
10171019
$this->assertArrayHasKey('CONTENT_LENGTH', $_SERVER);
10181020

1021+
$request->initialize(array('foo' => 'bar', 'baz' => 'foo'));
1022+
$request->query->remove('baz');
1023+
1024+
$request->overrideGlobals();
1025+
1026+
$this->assertEquals(array('foo' => 'bar'), $_GET);
1027+
$this->assertEquals('foo=bar', $_SERVER['QUERY_STRING']);
1028+
$this->assertEquals('foo=bar', $request->server->get('QUERY_STRING'));
1029+
10191030
// restore initial $_SERVER array
10201031
$_SERVER = $server;
10211032
}

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function setUp()
4141
'data_field' => 'data',
4242
'time_field' => 'time',
4343
'database' => 'sf2-test',
44-
'collection' => 'session-test'
44+
'collection' => 'session-test',
4545
);
4646

4747
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
@@ -100,6 +100,45 @@ public function testWrite()
100100
$that->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
101101
}
102102

103+
public function testWriteWhenUsingExpiresField()
104+
{
105+
$this->options = array(
106+
'id_field' => '_id',
107+
'data_field' => 'data',
108+
'time_field' => 'time',
109+
'database' => 'sf2-test',
110+
'collection' => 'session-test',
111+
'expiry_field' => 'expiresAt'
112+
);
113+
114+
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
115+
116+
$collection = $this->createMongoCollectionMock();
117+
118+
$this->mongo->expects($this->once())
119+
->method('selectCollection')
120+
->with($this->options['database'], $this->options['collection'])
121+
->will($this->returnValue($collection));
122+
123+
$that = $this;
124+
$data = array();
125+
126+
$collection->expects($this->once())
127+
->method('update')
128+
->will($this->returnCallback(function ($criteria, $updateData, $options) use ($that, &$data) {
129+
$that->assertEquals(array($that->options['id_field'] => 'foo'), $criteria);
130+
$that->assertEquals(array('upsert' => true, 'multiple' => false), $options);
131+
132+
$data = $updateData['$set'];
133+
}));
134+
135+
$this->assertTrue($this->storage->write('foo', 'bar'));
136+
137+
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
138+
$that->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
139+
$that->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
140+
}
141+
103142
public function testReplaceSessionData()
104143
{
105144
$collection = $this->createMongoCollectionMock();
@@ -154,10 +193,36 @@ public function testGc()
154193
->method('remove')
155194
->will($this->returnCallback(function ($criteria) use ($that) {
156195
$that->assertInstanceOf('MongoDate', $criteria[$that->options['time_field']]['$lt']);
157-
$that->assertGreaterThanOrEqual(time() - -1, $criteria[$that->options['time_field']]['$lt']->sec);
196+
$that->assertGreaterThanOrEqual(time() - 1, $criteria[$that->options['time_field']]['$lt']->sec);
158197
}));
159198

160-
$this->assertTrue($this->storage->gc(-1));
199+
$this->assertTrue($this->storage->gc(1));
200+
}
201+
202+
public function testGcWhenUsingExpiresField()
203+
{
204+
$this->options = array(
205+
'id_field' => '_id',
206+
'data_field' => 'data',
207+
'time_field' => 'time',
208+
'database' => 'sf2-test',
209+
'collection' => 'session-test',
210+
'expiry_field' => 'expiresAt'
211+
);
212+
213+
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
214+
215+
$collection = $this->createMongoCollectionMock();
216+
217+
$this->mongo->expects($this->never())
218+
->method('selectCollection');
219+
220+
$that = $this;
221+
222+
$collection->expects($this->never())
223+
->method('remove');
224+
225+
$this->assertTrue($this->storage->gc(1));
161226
}
162227

163228
public function testGetConnection()

src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,6 @@ public function testStartTime()
149149
$this->assertEquals(0, $event->getStartTime(), null, self::DELTA);
150150
}
151151

152-
public function testEndTime()
153-
{
154-
$event = new StopwatchEvent(microtime(true) * 1000);
155-
$this->assertEquals(0, $event->getEndTime());
156-
157-
$event = new StopwatchEvent(microtime(true) * 1000);
158-
$event->start();
159-
$this->assertEquals(0, $event->getEndTime());
160-
161-
$event = new StopwatchEvent(microtime(true) * 1000);
162-
$event->start();
163-
usleep(100000);
164-
$event->stop();
165-
$event->start();
166-
usleep(100000);
167-
$event->stop();
168-
$this->assertEquals(200, $event->getEndTime(), null, self::DELTA);
169-
}
170-
171152
/**
172153
* @expectedException \InvalidArgumentException
173154
*/

src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,6 @@ public function testStop()
8080
$this->assertEquals(200, $event->getDuration(), null, self::DELTA);
8181
}
8282

83-
public function testLap()
84-
{
85-
$stopwatch = new Stopwatch();
86-
$stopwatch->start('foo', 'cat');
87-
usleep(100000);
88-
$event = $stopwatch->lap('foo');
89-
usleep(100000);
90-
$stopwatch->stop('foo');
91-
92-
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
93-
$this->assertEquals(200, $event->getDuration(), null, self::DELTA);
94-
}
95-
9683
/**
9784
* @expectedException \LogicException
9885
*/

0 commit comments

Comments
 (0)