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

Json_Array type returns empty array when used with nullable annotation #968

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion composer.json
Expand Up @@ -16,7 +16,7 @@
"php": ">=5.3.2",
"ext-pdo": "*",
"doctrine/collections": "~1.1",
"doctrine/dbal": ">=2.5-dev,<2.6-dev",
"doctrine/dbal": "dev-bugfix/nullable-json-array-mapped-to-empty-array",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be in the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof

Sure, needs to be changed if doctrine/dbal#538 gets merged.

"symfony/console": "2.*"
},
"require-dev": {
Expand All @@ -26,6 +26,12 @@
"suggest": {
"symfony/yaml": "If you want to use YAML Metadata Mapping Driver"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/localheinz/dbal"
}
],
"autoload": {
"psr-0": { "Doctrine\\ORM\\": "lib/" }
},
Expand Down
72 changes: 72 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC446Test.php
@@ -0,0 +1,72 @@
<?php

namespace Doctrine\Tests\ORM\Functional\Ticket;

require_once __DIR__ . '/../../../TestInit.php';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed as it is already the PHPUnit bootstrap file (yeah, I know we have lots of places using it because it was not cleaned when cleaning the PHPUnit setup)


class DDC446Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
parent::setUp();
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC446Entity'),
));
}

public function testNullableJsonArrayIsNull()
{
$entity = new DDC446Entity();

$this->_em->persist($entity);

$this->_em->flush();
$this->_em->clear();

$entity = $this->_em->find(
DDC446Entity::class,
$entity->getId()
);

$this->assertInstanceOf(DDC446Entity::class, $entity);
$this->assertNull($entity->getData());
}
}


/**
* @Entity
* @Table(name = "ddc446")
*/
class DDC446Entity
{
/**
* @Id
* @Column(
* name = "id",
* type = "integer"
* )
* @GeneratedValue(strategy="AUTO")
*/
public $id;

/**
* @Column(
* name = "data",
* type = "json_array",
* nullable = true
* )
*/
public $data;

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

public function getData()
{
return $this->data;
}
}