Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for Paginator with objects custom Id #7886

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,9 @@ public function getSingleResult($hydrationMode = null)
*
* Alias for getSingleResult(HYDRATE_SINGLE_SCALAR).
*
* @return mixed The scalar result, or NULL if the query returned no result.
* @return mixed The scalar result.
*
* @throws NoResultException If the query returned no result.
* @throws NonUniqueResultException If the query result is not unique.
*/
public function getSingleScalarResult()
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Version
/**
* Current Doctrine Version
*/
const VERSION = '2.6.4-DEV';
const VERSION = '2.6.5-DEV';

/**
* Compares a Doctrine version with the current one.
Expand Down
250 changes: 250 additions & 0 deletions tests/Doctrine/Tests/Models/CMSCustomId/CmsAddress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<?php

namespace Doctrine\Tests\Models\CMSCustomId;

/**
* CmsAddress
*
* @author Roman S. Borschel
* @Entity
* @Table(name="cms_addresses_customid")
*
* @NamedNativeQueries({
* @NamedNativeQuery(
* name = "find-all",
* resultSetMapping = "mapping-find-all",
* query = "SELECT id, country, city FROM cms_addresses"
* ),
* @NamedNativeQuery(
* name = "find-by-id",
* resultClass = "CmsAddress",
* query = "SELECT * FROM cms_addresses WHERE id = ?"
* ),
* @NamedNativeQuery(
* name = "count",
* resultSetMapping= "mapping-count",
* query = "SELECT COUNT(*) AS count FROM cms_addresses"
* )
* })
*
* @SqlResultSetMappings({
* @SqlResultSetMapping(
* name = "mapping-find-all",
* entities= {
* @EntityResult(
* entityClass = "CmsAddress",
* fields = {
* @FieldResult(name = "id", column="id"),
* @FieldResult(name = "city", column="city"),
* @FieldResult(name = "country", column="country")
* }
* )
* }
* ),
* @SqlResultSetMapping(
* name = "mapping-without-fields",
* entities= {
* @EntityResult(
* entityClass = "__CLASS__"
* )
* }
* ),
* @SqlResultSetMapping(
* name = "mapping-count",
* columns = {
* @ColumnResult(
* name = "count"
* )
* }
* )
* })
*
* @EntityListeners({"CmsAddressListener"})
*/
class CmsAddress
{
/**
* @Id
* @Column(type="CustomIdObject")
* @GeneratedValue(strategy="NONE")
*/
public $id;

/**
* @Column(length=50)
*/
public $country;

/**
* @Column(length=50)
*/
public $zip;

/**
* @Column(length=50)
*/
public $city;

/**
* Testfield for Schema Updating Tests.
*/
public $street;

/**
* @OneToOne(targetEntity="CmsUser", inversedBy="address")
* @JoinColumn(referencedColumnName="id")
*/
public $user;

public function getId() {
return $this->id;
}

public function getUser() {
return $this->user;
}

public function getCountry() {
return $this->country;
}

public function getZipCode() {
return $this->zip;
}

public function getCity() {
return $this->city;
}

public function setUser(CmsUser $user) {
if ($this->user !== $user) {
$this->user = $user;
$user->setAddress($this);
}
}

public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
{
$metadata->setPrimaryTable(
[
'name' => 'company_person',
]
);

$metadata->mapField(
[
'id' => true,
'fieldName' => 'id',
'type' => 'integer',
]
);

$metadata->mapField(
[
'fieldName' => 'zip',
'length' => 50,
]
);

$metadata->mapField(
[
'fieldName' => 'city',
'length' => 50,
]
);

$metadata->mapOneToOne(
[
'fieldName' => 'user',
'targetEntity' => 'CmsUser',
'joinColumns' => [['referencedColumnName' => 'id']]
]
);

$metadata->addNamedNativeQuery(
[
'name' => 'find-all',
'query' => 'SELECT id, country, city FROM cms_addresses_customid',
'resultSetMapping' => 'mapping-find-all',
]
);

$metadata->addNamedNativeQuery(
[
'name' => 'find-by-id',
'query' => 'SELECT * FROM cms_addresses_customid WHERE id = ?',
'resultClass' => CmsAddress::class,
]
);

$metadata->addNamedNativeQuery(
[
'name' => 'count',
'query' => 'SELECT COUNT(*) AS count FROM cms_addresses_customid',
'resultSetMapping' => 'mapping-count',
]
);

$metadata->addSqlResultSetMapping(
[
'name' => 'mapping-find-all',
'columns' => [],
'entities' => [
[
'fields' => [
[
'name' => 'id',
'column' => 'id',
],
[
'name' => 'city',
'column' => 'city',
],
[
'name' => 'country',
'column' => 'country',
],
],
'entityClass' => CmsAddress::class,
],
],
]
);

$metadata->addSqlResultSetMapping(
[
'name' => 'mapping-without-fields',
'columns' => [],
'entities' => [
[
'entityClass' => CmsAddress::class,
'fields' => []
]
]
]
);

$metadata->addSqlResultSetMapping(
[
'name' => 'mapping-count',
'columns' => [
[
'name' => 'count',
],
]
]
);

$metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CmsAddressListener', 'postPersist');
$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CmsAddressListener', 'prePersist');

$metadata->addEntityListener(\Doctrine\ORM\Events::postUpdate, 'CmsAddressListener', 'postUpdate');
$metadata->addEntityListener(\Doctrine\ORM\Events::preUpdate, 'CmsAddressListener', 'preUpdate');

$metadata->addEntityListener(\Doctrine\ORM\Events::postRemove, 'CmsAddressListener', 'postRemove');
$metadata->addEntityListener(\Doctrine\ORM\Events::preRemove, 'CmsAddressListener', 'preRemove');

$metadata->addEntityListener(\Doctrine\ORM\Events::preFlush, 'CmsAddressListener', 'preFlush');
$metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CmsAddressListener', 'postLoad');
}
}
58 changes: 58 additions & 0 deletions tests/Doctrine/Tests/Models/CMSCustomId/CmsAddressListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Doctrine\Tests\Models\CMSCustomId;

class CmsAddressListener
{
public $calls;

public function prePersist()
{
$this->calls[__FUNCTION__][] = func_get_args();
}

public function postPersist()
{
$this->calls[__FUNCTION__][] = func_get_args();
}

public function preUpdate()
{
$this->calls[__FUNCTION__][] = func_get_args();
}

public function postUpdate()
{
$this->calls[__FUNCTION__][] = func_get_args();
}

public function preRemove()
{
$this->calls[__FUNCTION__][] = func_get_args();
}

public function postRemove()
{
$this->calls[__FUNCTION__][] = func_get_args();
}

public function postLoad()
{
$this->calls[__FUNCTION__][] = func_get_args();
}

public function preFlush()
{
$this->calls[__FUNCTION__][] = func_get_args();
}

protected function postPersistHandler()
{
throw new \BadMethodCallException("This is not a valid callback");
}

protected function prePersistHandler()
{
throw new \BadMethodCallException("This is not a valid callback");
}
}
48 changes: 48 additions & 0 deletions tests/Doctrine/Tests/Models/CMSCustomId/CmsArticle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Doctrine\Tests\Models\CMSCustomId;

/**
* @Entity
* @Table(name="cms_articles_customid")
*/
class CmsArticle
{
/**
* @Id
* @Column(type="CustomIdObject")
* @GeneratedValue(strategy="NONE")
*/
public $id;
/**
* @Column(type="string", length=255)
*/
public $topic;
/**
* @Column(type="text")
*/
public $text;
/**
* @ManyToOne(targetEntity="CmsUser", inversedBy="articles")
* @JoinColumn(name="user_id", referencedColumnName="id")
*/
public $user;
/**
* @OneToMany(targetEntity="CmsComment", mappedBy="article")
*/
public $comments;

/**
* @Version @column(type="integer")
*/
public $version;

public function setAuthor(CmsUser $author) {
$this->user = $author;
}

public function addComment(CmsComment $comment) {
$this->comments[] = $comment;
$comment->setArticle($this);
}
}
Loading