Skip to content

Commit

Permalink
Applied changes, as requested
Browse files Browse the repository at this point in the history
Requests described in doctrine#98
usage of ::class where applicable
usage of short arrays
PHP 5.3, 5.4 is not supported anymore
  • Loading branch information
Alexander Golovnya committed Dec 6, 2016
1 parent 1b236bf commit 6e28615
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 54 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class ArrayCollectionTest extends BaseArrayCollectionTest
{
protected function buildCollection(array $elements = array())
protected function buildCollection(array $elements = [])
{
return new ArrayCollection($elements);
}
Expand Down
60 changes: 30 additions & 30 deletions tests/Doctrine/Tests/Common/Collections/BaseArrayCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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) {
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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()
);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Doctrine/Tests/Common/Collections/BaseCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions tests/Doctrine/Tests/Common/Collections/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ 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());
}

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());
Expand All @@ -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());
Expand Down

0 comments on commit 6e28615

Please sign in to comment.