Update to drupal-org-drupal 8.0.0-rc2. For more information, see https://www.drupal.org/node/2598668
This commit is contained in:
parent
f32e58e4b1
commit
8e18df8c36
3062 changed files with 15044 additions and 172506 deletions
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Collections;
|
||||
|
||||
use Doctrine\Tests\LazyArrayCollection;
|
||||
|
||||
class AbstractLazyCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testLazyCollection()
|
||||
{
|
||||
$collection = new LazyArrayCollection();
|
||||
|
||||
$this->assertFalse($collection->isInitialized());
|
||||
$this->assertCount(3, $collection);
|
||||
|
||||
$collection->add('bar');
|
||||
$this->assertTrue($collection->isInitialized());
|
||||
$this->assertCount(4, $collection);
|
||||
}
|
||||
}
|
|
@ -1,296 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\Common\Collections;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
|
||||
/**
|
||||
* Tests for {@see \Doctrine\Common\Collections\ArrayCollection}
|
||||
*
|
||||
* @covers \Doctrine\Common\Collections\ArrayCollection
|
||||
*/
|
||||
class ArrayCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testToArray($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertSame($elements, $collection->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testFirst($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
$this->assertSame(reset($elements), $collection->first());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testLast($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
$this->assertSame(end($elements), $collection->last());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testKey($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertSame(key($elements), $collection->key());
|
||||
|
||||
next($elements);
|
||||
$collection->next();
|
||||
|
||||
$this->assertSame(key($elements), $collection->key());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testNext($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
while (true) {
|
||||
$collectionNext = $collection->next();
|
||||
$arrayNext = next($elements);
|
||||
|
||||
if(!$collectionNext || !$arrayNext) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->assertSame($arrayNext, $collectionNext, "Returned value of ArrayCollection::next() and next() not match");
|
||||
$this->assertSame(key($elements), $collection->key(), "Keys not match");
|
||||
$this->assertSame(current($elements), $collection->current(), "Current values not match");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testCurrent($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertSame(current($elements), $collection->current());
|
||||
|
||||
next($elements);
|
||||
$collection->next();
|
||||
|
||||
$this->assertSame(current($elements), $collection->current());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testGetKeys($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertSame(array_keys($elements), $collection->getKeys());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testGetValues($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertSame(array_values($elements), $collection->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testCount($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertSame(count($elements), $collection->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDifferentElements
|
||||
*/
|
||||
public function testIterator($elements)
|
||||
{
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$iterations = 0;
|
||||
foreach($collection->getIterator() as $key => $item) {
|
||||
$this->assertSame($elements[$key], $item, "Item {$key} not match");
|
||||
$iterations++;
|
||||
}
|
||||
|
||||
$this->assertEquals(count($elements), $iterations, "Number of iterations not match");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
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)),
|
||||
);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$elements = array(1, 'A' => 'a', 2, 'B' => 'b', 3);
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertEquals(1, $collection->remove(0));
|
||||
unset($elements[0]);
|
||||
|
||||
$this->assertEquals(null, $collection->remove('non-existent'));
|
||||
unset($elements['non-existent']);
|
||||
|
||||
$this->assertEquals(2, $collection->remove(1));
|
||||
unset($elements[1]);
|
||||
|
||||
$this->assertEquals('a', $collection->remove('A'));
|
||||
unset($elements['A']);
|
||||
|
||||
$this->assertEquals($elements, $collection->toArray());
|
||||
}
|
||||
|
||||
public function testRemoveElement()
|
||||
{
|
||||
$elements = array(1, 'A' => 'a', 2, 'B' => 'b', 3, 'A2' => 'a', 'B2' => 'b');
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertTrue($collection->removeElement(1));
|
||||
unset($elements[0]);
|
||||
|
||||
$this->assertFalse($collection->removeElement('non-existent'));
|
||||
|
||||
$this->assertTrue($collection->removeElement('a'));
|
||||
unset($elements['A']);
|
||||
|
||||
$this->assertTrue($collection->removeElement('a'));
|
||||
unset($elements['A2']);
|
||||
|
||||
$this->assertEquals($elements, $collection->toArray());
|
||||
}
|
||||
|
||||
public function testContainsKey()
|
||||
{
|
||||
$elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'B2' => 'b');
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertTrue($collection->containsKey(0), "Contains index 0");
|
||||
$this->assertTrue($collection->containsKey('A'), "Contains key \"A\"");
|
||||
$this->assertTrue($collection->containsKey('null'), "Contains key \"null\", with value null");
|
||||
$this->assertFalse($collection->containsKey('non-existent'), "Doesn't contain key");
|
||||
}
|
||||
|
||||
public function testEmpty()
|
||||
{
|
||||
$collection = new ArrayCollection();
|
||||
$this->assertTrue($collection->isEmpty(), "Empty collection");
|
||||
|
||||
$collection->add(1);
|
||||
$this->assertFalse($collection->isEmpty(), "Not empty collection");
|
||||
}
|
||||
|
||||
public function testContains()
|
||||
{
|
||||
$elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0);
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertTrue($collection->contains(0), "Contains Zero");
|
||||
$this->assertTrue($collection->contains('a'), "Contains \"a\"");
|
||||
$this->assertTrue($collection->contains(null), "Contains Null");
|
||||
$this->assertFalse($collection->contains('non-existent'), "Doesn't contain an element");
|
||||
}
|
||||
|
||||
public function testExists()
|
||||
{
|
||||
$elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0);
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertTrue($collection->exists(function($key, $element) {
|
||||
return $key == 'A' && $element == 'a';
|
||||
}), "Element exists");
|
||||
|
||||
$this->assertFalse($collection->exists(function($key, $element) {
|
||||
return $key == 'non-existent' && $element == 'non-existent';
|
||||
}), "Element not exists");
|
||||
}
|
||||
|
||||
public function testIndexOf()
|
||||
{
|
||||
$elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0);
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertSame(array_search(2, $elements, true), $collection->indexOf(2), 'Index of 2');
|
||||
$this->assertSame(array_search(null, $elements, true), $collection->indexOf(null), 'Index of null');
|
||||
$this->assertSame(array_search('non-existent', $elements, true), $collection->indexOf('non-existent'), 'Index of non existent');
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0);
|
||||
$collection = new ArrayCollection($elements);
|
||||
|
||||
$this->assertSame(2, $collection->get(1), 'Get element by index');
|
||||
$this->assertSame('a', $collection->get('A'), 'Get element by name');
|
||||
$this->assertSame(null, $collection->get('non-existent'), 'Get non existent element');
|
||||
}
|
||||
|
||||
public function testMatchingWithSortingPreservesyKeys()
|
||||
{
|
||||
$object1 = new \stdClass();
|
||||
$object2 = new \stdClass();
|
||||
|
||||
$object1->sortField = 2;
|
||||
$object2->sortField = 1;
|
||||
|
||||
$collection = new ArrayCollection(array(
|
||||
'object1' => $object1,
|
||||
'object2' => $object2,
|
||||
));
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'object2' => $object2,
|
||||
'object1' => $object1,
|
||||
),
|
||||
$collection
|
||||
->matching(new Criteria(null, array('sortField' => Criteria::ASC)))
|
||||
->toArray()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,250 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\Common\Collections;
|
||||
|
||||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
|
||||
use Doctrine\Common\Collections\ExpressionBuilder;
|
||||
|
||||
/**
|
||||
* @group DDC-1637
|
||||
*/
|
||||
class ClosureExpressionVisitorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ClosureExpressionVisitor
|
||||
*/
|
||||
private $visitor;
|
||||
|
||||
/**
|
||||
* @var ExpressionBuilder
|
||||
*/
|
||||
private $builder;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->visitor = new ClosureExpressionVisitor();
|
||||
$this->builder = new ExpressionBuilder();
|
||||
}
|
||||
|
||||
public function testGetObjectFieldValueIsAccessor()
|
||||
{
|
||||
$object = new TestObject(1, 2, true);
|
||||
|
||||
$this->assertTrue($this->visitor->getObjectFieldValue($object, 'baz'));
|
||||
}
|
||||
|
||||
public function testGetObjectFieldValueMagicCallMethod()
|
||||
{
|
||||
$object = new TestObject(1, 2, true, 3);
|
||||
|
||||
$this->assertEquals(3, $this->visitor->getObjectFieldValue($object, 'qux'));
|
||||
}
|
||||
|
||||
public function testWalkEqualsComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->eq("foo", 1));
|
||||
|
||||
$this->assertTrue($closure(new TestObject(1)));
|
||||
$this->assertFalse($closure(new TestObject(2)));
|
||||
}
|
||||
|
||||
public function testWalkNotEqualsComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->neq("foo", 1));
|
||||
|
||||
$this->assertFalse($closure(new TestObject(1)));
|
||||
$this->assertTrue($closure(new TestObject(2)));
|
||||
}
|
||||
|
||||
public function testWalkLessThanComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->lt("foo", 1));
|
||||
|
||||
$this->assertFalse($closure(new TestObject(1)));
|
||||
$this->assertTrue($closure(new TestObject(0)));
|
||||
}
|
||||
|
||||
public function testWalkLessThanEqualsComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->lte("foo", 1));
|
||||
|
||||
$this->assertFalse($closure(new TestObject(2)));
|
||||
$this->assertTrue($closure(new TestObject(1)));
|
||||
$this->assertTrue($closure(new TestObject(0)));
|
||||
}
|
||||
|
||||
public function testWalkGreaterThanEqualsComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->gte("foo", 1));
|
||||
|
||||
$this->assertTrue($closure(new TestObject(2)));
|
||||
$this->assertTrue($closure(new TestObject(1)));
|
||||
$this->assertFalse($closure(new TestObject(0)));
|
||||
}
|
||||
|
||||
public function testWalkGreaterThanComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->gt("foo", 1));
|
||||
|
||||
$this->assertTrue($closure(new TestObject(2)));
|
||||
$this->assertFalse($closure(new TestObject(1)));
|
||||
$this->assertFalse($closure(new TestObject(0)));
|
||||
}
|
||||
|
||||
public function testWalkInComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->in("foo", array(1, 2, 3)));
|
||||
|
||||
$this->assertTrue($closure(new TestObject(2)));
|
||||
$this->assertTrue($closure(new TestObject(1)));
|
||||
$this->assertFalse($closure(new TestObject(0)));
|
||||
}
|
||||
|
||||
public function testWalkNotInComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->notIn("foo", array(1, 2, 3)));
|
||||
|
||||
$this->assertFalse($closure(new TestObject(1)));
|
||||
$this->assertFalse($closure(new TestObject(2)));
|
||||
$this->assertTrue($closure(new TestObject(0)));
|
||||
$this->assertTrue($closure(new TestObject(4)));
|
||||
}
|
||||
|
||||
public function testWalkContainsComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->contains('foo', 'hello'));
|
||||
|
||||
$this->assertTrue($closure(new TestObject('hello world')));
|
||||
$this->assertFalse($closure(new TestObject('world')));
|
||||
}
|
||||
|
||||
public function testWalkAndCompositeExpression()
|
||||
{
|
||||
$closure = $this->visitor->walkCompositeExpression(
|
||||
$this->builder->andX(
|
||||
$this->builder->eq("foo", 1),
|
||||
$this->builder->eq("bar", 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue($closure(new TestObject(1, 1)));
|
||||
$this->assertFalse($closure(new TestObject(1, 0)));
|
||||
$this->assertFalse($closure(new TestObject(0, 1)));
|
||||
$this->assertFalse($closure(new TestObject(0, 0)));
|
||||
}
|
||||
|
||||
public function testWalkOrCompositeExpression()
|
||||
{
|
||||
$closure = $this->visitor->walkCompositeExpression(
|
||||
$this->builder->orX(
|
||||
$this->builder->eq("foo", 1),
|
||||
$this->builder->eq("bar", 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue($closure(new TestObject(1, 1)));
|
||||
$this->assertTrue($closure(new TestObject(1, 0)));
|
||||
$this->assertTrue($closure(new TestObject(0, 1)));
|
||||
$this->assertFalse($closure(new TestObject(0, 0)));
|
||||
}
|
||||
|
||||
public function testSortByFieldAscending()
|
||||
{
|
||||
$objects = array(new TestObject("b"), new TestObject("a"), new TestObject("c"));
|
||||
$sort = ClosureExpressionVisitor::sortByField("foo");
|
||||
|
||||
usort($objects, $sort);
|
||||
|
||||
$this->assertEquals("a", $objects[0]->getFoo());
|
||||
$this->assertEquals("b", $objects[1]->getFoo());
|
||||
$this->assertEquals("c", $objects[2]->getFoo());
|
||||
}
|
||||
|
||||
public function testSortByFieldDescending()
|
||||
{
|
||||
$objects = array(new TestObject("b"), new TestObject("a"), new TestObject("c"));
|
||||
$sort = ClosureExpressionVisitor::sortByField("foo", -1);
|
||||
|
||||
usort($objects, $sort);
|
||||
|
||||
$this->assertEquals("c", $objects[0]->getFoo());
|
||||
$this->assertEquals("b", $objects[1]->getFoo());
|
||||
$this->assertEquals("a", $objects[2]->getFoo());
|
||||
}
|
||||
|
||||
public function testSortDelegate()
|
||||
{
|
||||
$objects = array(new TestObject("a", "c"), new TestObject("a", "b"), new TestObject("a", "a"));
|
||||
$sort = ClosureExpressionVisitor::sortByField("bar", 1);
|
||||
$sort = ClosureExpressionVisitor::sortByField("foo", 1, $sort);
|
||||
|
||||
usort($objects, $sort);
|
||||
|
||||
$this->assertEquals("a", $objects[0]->getBar());
|
||||
$this->assertEquals("b", $objects[1]->getBar());
|
||||
$this->assertEquals("c", $objects[2]->getBar());
|
||||
}
|
||||
|
||||
public function testArrayComparison()
|
||||
{
|
||||
$closure = $this->visitor->walkComparison($this->builder->eq("foo", 42));
|
||||
|
||||
$this->assertTrue($closure(array('foo' => 42)));
|
||||
}
|
||||
}
|
||||
|
||||
class TestObject
|
||||
{
|
||||
private $foo;
|
||||
private $bar;
|
||||
private $baz;
|
||||
private $qux;
|
||||
|
||||
public function __construct($foo = null, $bar = null, $baz = null, $qux = null)
|
||||
{
|
||||
$this->foo = $foo;
|
||||
$this->bar = $bar;
|
||||
$this->baz = $baz;
|
||||
$this->qux = $qux;
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if ('getqux' === $name) {
|
||||
return $this->qux;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFoo()
|
||||
{
|
||||
return $this->foo;
|
||||
}
|
||||
|
||||
public function getBar()
|
||||
{
|
||||
return $this->bar;
|
||||
}
|
||||
|
||||
public function isBaz()
|
||||
{
|
||||
return $this->baz;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,265 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Collections;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
|
||||
class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->collection = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function testIssetAndUnset()
|
||||
{
|
||||
$this->assertFalse(isset($this->collection[0]));
|
||||
$this->collection->add('testing');
|
||||
$this->assertTrue(isset($this->collection[0]));
|
||||
unset($this->collection[0]);
|
||||
$this->assertFalse(isset($this->collection[0]));
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->collection->add('testing');
|
||||
$this->assertTrue(is_string((string) $this->collection));
|
||||
}
|
||||
|
||||
public function testRemovingNonExistentEntryReturnsNull()
|
||||
{
|
||||
$this->assertEquals(null, $this->collection->remove('testing_does_not_exist'));
|
||||
}
|
||||
|
||||
public function testExists()
|
||||
{
|
||||
$this->collection->add("one");
|
||||
$this->collection->add("two");
|
||||
$exists = $this->collection->exists(function($k, $e) { return $e == "one"; });
|
||||
$this->assertTrue($exists);
|
||||
$exists = $this->collection->exists(function($k, $e) { return $e == "other"; });
|
||||
$this->assertFalse($exists);
|
||||
}
|
||||
|
||||
public function testMap()
|
||||
{
|
||||
$this->collection->add(1);
|
||||
$this->collection->add(2);
|
||||
$res = $this->collection->map(function($e) { return $e * 2; });
|
||||
$this->assertEquals(array(2, 4), $res->toArray());
|
||||
}
|
||||
|
||||
public function testFilter()
|
||||
{
|
||||
$this->collection->add(1);
|
||||
$this->collection->add("foo");
|
||||
$this->collection->add(3);
|
||||
$res = $this->collection->filter(function($e) { return is_numeric($e); });
|
||||
$this->assertEquals(array(0 => 1, 2 => 3), $res->toArray());
|
||||
}
|
||||
|
||||
public function testFirstAndLast()
|
||||
{
|
||||
$this->collection->add('one');
|
||||
$this->collection->add('two');
|
||||
|
||||
$this->assertEquals($this->collection->first(), 'one');
|
||||
$this->assertEquals($this->collection->last(), 'two');
|
||||
}
|
||||
|
||||
public function testArrayAccess()
|
||||
{
|
||||
$this->collection[] = 'one';
|
||||
$this->collection[] = 'two';
|
||||
|
||||
$this->assertEquals($this->collection[0], 'one');
|
||||
$this->assertEquals($this->collection[1], 'two');
|
||||
|
||||
unset($this->collection[0]);
|
||||
$this->assertEquals($this->collection->count(), 1);
|
||||
}
|
||||
|
||||
public function testContainsKey()
|
||||
{
|
||||
$this->collection[5] = 'five';
|
||||
$this->assertTrue($this->collection->containsKey(5));
|
||||
}
|
||||
|
||||
public function testContains()
|
||||
{
|
||||
$this->collection[0] = 'test';
|
||||
$this->assertTrue($this->collection->contains('test'));
|
||||
}
|
||||
|
||||
public function testSearch()
|
||||
{
|
||||
$this->collection[0] = 'test';
|
||||
$this->assertEquals(0, $this->collection->indexOf('test'));
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->collection[0] = 'test';
|
||||
$this->assertEquals('test', $this->collection->get(0));
|
||||
}
|
||||
|
||||
public function testGetKeys()
|
||||
{
|
||||
$this->collection[] = 'one';
|
||||
$this->collection[] = 'two';
|
||||
$this->assertEquals(array(0, 1), $this->collection->getKeys());
|
||||
}
|
||||
|
||||
public function testGetValues()
|
||||
{
|
||||
$this->collection[] = 'one';
|
||||
$this->collection[] = 'two';
|
||||
$this->assertEquals(array('one', 'two'), $this->collection->getValues());
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$this->collection[] = 'one';
|
||||
$this->collection[] = 'two';
|
||||
$this->assertEquals($this->collection->count(), 2);
|
||||
$this->assertEquals(count($this->collection), 2);
|
||||
}
|
||||
|
||||
public function testForAll()
|
||||
{
|
||||
$this->collection[] = 'one';
|
||||
$this->collection[] = 'two';
|
||||
$this->assertEquals($this->collection->forAll(function($k, $e) { return is_string($e); }), true);
|
||||
$this->assertEquals($this->collection->forAll(function($k, $e) { return is_array($e); }), false);
|
||||
}
|
||||
|
||||
public function testPartition()
|
||||
{
|
||||
$this->collection[] = true;
|
||||
$this->collection[] = false;
|
||||
$partition = $this->collection->partition(function($k, $e) { return $e == true; });
|
||||
$this->assertEquals($partition[0][0], true);
|
||||
$this->assertEquals($partition[1][0], false);
|
||||
}
|
||||
|
||||
public function testClear()
|
||||
{
|
||||
$this->collection[] = 'one';
|
||||
$this->collection[] = 'two';
|
||||
$this->collection->clear();
|
||||
$this->assertEquals($this->collection->isEmpty(), true);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$this->collection[] = 'one';
|
||||
$this->collection[] = 'two';
|
||||
$el = $this->collection->remove(0);
|
||||
|
||||
$this->assertEquals('one', $el);
|
||||
$this->assertEquals($this->collection->contains('one'), false);
|
||||
$this->assertNull($this->collection->remove(0));
|
||||
}
|
||||
|
||||
public function testRemoveElement()
|
||||
{
|
||||
$this->collection[] = 'one';
|
||||
$this->collection[] = 'two';
|
||||
|
||||
$this->assertTrue($this->collection->removeElement('two'));
|
||||
$this->assertFalse($this->collection->contains('two'));
|
||||
$this->assertFalse($this->collection->removeElement('two'));
|
||||
}
|
||||
|
||||
public function testSlice()
|
||||
{
|
||||
$this->collection[] = 'one';
|
||||
$this->collection[] = 'two';
|
||||
$this->collection[] = 'three';
|
||||
|
||||
$slice = $this->collection->slice(0, 1);
|
||||
$this->assertInternalType('array', $slice);
|
||||
$this->assertEquals(array('one'), $slice);
|
||||
|
||||
$slice = $this->collection->slice(1);
|
||||
$this->assertEquals(array(1 => 'two', 2 => 'three'), $slice);
|
||||
|
||||
$slice = $this->collection->slice(1, 1);
|
||||
$this->assertEquals(array(1 => 'two'), $slice);
|
||||
}
|
||||
|
||||
public function fillMatchingFixture()
|
||||
{
|
||||
$std1 = new \stdClass();
|
||||
$std1->foo = "bar";
|
||||
$this->collection[] = $std1;
|
||||
|
||||
$std2 = new \stdClass();
|
||||
$std2->foo = "baz";
|
||||
$this->collection[] = $std2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1637
|
||||
*/
|
||||
public function testMatching()
|
||||
{
|
||||
$this->fillMatchingFixture();
|
||||
|
||||
$col = $this->collection->matching(new Criteria(Criteria::expr()->eq("foo", "bar")));
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $col);
|
||||
$this->assertNotSame($col, $this->collection);
|
||||
$this->assertEquals(1, count($col));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1637
|
||||
*/
|
||||
public function testMatchingOrdering()
|
||||
{
|
||||
$this->fillMatchingFixture();
|
||||
|
||||
$col = $this->collection->matching(new Criteria(null, array('foo' => 'DESC')));
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $col);
|
||||
$this->assertNotSame($col, $this->collection);
|
||||
$this->assertEquals(2, count($col));
|
||||
$this->assertEquals('baz', $col->first()->foo);
|
||||
$this->assertEquals('bar', $col->last()->foo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1637
|
||||
*/
|
||||
public function testMatchingSlice()
|
||||
{
|
||||
$this->fillMatchingFixture();
|
||||
|
||||
$col = $this->collection->matching(new Criteria(null, null, 1, 1));
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $col);
|
||||
$this->assertNotSame($col, $this->collection);
|
||||
$this->assertEquals(1, count($col));
|
||||
$this->assertEquals('baz', $col[0]->foo);
|
||||
}
|
||||
|
||||
public function testCanRemoveNullValuesByKey()
|
||||
{
|
||||
$this->collection->add(null);
|
||||
$this->collection->remove(0);
|
||||
$this->assertTrue($this->collection->isEmpty());
|
||||
}
|
||||
|
||||
public function testCanVerifyExistingKeysWithNullValues()
|
||||
{
|
||||
$this->collection->set('key', null);
|
||||
$this->assertTrue($this->collection->containsKey('key'));
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Collections;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use Doctrine\Common\Collections\Expr\CompositeExpression;
|
||||
|
||||
class CriteriaTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$criteria = Criteria::create();
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Criteria', $criteria);
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$expr = new Comparison("field", "=", "value");
|
||||
$criteria = new Criteria($expr, array("foo" => "ASC"), 10, 20);
|
||||
|
||||
$this->assertSame($expr, $criteria->getWhereExpression());
|
||||
$this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
|
||||
$this->assertEquals(10, $criteria->getFirstResult());
|
||||
$this->assertEquals(20, $criteria->getMaxResults());
|
||||
}
|
||||
|
||||
public function testWhere()
|
||||
{
|
||||
$expr = new Comparison("field", "=", "value");
|
||||
$criteria = new Criteria();
|
||||
|
||||
$criteria->where($expr);
|
||||
|
||||
$this->assertSame($expr, $criteria->getWhereExpression());
|
||||
}
|
||||
|
||||
public function testAndWhere()
|
||||
{
|
||||
$expr = new Comparison("field", "=", "value");
|
||||
$criteria = new Criteria();
|
||||
|
||||
$criteria->where($expr);
|
||||
$expr = $criteria->getWhereExpression();
|
||||
$criteria->andWhere($expr);
|
||||
|
||||
$where = $criteria->getWhereExpression();
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
|
||||
|
||||
$this->assertEquals(CompositeExpression::TYPE_AND, $where->getType());
|
||||
$this->assertSame(array($expr, $expr), $where->getExpressionList());
|
||||
}
|
||||
|
||||
public function testOrWhere()
|
||||
{
|
||||
$expr = new Comparison("field", "=", "value");
|
||||
$criteria = new Criteria();
|
||||
|
||||
$criteria->where($expr);
|
||||
$expr = $criteria->getWhereExpression();
|
||||
$criteria->orWhere($expr);
|
||||
|
||||
$where = $criteria->getWhereExpression();
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where);
|
||||
|
||||
$this->assertEquals(CompositeExpression::TYPE_OR, $where->getType());
|
||||
$this->assertSame(array($expr, $expr), $where->getExpressionList());
|
||||
}
|
||||
|
||||
public function testOrderings()
|
||||
{
|
||||
$criteria = Criteria::create()
|
||||
->orderBy(array("foo" => "ASC"));
|
||||
|
||||
$this->assertEquals(array("foo" => "ASC"), $criteria->getOrderings());
|
||||
}
|
||||
|
||||
public function testExpr()
|
||||
{
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\ExpressionBuilder', Criteria::expr());
|
||||
}
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Collections;
|
||||
|
||||
use Doctrine\Common\Collections\ExpressionBuilder;
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use Doctrine\Common\Collections\Expr\CompositeExpression;
|
||||
|
||||
/**
|
||||
* @group DDC-1637
|
||||
*/
|
||||
class ExpressionBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ExpressionBuilder
|
||||
*/
|
||||
private $builder;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->builder = new ExpressionBuilder();
|
||||
}
|
||||
|
||||
public function testAndX()
|
||||
{
|
||||
$expr = $this->builder->andX($this->builder->eq("a", "b"));
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $expr);
|
||||
$this->assertEquals(CompositeExpression::TYPE_AND, $expr->getType());
|
||||
}
|
||||
|
||||
public function testOrX()
|
||||
{
|
||||
$expr = $this->builder->orX($this->builder->eq("a", "b"));
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $expr);
|
||||
$this->assertEquals(CompositeExpression::TYPE_OR, $expr->getType());
|
||||
}
|
||||
|
||||
public function testInvalidAndXArgument()
|
||||
{
|
||||
$this->setExpectedException("RuntimeException");
|
||||
$this->builder->andX("foo");
|
||||
}
|
||||
|
||||
public function testEq()
|
||||
{
|
||||
$expr = $this->builder->eq("a", "b");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr);
|
||||
$this->assertEquals(Comparison::EQ, $expr->getOperator());
|
||||
}
|
||||
|
||||
public function testNeq()
|
||||
{
|
||||
$expr = $this->builder->neq("a", "b");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr);
|
||||
$this->assertEquals(Comparison::NEQ, $expr->getOperator());
|
||||
}
|
||||
|
||||
public function testLt()
|
||||
{
|
||||
$expr = $this->builder->lt("a", "b");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr);
|
||||
$this->assertEquals(Comparison::LT, $expr->getOperator());
|
||||
}
|
||||
|
||||
public function testGt()
|
||||
{
|
||||
$expr = $this->builder->gt("a", "b");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr);
|
||||
$this->assertEquals(Comparison::GT, $expr->getOperator());
|
||||
}
|
||||
|
||||
public function testGte()
|
||||
{
|
||||
$expr = $this->builder->gte("a", "b");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr);
|
||||
$this->assertEquals(Comparison::GTE, $expr->getOperator());
|
||||
}
|
||||
|
||||
public function testLte()
|
||||
{
|
||||
$expr = $this->builder->lte("a", "b");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr);
|
||||
$this->assertEquals(Comparison::LTE, $expr->getOperator());
|
||||
}
|
||||
|
||||
public function testIn()
|
||||
{
|
||||
$expr = $this->builder->in("a", array("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"));
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr);
|
||||
$this->assertEquals(Comparison::NIN, $expr->getOperator());
|
||||
}
|
||||
|
||||
public function testIsNull()
|
||||
{
|
||||
$expr = $this->builder->isNull("a");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr);
|
||||
$this->assertEquals(Comparison::EQ, $expr->getOperator());
|
||||
}
|
||||
|
||||
public function testContains()
|
||||
{
|
||||
$expr = $this->builder->contains("a", "b");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\Comparison', $expr);
|
||||
$this->assertEquals(Comparison::CONTAINS, $expr->getOperator());
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
use Doctrine\Common\Collections\AbstractLazyCollection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* Simple lazy collection that used an ArrayCollection as backed collection
|
||||
*/
|
||||
class LazyArrayCollection extends AbstractLazyCollection
|
||||
{
|
||||
/**
|
||||
* Do the initialization logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function doInitialize()
|
||||
{
|
||||
$this->collection = new ArrayCollection(array('a', 'b', 'c'));
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file bootstraps the test environment.
|
||||
*/
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
// register silently failing autoloader
|
||||
spl_autoload_register(function($class) {
|
||||
if (0 === strpos($class, 'Doctrine\Tests\\')) {
|
||||
$path = __DIR__.'/../../'.strtr($class, '\\', '/').'.php';
|
||||
if (is_file($path) && is_readable($path)) {
|
||||
require_once $path;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
require_once __DIR__ . "/../../../vendor/autoload.php";
|
Reference in a new issue