Skip to content

Commit 2318b60

Browse files
committed
Merge branch '3.1'
* 3.1: expectedException expects FQCN Fixed expectedException annotations [Cache] Fix password used to make the redis connection. Security and validators messages translation to Latvian [Form] FormView->isRendered() remove dead code and simplify the flow Fixed issue with legacy find() method not working as expected
2 parents b53fe24 + 90f6b30 commit 2318b60

File tree

20 files changed

+586
-195
lines changed

20 files changed

+586
-195
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testMissingControllers($name)
9393

9494
try {
9595
$parser->parse($name);
96-
$this->fail('->parse() throws a \InvalidArgumentException if the string is in the valid format, but not matching class can be found');
96+
$this->fail('->parse() throws a \InvalidArgumentException if the class is found but does not exist');
9797
} catch (\Exception $e) {
9898
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws a \InvalidArgumentException if the class is found but does not exist');
9999
}
@@ -108,7 +108,6 @@ public function getMissingControllersTest()
108108
}
109109

110110
/**
111-
* @expectedException
112111
* @dataProvider getInvalidBundleNameTests
113112
*/
114113
public function testInvalidBundleName($bundleName, $suggestedBundleName)
@@ -117,6 +116,7 @@ public function testInvalidBundleName($bundleName, $suggestedBundleName)
117116

118117
try {
119118
$parser->parse($bundleName);
119+
$this->fail('->parse() throws a \InvalidArgumentException if the bundle does not exist');
120120
} catch (\Exception $e) {
121121
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws a \InvalidArgumentException if the bundle does not exist');
122122

src/Symfony/Component/Asset/Tests/UrlPackageTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use Symfony\Component\Asset\UrlPackage;
1515
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
1616
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
17-
use Symfony\Component\Asset\Exception\InvalidArgumentException;
18-
use Symfony\Component\Asset\Exception\LogicException;
1917

2018
class UrlPackageTest extends \PHPUnit_Framework_TestCase
2119
{
@@ -79,15 +77,15 @@ public function getContextConfigs()
7977
}
8078

8179
/**
82-
* @expectedException LogicException
80+
* @expectedException \Symfony\Component\Asset\Exception\LogicException
8381
*/
8482
public function testNoBaseUrls()
8583
{
8684
new UrlPackage(array(), new EmptyVersionStrategy());
8785
}
8886

8987
/**
90-
* @expectedException InvalidArgumentException
88+
* @expectedException \Symfony\Component\Asset\Exception\InvalidArgumentException
9189
*/
9290
public function testWrongBaseUrl()
9391
{

src/Symfony/Component/Cache/Adapter/RedisAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static function createConnection($dsn, array $options = array())
7070
if (0 !== strpos($dsn, 'redis://')) {
7171
throw new InvalidArgumentException(sprintf('Invalid Redis DSN: %s does not start with "redis://"', $dsn));
7272
}
73-
$params = preg_replace_callback('#^redis://(?:([^@]*)@)?#', function ($m) use (&$auth) {
73+
$params = preg_replace_callback('#^redis://(?:(?:[^:@]*+:)?([^@]*+)@)?#', function ($m) use (&$auth) {
7474
if (isset($m[1])) {
7575
$auth = $m[1];
7676
}

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function testSilentHelp()
176176
}
177177

178178
/**
179-
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
179+
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
180180
* @expectedExceptionMessage The command "foofoo" does not exist.
181181
*/
182182
public function testGetInvalidCommand()
@@ -212,7 +212,7 @@ public function testFindNamespaceWithSubnamespaces()
212212
}
213213

214214
/**
215-
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
215+
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
216216
* @expectedExceptionMessage The namespace "f" is ambiguous (foo, foo1).
217217
*/
218218
public function testFindAmbiguousNamespace()
@@ -225,7 +225,7 @@ public function testFindAmbiguousNamespace()
225225
}
226226

227227
/**
228-
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
228+
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
229229
* @expectedExceptionMessage There are no commands defined in the "bar" namespace.
230230
*/
231231
public function testFindInvalidNamespace()
@@ -235,7 +235,7 @@ public function testFindInvalidNamespace()
235235
}
236236

237237
/**
238-
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
238+
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
239239
* @expectedExceptionMessage Command "foo1" is not defined
240240
*/
241241
public function testFindUniqueNameButNamespaceName()
@@ -313,7 +313,7 @@ public function testFindCommandWithMissingNamespace()
313313

314314
/**
315315
* @dataProvider provideInvalidCommandNamesSingle
316-
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
316+
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
317317
* @expectedExceptionMessage Did you mean this
318318
*/
319319
public function testFindAlternativeExceptionMessageSingle($name)
@@ -463,7 +463,7 @@ public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces()
463463
}
464464

465465
/**
466-
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
466+
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
467467
* @expectedExceptionMessage Command "foo::bar" is not defined.
468468
*/
469469
public function testFindWithDoubleColonInNameThrowsException()

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function testExecuteMethodNeedsToBeOverridden()
257257
}
258258

259259
/**
260-
* @expectedException Symfony\Component\Console\Exception\InvalidOptionException
260+
* @expectedException \Symfony\Component\Console\Exception\InvalidOptionException
261261
* @expectedExceptionMessage The "--bar" option does not exist.
262262
*/
263263
public function testRunWithInvalidOption()

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ public function testColumnWiths()
695695
}
696696

697697
/**
698-
* @expectedException Symfony\Component\Console\Exception\InvalidArgumentException
698+
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
699699
* @expectedExceptionMessage Style "absent" is not defined.
700700
*/
701701
public function testIsNotDefinedStyleException()

src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function testSetIsDeprecated()
159159

160160
/**
161161
* @dataProvider invalidDeprecationMessageProvider
162-
* @expectedException Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
162+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
163163
*/
164164
public function testSetDeprecatedWithInvalidDeprecationTemplate($message)
165165
{

src/Symfony/Component/Form/FormView.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,17 @@ public function __construct(FormView $parent = null)
6565
*/
6666
public function isRendered()
6767
{
68-
$hasChildren = 0 < count($this->children);
69-
70-
if (true === $this->rendered || !$hasChildren) {
68+
if (true === $this->rendered || 0 === count($this->children)) {
7169
return $this->rendered;
7270
}
7371

74-
if ($hasChildren) {
75-
foreach ($this->children as $child) {
76-
if (!$child->isRendered()) {
77-
return false;
78-
}
72+
foreach ($this->children as $child) {
73+
if (!$child->isRendered()) {
74+
return false;
7975
}
80-
81-
return $this->rendered = true;
8276
}
8377

84-
return false;
78+
return $this->rendered = true;
8579
}
8680

8781
/**

src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,90 +24,102 @@ class Collection implements CollectionInterface
2424
private $search;
2525
private $entries;
2626

27-
public function __construct(Connection $connection, Query $search, array $entries = array())
27+
public function __construct(Connection $connection, Query $search)
2828
{
2929
$this->connection = $connection;
3030
$this->search = $search;
31-
$this->entries = array();
3231
}
3332

3433
/**
3534
* {@inheritdoc}
3635
*/
3736
public function toArray()
3837
{
39-
$this->initialize();
38+
if (null === $this->entries) {
39+
$this->entries = iterator_to_array($this->getIterator(), false);
40+
}
4041

4142
return $this->entries;
4243
}
4344

4445
public function count()
4546
{
46-
$this->initialize();
47+
if (false !== $count = ldap_count_entries($this->connection->getResource(), $this->search->getResource())) {
48+
return $count;
49+
}
4750

48-
return count($this->entries);
51+
throw new LdapException(sprintf('Error while retrieving entry count: %s', ldap_error($this->connection->getResource())));
4952
}
5053

5154
public function getIterator()
5255
{
53-
return new ResultIterator($this->connection, $this->search);
56+
$con = $this->connection->getResource();
57+
$search = $this->search->getResource();
58+
$current = ldap_first_entry($con, $search);
59+
60+
if (0 === $this->count()) {
61+
return;
62+
}
63+
64+
if (false === $current) {
65+
throw new LdapException(sprintf('Could not rewind entries array: %s', ldap_error($con)));
66+
}
67+
68+
yield $this->getSingleEntry($con, $current);
69+
70+
while (false !== $current = ldap_next_entry($con, $current)) {
71+
yield $this->getSingleEntry($con, $current);
72+
}
5473
}
5574

5675
public function offsetExists($offset)
5776
{
58-
$this->initialize();
77+
$this->toArray();
5978

6079
return isset($this->entries[$offset]);
6180
}
6281

6382
public function offsetGet($offset)
6483
{
84+
$this->toArray();
85+
6586
return isset($this->entries[$offset]) ? $this->entries[$offset] : null;
6687
}
6788

6889
public function offsetSet($offset, $value)
6990
{
70-
$this->initialize();
91+
$this->toArray();
7192

7293
$this->entries[$offset] = $value;
7394
}
7495

7596
public function offsetUnset($offset)
7697
{
77-
$this->initialize();
98+
$this->toArray();
7899

79100
unset($this->entries[$offset]);
80101
}
81102

82-
private function initialize()
103+
private function getSingleEntry($con, $current)
83104
{
84-
if (null === $this->entries) {
85-
return;
86-
}
105+
$attributes = ldap_get_attributes($con, $current);
87106

88-
$con = $this->connection->getResource();
89-
90-
$entries = ldap_get_entries($con, $this->search->getResource());
91-
92-
if (false === $entries) {
93-
throw new LdapException(sprintf('Could not load entries: %s', ldap_error($con)));
107+
if (false === $attributes) {
108+
throw new LdapException(sprintf('Could not fetch attributes: %s', ldap_error($con)));
94109
}
95110

96-
if (0 === $entries['count']) {
97-
return array();
98-
}
111+
$attributes = $this->cleanupAttributes($attributes);
99112

100-
unset($entries['count']);
113+
$dn = ldap_get_dn($con, $current);
101114

102-
$this->entries = array_map(function (array $entry) {
103-
$dn = $entry['dn'];
104-
$attributes = $this->cleanupAttributes($entry);
115+
if (false === $dn) {
116+
throw new LdapException(sprintf('Could not fetch DN: %s', ldap_error($con)));
117+
}
105118

106-
return new Entry($dn, $attributes);
107-
}, $entries);
119+
return new Entry($dn, $attributes);
108120
}
109121

110-
private function cleanupAttributes(array $entry = array())
122+
private function cleanupAttributes(array $entry)
111123
{
112124
$attributes = array_diff_key($entry, array_flip(range(0, $entry['count'] - 1)) + array(
113125
'count' => null,

src/Symfony/Component/Ldap/Adapter/ExtLdap/ResultIterator.php

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)