From 131df33e3b6daca5b1b6a8109330ccebc5baa660 Mon Sep 17 00:00:00 2001 From: Bilge Date: Wed, 13 Jul 2016 15:46:32 +0100 Subject: [PATCH] Added ArrayCollectionTest::testDerivedClassCreation. --- composer.json | 5 +++++ phpunit.xml.dist | 3 +-- .../Collections/ArrayCollectionTest.php | 18 ++++++++++++++++ .../Doctrine/Tests/DerivedArrayCollection.php | 21 +++++++++++++++++++ tests/Doctrine/Tests/TestInit.php | 21 ------------------- 5 files changed, 45 insertions(+), 23 deletions(-) create mode 100644 tests/Doctrine/Tests/DerivedArrayCollection.php delete mode 100644 tests/Doctrine/Tests/TestInit.php diff --git a/composer.json b/composer.json index d8525e56f..bfcd27f24 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index db9c9bccf..3a93ce6a9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,6 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="./tests/Doctrine/Tests/TestInit.php" > @@ -22,7 +21,7 @@ ./lib/Doctrine/ - + performance diff --git a/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php b/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php index e935418bd..c8b9f63e4 100644 --- a/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php +++ b/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php @@ -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} @@ -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)); + } } diff --git a/tests/Doctrine/Tests/DerivedArrayCollection.php b/tests/Doctrine/Tests/DerivedArrayCollection.php new file mode 100644 index 000000000..f799ce4fa --- /dev/null +++ b/tests/Doctrine/Tests/DerivedArrayCollection.php @@ -0,0 +1,21 @@ +foo = $foo; + + parent::__construct($elements); + } + + protected function createFrom(array $elements) + { + return new static($this->foo, $elements); + } +} diff --git a/tests/Doctrine/Tests/TestInit.php b/tests/Doctrine/Tests/TestInit.php deleted file mode 100644 index 973b5fef6..000000000 --- a/tests/Doctrine/Tests/TestInit.php +++ /dev/null @@ -1,21 +0,0 @@ -