Skip to content

Commit

Permalink
Added ArrayCollectionTest::testDerivedClassCreation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge authored and Paul committed Jul 13, 2016
1 parent ca5d358 commit 131df33
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"autoload": {
"psr-0": { "Doctrine\\Common\\Collections\\": "lib/" }
},
"autoload-dev": {
"psr-4": {
"Doctrine\\Tests\\": "tests/Doctrine/Tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/Doctrine/Tests/TestInit.php"
>
<testsuites>
<testsuite name="Doctrine Collections Test Suite">
Expand All @@ -22,7 +21,7 @@
<directory>./lib/Doctrine/</directory>
</whitelist>
</filter>

<groups>
<exclude>
<group>performance</group>
Expand Down
18 changes: 18 additions & 0 deletions tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Tests\DerivedArrayCollection;

/**
* Tests for {@see \Doctrine\Common\Collections\ArrayCollection}
Expand Down Expand Up @@ -315,4 +316,21 @@ public function testMultiColumnSortAppliesAllSorts()
->toArray()
);
}

/**
* Tests that methods that create a new instance can be called in a derived
* class that implements different constructor semantics.
*/
public function testDerivedClassCreation()
{
$collection = new DerivedArrayCollection(new \stdClass);
$closure = function () {
// Intentionally empty.
};

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));
}
}
21 changes: 21 additions & 0 deletions tests/Doctrine/Tests/DerivedArrayCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace Doctrine\Tests;

use Doctrine\Common\Collections\ArrayCollection;

final class DerivedArrayCollection extends ArrayCollection
{
private $foo;

public function __construct(\stdClass $foo, array $elements = array())
{
$this->foo = $foo;

parent::__construct($elements);
}

protected function createFrom(array $elements)
{
return new static($this->foo, $elements);
}
}
21 changes: 0 additions & 21 deletions tests/Doctrine/Tests/TestInit.php

This file was deleted.

0 comments on commit 131df33

Please sign in to comment.