From 6e286158de78c4b5bfcbd33cd1642d0a1502f965 Mon Sep 17 00:00:00 2001 From: Alexander Golovnya Date: Tue, 6 Dec 2016 21:43:15 +0300 Subject: [PATCH] Applied changes, as requested Requests described in https://github.com/doctrine/collections/pull/98 usage of ::class where applicable usage of short arrays PHP 5.3, 5.4 is not supported anymore --- .travis.yml | 2 - .../AbstractLazyArrayCollectionTest.php | 4 +- .../Collections/ArrayCollectionTest.php | 2 +- .../Collections/BaseArrayCollectionTest.php | 60 +++++++++---------- .../Common/Collections/BaseCollectionTest.php | 14 ++--- .../Common/Collections/CollectionTest.php | 10 ++-- .../Collections/DerivedCollectionTest.php | 8 +-- .../Collections/ExpressionBuilderTest.php | 6 +- 8 files changed, 52 insertions(+), 54 deletions(-) diff --git a/.travis.yml b/.travis.yml index a86294bd2..5315ad81b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: php php: - - 5.3 - - 5.4 - 5.5 - 5.6 - 7.0 diff --git a/tests/Doctrine/Tests/Common/Collections/AbstractLazyArrayCollectionTest.php b/tests/Doctrine/Tests/Common/Collections/AbstractLazyArrayCollectionTest.php index 5bd1c383e..397771709 100644 --- a/tests/Doctrine/Tests/Common/Collections/AbstractLazyArrayCollectionTest.php +++ b/tests/Doctrine/Tests/Common/Collections/AbstractLazyArrayCollectionTest.php @@ -29,14 +29,14 @@ */ class AbstractLazyCollectionTest extends BaseArrayCollectionTest { - protected function buildCollection(array $elements = array()) + protected function buildCollection(array $elements = []) { return new LazyArrayCollection(new ArrayCollection($elements)); } public function testLazyCollection() { - $collection = $this->buildCollection(array('a', 'b', 'c')); + $collection = $this->buildCollection(['a', 'b', 'c']); $this->assertFalse($collection->isInitialized()); $this->assertCount(3, $collection); diff --git a/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php b/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php index fe2c3e7ba..75d479eee 100644 --- a/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php +++ b/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php @@ -28,7 +28,7 @@ */ class ArrayCollectionTest extends BaseArrayCollectionTest { - protected function buildCollection(array $elements = array()) + protected function buildCollection(array $elements = []) { return new ArrayCollection($elements); } diff --git a/tests/Doctrine/Tests/Common/Collections/BaseArrayCollectionTest.php b/tests/Doctrine/Tests/Common/Collections/BaseArrayCollectionTest.php index 58106d890..fb98155c6 100644 --- a/tests/Doctrine/Tests/Common/Collections/BaseArrayCollectionTest.php +++ b/tests/Doctrine/Tests/Common/Collections/BaseArrayCollectionTest.php @@ -24,7 +24,7 @@ abstract class BaseArrayCollectionTest extends \PHPUnit_Framework_TestCase { - abstract protected function buildCollection(array $elements = array()); + abstract protected function buildCollection(array $elements = []); protected function isSelectable($obj) { @@ -161,16 +161,16 @@ public function testIterator($elements) */ public function provideDifferentElements() { - return array( - 'indexed' => array(array(1, 2, 3, 4, 5)), - 'associative' => array(array('A' => 'a', 'B' => 'b', 'C' => 'c')), - 'mixed' => array(array('A' => 'a', 1, 'B' => 'b', 2, 3)), - ); + return [ + 'indexed' => [[1, 2, 3, 4, 5]], + 'associative' => [['A' => 'a', 'B' => 'b', 'C' => 'c']], + 'mixed' => [['A' => 'a', 1, 'B' => 'b', 2, 3]], + ]; } public function testRemove() { - $elements = array(1, 'A' => 'a', 2, 'B' => 'b', 3); + $elements = [1, 'A' => 'a', 2, 'B' => 'b', 3]; $collection = $this->buildCollection($elements); $this->assertEquals(1, $collection->remove(0)); @@ -190,7 +190,7 @@ public function testRemove() public function testRemoveElement() { - $elements = array(1, 'A' => 'a', 2, 'B' => 'b', 3, 'A2' => 'a', 'B2' => 'b'); + $elements = [1, 'A' => 'a', 2, 'B' => 'b', 3, 'A2' => 'a', 'B2' => 'b']; $collection = $this->buildCollection($elements); $this->assertTrue($collection->removeElement(1)); @@ -209,7 +209,7 @@ public function testRemoveElement() public function testContainsKey() { - $elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'B2' => 'b'); + $elements = [1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'B2' => 'b']; $collection = $this->buildCollection($elements); $this->assertTrue($collection->containsKey(0), 'Contains index 0'); @@ -229,7 +229,7 @@ public function testEmpty() public function testContains() { - $elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0); + $elements = [1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0]; $collection = $this->buildCollection($elements); $this->assertTrue($collection->contains(0), 'Contains Zero'); @@ -240,7 +240,7 @@ public function testContains() public function testExists() { - $elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0); + $elements = [1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0]; $collection = $this->buildCollection($elements); $this->assertTrue($collection->exists(function ($key, $element) { @@ -254,7 +254,7 @@ public function testExists() public function testIndexOf() { - $elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0); + $elements = [1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0]; $collection = $this->buildCollection($elements); $this->assertSame(array_search(2, $elements, true), $collection->indexOf(2), 'Index of 2'); @@ -264,7 +264,7 @@ public function testIndexOf() public function testGet() { - $elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0); + $elements = [1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0]; $collection = $this->buildCollection($elements); $this->assertSame(2, $collection->get(1), 'Get element by index'); @@ -280,39 +280,39 @@ public function testMatchingWithSortingPreservesyKeys() $object1->sortField = 2; $object2->sortField = 1; - $collection = $this->buildCollection(array( + $collection = $this->buildCollection([ 'object1' => $object1, 'object2' => $object2, - )); + ]); if (!$this->isSelectable($collection)) { $this->markTestSkipped('Collection does not support Selectable interface'); } $this->assertSame( - array( + [ 'object2' => $object2, 'object1' => $object1, - ), + ], $collection - ->matching(new Criteria(null, array('sortField' => Criteria::ASC))) + ->matching(new Criteria(null, ['sortField' => Criteria::ASC])) ->toArray() ); } public function testMultiColumnSortAppliesAllSorts() { - $collection = $this->buildCollection(array( - array('foo' => 1, 'bar' => 2), - array('foo' => 2, 'bar' => 4), - array('foo' => 2, 'bar' => 3) - )); - - $expected = array( - 1 => array('foo' => 2, 'bar' => 4), - 2 => array('foo' => 2, 'bar' => 3), - 0 => array('foo' => 1, 'bar' => 2) - ); + $collection = $this->buildCollection([ + ['foo' => 1, 'bar' => 2], + ['foo' => 2, 'bar' => 4], + ['foo' => 2, 'bar' => 3] + ]); + + $expected = [ + 1 => ['foo' => 2, 'bar' => 4], + 2 => ['foo' => 2, 'bar' => 3], + 0 => ['foo' => 1, 'bar' => 2] + ]; if (!$this->isSelectable($collection)) { $this->markTestSkipped('Collection does not support Selectable interface'); @@ -321,7 +321,7 @@ public function testMultiColumnSortAppliesAllSorts() $this->assertSame( $expected, $collection - ->matching(new Criteria(null, array('foo' => Criteria::DESC, 'bar' => Criteria::DESC))) + ->matching(new Criteria(null, ['foo' => Criteria::DESC, 'bar' => Criteria::DESC])) ->toArray() ); } diff --git a/tests/Doctrine/Tests/Common/Collections/BaseCollectionTest.php b/tests/Doctrine/Tests/Common/Collections/BaseCollectionTest.php index 21460c682..527e314e7 100644 --- a/tests/Doctrine/Tests/Common/Collections/BaseCollectionTest.php +++ b/tests/Doctrine/Tests/Common/Collections/BaseCollectionTest.php @@ -46,7 +46,7 @@ public function testMap() $res = $this->collection->map(function ($e) { return $e * 2; }); - $this->assertEquals(array(2, 4), $res->toArray()); + $this->assertEquals([2, 4], $res->toArray()); } public function testFilter() @@ -57,7 +57,7 @@ public function testFilter() $res = $this->collection->filter(function ($e) { return is_numeric($e); }); - $this->assertEquals(array(0 => 1, 2 => 3), $res->toArray()); + $this->assertEquals([0 => 1, 2 => 3], $res->toArray()); } public function testFirstAndLast() @@ -109,14 +109,14 @@ public function testGetKeys() { $this->collection[] = 'one'; $this->collection[] = 'two'; - $this->assertEquals(array(0, 1), $this->collection->getKeys()); + $this->assertEquals([0, 1], $this->collection->getKeys()); } public function testGetValues() { $this->collection[] = 'one'; $this->collection[] = 'two'; - $this->assertEquals(array('one', 'two'), $this->collection->getValues()); + $this->assertEquals(['one', 'two'], $this->collection->getValues()); } public function testCount() @@ -187,13 +187,13 @@ public function testSlice() $slice = $this->collection->slice(0, 1); $this->assertInternalType('array', $slice); - $this->assertEquals(array('one'), $slice); + $this->assertEquals(['one'], $slice); $slice = $this->collection->slice(1); - $this->assertEquals(array(1 => 'two', 2 => 'three'), $slice); + $this->assertEquals([1 => 'two', 2 => 'three'], $slice); $slice = $this->collection->slice(1, 1); - $this->assertEquals(array(1 => 'two'), $slice); + $this->assertEquals([1 => 'two'], $slice); } public function fillMatchingFixture() diff --git a/tests/Doctrine/Tests/Common/Collections/CollectionTest.php b/tests/Doctrine/Tests/Common/Collections/CollectionTest.php index b0c341393..65e17d960 100644 --- a/tests/Doctrine/Tests/Common/Collections/CollectionTest.php +++ b/tests/Doctrine/Tests/Common/Collections/CollectionTest.php @@ -26,8 +26,8 @@ public function testMatching() { $this->fillMatchingFixture(); - $col = $this->collection->matching(new Criteria(Criteria::expr()->eq("foo", "bar"))); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $col); + $col = $this->collection->matching(new Criteria(Criteria::expr()->eq('foo', 'bar'))); + $this->assertInstanceOf(Collection::class, $col); $this->assertNotSame($col, $this->collection); $this->assertEquals(1, count($col)); } @@ -39,9 +39,9 @@ public function testMatchingOrdering() { $this->fillMatchingFixture(); - $col = $this->collection->matching(new Criteria(null, array('foo' => 'DESC'))); + $col = $this->collection->matching(new Criteria(null, ['foo' => 'DESC'])); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $col); + $this->assertInstanceOf(Collection::class, $col); $this->assertNotSame($col, $this->collection); $this->assertEquals(2, count($col)); $this->assertEquals('baz', $col->first()->foo); @@ -57,7 +57,7 @@ public function testMatchingSlice() $col = $this->collection->matching(new Criteria(null, null, 1, 1)); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $col); + $this->assertInstanceOf(Collection::class, $col); $this->assertNotSame($col, $this->collection); $this->assertEquals(1, count($col)); $this->assertEquals('baz', $col[0]->foo); diff --git a/tests/Doctrine/Tests/Common/Collections/DerivedCollectionTest.php b/tests/Doctrine/Tests/Common/Collections/DerivedCollectionTest.php index 16dd914e8..e4054276e 100644 --- a/tests/Doctrine/Tests/Common/Collections/DerivedCollectionTest.php +++ b/tests/Doctrine/Tests/Common/Collections/DerivedCollectionTest.php @@ -37,9 +37,9 @@ public function testDerivedClassCreation() return $allMatches = false; }; - self::assertInstanceOf('Doctrine\Tests\DerivedArrayCollection', $collection->map($closure)); - self::assertInstanceOf('Doctrine\Tests\DerivedArrayCollection', $collection->filter($closure)); - self::assertContainsOnlyInstancesOf('Doctrine\Tests\DerivedArrayCollection', $collection->partition($closure)); - self::assertInstanceOf('Doctrine\Tests\DerivedArrayCollection', $collection->matching(new Criteria)); + self::assertInstanceOf(DerivedArrayCollection::class, $collection->map($closure)); + self::assertInstanceOf(DerivedArrayCollection::class, $collection->filter($closure)); + self::assertContainsOnlyInstancesOf(DerivedArrayCollection::class, $collection->partition($closure)); + self::assertInstanceOf(DerivedArrayCollection::class, $collection->matching(new Criteria())); } } diff --git a/tests/Doctrine/Tests/Common/Collections/ExpressionBuilderTest.php b/tests/Doctrine/Tests/Common/Collections/ExpressionBuilderTest.php index dbf1972b9..888338983 100644 --- a/tests/Doctrine/Tests/Common/Collections/ExpressionBuilderTest.php +++ b/tests/Doctrine/Tests/Common/Collections/ExpressionBuilderTest.php @@ -93,7 +93,7 @@ public function testLte() public function testIn() { - $expr = $this->builder->in("a", array("b")); + $expr = $this->builder->in("a", ["b"]); $this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr); $this->assertEquals(Comparison::IN, $expr->getOperator()); @@ -101,7 +101,7 @@ public function testIn() public function testNotIn() { - $expr = $this->builder->notIn("a", array("b")); + $expr = $this->builder->notIn("a", ["b"]); $this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr); $this->assertEquals(Comparison::NIN, $expr->getOperator()); @@ -125,7 +125,7 @@ public function testContains() public function testMemberOf() { - $expr = $this->builder->memberOf("b", array("a")); + $expr = $this->builder->memberOf("b", ["a"]); $this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr); $this->assertEquals(Comparison::MEMBER_OF, $expr->getOperator());