Skip to content

Commit 6587c42

Browse files
damienflamentdbu
authored andcommitted
Removed usage of the deprecated each function (#412)
* Removed usage of the deprecated `each` function Getting routes by key in the collection does not allow to check their ordering. Calling `next` on an iterator produce the same behavior as using the deprecated `each` function on an array. * Fixed style issues
1 parent 77a6ece commit 6587c42

File tree

10 files changed

+59
-26
lines changed

10 files changed

+59
-26
lines changed

src/Form/Type/RouteTypeType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
class RouteTypeType extends AbstractType
1919
{
2020
protected $routeTypes = [];
21+
2122
protected $translator;
2223

2324
/**

tests/Functional/Doctrine/Phpcr/RouteProviderTest.php

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,21 @@ public function testGetRouteCollectionForRequest()
6666
$this->assertCount(3, $routes);
6767
$this->assertContainsOnlyInstancesOf(RouteObjectInterface::class, $routes);
6868

69-
$routes = $routes->all();
70-
list($key, $child) = each($routes);
71-
$this->assertEquals(self::ROUTE_ROOT.'/testroute/noroute/child', $key);
72-
$this->assertEquals('json', $child->getDefault('_format'));
73-
list($key, $testroute) = each($routes);
74-
$this->assertEquals(self::ROUTE_ROOT.'/testroute', $key);
75-
$this->assertEquals('html', $testroute->getDefault('_format'));
76-
list($key, $root) = each($routes);
77-
$this->assertEquals(self::ROUTE_ROOT, $key);
78-
$this->assertNull($root->getDefault('_format'));
69+
$iterator = $routes->getIterator();
70+
71+
$this->assertTrue($iterator->valid());
72+
$this->assertEquals(self::ROUTE_ROOT.'/testroute/noroute/child', $iterator->key());
73+
$this->assertEquals('json', $iterator->current()->getDefault('_format'));
74+
75+
$iterator->next();
76+
$this->assertTrue($iterator->valid());
77+
$this->assertEquals(self::ROUTE_ROOT.'/testroute', $iterator->key());
78+
$this->assertEquals('html', $iterator->current()->getDefault('_format'));
79+
80+
$iterator->next();
81+
$this->assertTrue($iterator->valid());
82+
$this->assertEquals(self::ROUTE_ROOT, $iterator->key());
83+
$this->assertNull($iterator->current()->getDefault('_format'));
7984
}
8085

8186
public function testGetRouteCollectionForRequestFormat()
@@ -86,29 +91,36 @@ public function testGetRouteCollectionForRequestFormat()
8691
$this->assertCount(3, $routes);
8792
$this->assertContainsOnlyInstancesOf(RouteObjectInterface::class, $routes);
8893

89-
$routes = $routes->all();
90-
list($key, $child) = each($routes);
91-
$this->assertEquals(self::ROUTE_ROOT.'/testroute/noroute/child', $key);
92-
$this->assertEquals('json', $child->getDefault('_format'));
93-
list($key, $testroute) = each($routes);
94-
$this->assertEquals(self::ROUTE_ROOT.'/testroute', $key);
95-
$this->assertEquals('html', $testroute->getDefault('_format'));
96-
list($key, $root) = each($routes);
97-
$this->assertEquals(self::ROUTE_ROOT, $key);
98-
$this->assertNull($root->getDefault('_format'));
94+
$iterator = $routes->getIterator();
95+
96+
$this->assertTrue($iterator->valid());
97+
$this->assertEquals(self::ROUTE_ROOT.'/testroute/noroute/child', $iterator->key());
98+
$this->assertEquals('json', $iterator->current()->getDefault('_format'));
99+
100+
$iterator->next();
101+
$this->assertTrue($iterator->valid());
102+
$this->assertEquals(self::ROUTE_ROOT.'/testroute', $iterator->key());
103+
$this->assertEquals('html', $iterator->current()->getDefault('_format'));
104+
105+
$iterator->next();
106+
$this->assertTrue($iterator->valid());
107+
$this->assertEquals(self::ROUTE_ROOT, $iterator->key());
108+
$this->assertNull($iterator->current()->getDefault('_format'));
99109
}
100110

101111
/**
102112
* The root route will always be found.
103113
*/
104114
public function testGetRouteCollectionForRequestNonPhpcrUrl()
105115
{
106-
$collection = $this->repository->getRouteCollectionForRequest(Request::create('http:///'));
107-
$this->assertInstanceOf(RouteCollection::class, $collection);
108-
$this->assertCount(1, $collection);
109-
$routes = $collection->all();
110-
list($key, $route) = each($routes);
111-
$this->assertEquals(self::ROUTE_ROOT, $key);
116+
$routes = $this->repository->getRouteCollectionForRequest(Request::create('http:///'));
117+
$this->assertInstanceOf(RouteCollection::class, $routes);
118+
$this->assertCount(1, $routes);
119+
120+
$iterator = $routes->getIterator();
121+
122+
$this->assertTrue($iterator->valid());
123+
$this->assertEquals(self::ROUTE_ROOT, $iterator->key());
112124
}
113125

114126
/**

tests/Functional/Routing/DynamicRouterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class DynamicRouterTest extends BaseTestCase
3333
* @var ChainRouter
3434
*/
3535
protected $router;
36+
3637
protected $routeNamePrefix;
3738

3839
const ROUTE_ROOT = '/test/routing';

tests/Unit/DependencyInjection/XmlSchemaTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class XmlSchemaTest extends XmlSchemaTestCase
1717
{
1818
protected $fixturesPath;
19+
1920
protected $schemaPath;
2021

2122
public function setUp()

tests/Unit/Doctrine/Orm/ContentRepositoryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
class ContentRepositoryTest extends \PHPUnit_Framework_TestCase
2020
{
2121
private $document;
22+
2223
private $managerRegistry;
24+
2325
private $objectManager;
26+
2427
private $objectRepository;
2528

2629
public function setUp()

tests/Unit/Doctrine/Phpcr/ContentRepositoryTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
class ContentRepositoryTest extends \PHPUnit_Framework_TestCase
2121
{
2222
private $document;
23+
2324
private $document2;
25+
2426
private $objectManager;
27+
2528
private $objectManager2;
29+
2630
private $managerRegistry;
2731

2832
public function setUp()

tests/Unit/Doctrine/Phpcr/RouteProviderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class RouteProviderTest extends \PHPUnit_Framework_TestCase
4141
* @var DocumentManager|\PHPUnit_Framework_MockObject_MockObject
4242
*/
4343
protected $dmMock;
44+
4445
/**
4546
* @var DocumentManager|\PHPUnit_Framework_MockObject_MockObject
4647
*/
@@ -50,6 +51,7 @@ class RouteProviderTest extends \PHPUnit_Framework_TestCase
5051
* @var Route|\PHPUnit_Framework_MockObject_MockObject
5152
*/
5253
protected $routeMock;
54+
5355
/**
5456
* @var Route|\PHPUnit_Framework_MockObject_MockObject
5557
*/

tests/Unit/Doctrine/Phpcr/RouteTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class RouteTest extends \PHPUnit_Framework_TestCase
1717
{
1818
/** @var Route */
1919
private $route;
20+
2021
private $childRoute1;
2122

2223
public function setUp()

tests/Unit/Routing/DynamicRouterTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,25 @@
2626
class DynamicRouterTest extends \PHPUnit_Framework_TestCase
2727
{
2828
protected $matcher;
29+
2930
protected $generator;
31+
3032
/** @var DynamicRouter */
3133
protected $router;
34+
3235
protected $context;
36+
3337
/** @var Request */
3438
protected $request;
39+
3540
/**
3641
* @var RequestStack
3742
*/
3843
private $requestStack;
44+
3945
/** @var EventDispatcherInterface */
4046
protected $eventDispatcher;
47+
4148
protected $container;
4249

4350
public function setUp()

tests/Unit/Validator/Constraints/RouteDefaultsValidatorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ abstract class HackBaseClass extends ConstraintValidatorTestCase
3131
abstract class RouteDefaultsValidatorTest extends HackBaseClass
3232
{
3333
protected $controllerResolver;
34+
3435
protected $engine;
3536

3637
public function testCorrectControllerPath()

0 commit comments

Comments
 (0)