Skip to content

Commit

Permalink
Merge pull request #7281 from Majkl578/sync-2.7
Browse files Browse the repository at this point in the history
Sync 2.7 with 2.6
  • Loading branch information
Ocramius committed Jul 3, 2018
2 parents 4f6d47b + 915b152 commit e814f67
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 6 deletions.
7 changes: 7 additions & 0 deletions UPGRADE.md
Expand Up @@ -7,6 +7,13 @@ It will be removed in 3.0.

# Upgrade to 2.6

## Added `Doctrine\ORM\EntityRepository::count()` method

`Doctrine\ORM\EntityRepository::count()` has been added. This new method has different
signature than `Countable::count()` (required parameter) and therefore are not compatible.
If your repository implemented the `Countable` interface, you will have to use
`$repository->count([])` instead and not implement `Countable` interface anymore.

## Minor BC BREAK: `Doctrine\ORM\Tools\Console\ConsoleRunner` is now final

Since it's just an utilitarian class and should not be inherited.
Expand Down
7 changes: 7 additions & 0 deletions docs/en/reference/working-with-objects.rst
Expand Up @@ -25,6 +25,13 @@ Work that have not yet been persisted are lost.
Not calling ``EntityManager#flush()`` will lead to all changes
during that request being lost.

.. note::

Doctrine does NEVER touch the public API of methods in your entity
classes (like getters and setters) nor the constructor method.
Instead, it uses reflection to get/set data from/to your entity objects.
When Doctrine fetches data from DB and saves it back,
any code put in your get/set methods won't be implicitly taken into account.

Entities and the Identity Map
-----------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/EntityRepository.php
Expand Up @@ -19,7 +19,7 @@

namespace Doctrine\ORM;

use Doctrine\Common\Util\Inflector;
use Doctrine\Common\Inflector\Inflector;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\Common\Collections\Selectable;
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Id/AbstractIdGenerator.php
Expand Up @@ -27,7 +27,7 @@ abstract class AbstractIdGenerator
* Generates an identifier for an entity.
*
* @param EntityManager $em
* @param \Doctrine\ORM\Mapping\Entity $entity
* @param object|null $entity
* @return mixed
*/
abstract public function generate(EntityManager $em, $entity);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
Expand Up @@ -19,9 +19,9 @@

namespace Doctrine\ORM\Mapping\Driver;

use Doctrine\Common\Inflector\Inflector;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Util\Inflector;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Table;
Expand Down
6 changes: 5 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
Expand Up @@ -19,6 +19,7 @@

namespace Doctrine\ORM\Mapping\Driver;

use Doctrine\Common\Collections\Criteria;
use SimpleXMLElement;
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder;
Expand Down Expand Up @@ -429,7 +430,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
if (isset($oneToManyElement->{'order-by'})) {
$orderBy = [];
foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) {
$orderBy[(string) $orderByField['name']] = (string) $orderByField['direction'];
$orderBy[(string) $orderByField['name']] = isset($orderByField['direction'])
? (string) $orderByField['direction']
: Criteria::ASC
;
}
$mapping['orderBy'] = $orderBy;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/Query/Lexer.php
Expand Up @@ -19,6 +19,8 @@

namespace Doctrine\ORM\Query;

use Doctrine\Common\Lexer\AbstractLexer;

/**
* Scans a DQL query for tokens.
*
Expand All @@ -27,7 +29,7 @@
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class Lexer extends \Doctrine\Common\Lexer
class Lexer extends AbstractLexer
{
// All tokens that are not valid identifiers must be < 100
const T_NONE = 1;
Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/Models/GH7141/GH7141Article.php
@@ -0,0 +1,15 @@
<?php

namespace Doctrine\Tests\Models\GH7141;

use Doctrine\Common\Collections\ArrayCollection;

class GH7141Article
{
private $tags;

public function __construct()
{
$this->tags = new ArrayCollection();
}
}
20 changes: 20 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\Tests\ORM\Mapping;

use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
Expand All @@ -11,6 +12,7 @@
use Doctrine\Tests\Models\DDC3293\DDC3293UserPrefixed;
use Doctrine\Tests\Models\DDC889\DDC889Class;
use Doctrine\Tests\Models\Generic\SerializationModel;
use Doctrine\Tests\Models\GH7141\GH7141Article;
use Doctrine\Tests\Models\ValueObjects\Name;
use Doctrine\Tests\Models\ValueObjects\Person;

Expand Down Expand Up @@ -174,6 +176,24 @@ static public function dataValidSchema()
}, $list);
}

/**
* @group GH-7141
*/
public function testOneToManyDefaultOrderByAsc()
{
$driver = $this->_loadDriver();
$class = new ClassMetadata(GH7141Article::class);

$class->initializeReflection(new RuntimeReflectionService());
$driver->loadMetadataForClass(GH7141Article::class, $class);


$this->assertEquals(
Criteria::ASC,
$class->getMetadataValue('associationMappings')['tags']['orderBy']['position']
);
}

/**
* @group DDC-889
* @expectedException \Doctrine\Common\Persistence\Mapping\MappingException
Expand Down
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Doctrine\Tests\Models\GH7141\GH7141Article">
<one-to-many field="tags" target-entity="NoTargetEntity" mapped-by="noMappedByField">
<order-by>
<order-by-field name="position"/>
</order-by>
</one-to-many>
</entity>
</doctrine-mapping>
9 changes: 8 additions & 1 deletion tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
Expand Up @@ -823,7 +823,14 @@ public function testLimitAndOffsetFromQueryClass()
->setMaxResults(10)
->setFirstResult(0);

$this->assertEquals('SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ LIMIT 10 OFFSET 0', $q->getSql());
// DBAL 2.8+ doesn't add OFFSET part when offset is 0
self::assertThat(
$q->getSql(),
self::logicalOr(
self::identicalTo('SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ LIMIT 10'),
self::identicalTo('SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ LIMIT 10 OFFSET 0')
)
);
}

public function testSizeFunction()
Expand Down

0 comments on commit e814f67

Please sign in to comment.