Skip to content

Commit

Permalink
Test IDENTITY
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed Jun 19, 2024
1 parent 7f2a331 commit f02c1f0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/Platform/Entity/PlatformEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class PlatformEntity
#[ORM\Column(type: 'string', nullable: false)]
public $id;

/**
* @ORM\ManyToOne(targetEntity=PlatformRelatedEntity::class)
* @ORM\JoinColumn(name="related_entity_id", referencedColumnName="id", nullable=false)
* @var PlatformRelatedEntity
*/
#[ORM\ManyToOne(targetEntity: PlatformRelatedEntity::class)]
#[ORM\JoinColumn(name: 'related_entity_id', referencedColumnName: 'id', nullable: false)]
public $related_entity;

/**
* @ORM\Column(type="string", name="col_string", nullable=false)
* @var string
Expand Down
25 changes: 25 additions & 0 deletions tests/Platform/Entity/PlatformRelatedEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1);

namespace PHPStan\Platform\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Table(name="test_related")
* @ORM\Entity
*/
#[ORM\Table(name: 'test_related')]
#[ORM\Entity]
class PlatformRelatedEntity
{

/**
* @ORM\Id
* @ORM\Column(type="integer", nullable=false)
* @var int
*/
#[ORM\Id]
#[ORM\Column(type: 'integer', nullable: false)]
public $id;

}
23 changes: 22 additions & 1 deletion tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PHPStan\Doctrine\Driver\DriverType;
use PHPStan\Php\PhpVersion;
use PHPStan\Platform\Entity\PlatformEntity;
use PHPStan\Platform\Entity\PlatformRelatedEntity;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\BooleanType;
Expand Down Expand Up @@ -3509,7 +3510,21 @@ public static function provideCases(): iterable
'stringify' => self::STRINGIFY_DEFAULT,
];

// TODO test IDENTITY
yield 'IDENTITY(t.related_entity)' => [
'data' => self::dataDefault(),
'select' => 'SELECT IDENTITY(t.related_entity) FROM %s t',
'mysql' => self::int(),
'sqlite' => self::int(),
'pdo_pgsql' => self::int(),
'pgsql' => self::int(),
'mssql' => self::mixed(),
'mysqlResult' => 1,
'sqliteResult' => 1,
'pdoPgsqlResult' => 1,
'pgsqlResult' => 1,
'mssqlResult' => 1,
'stringify' => self::STRINGIFY_DEFAULT,
];
}

/**
Expand Down Expand Up @@ -3653,8 +3668,14 @@ private function getQuery(
$schemaTool->dropSchema($classes);
$schemaTool->createSchema($classes);

$relatedEntity = new PlatformRelatedEntity();
$relatedEntity->id = 1;
$entityManager->persist($relatedEntity);

foreach ($data as $rowData) {
$entity = new PlatformEntity();
$entity->related_entity = $relatedEntity;

foreach ($rowData as $column => $value) {
$entity->$column = $value; // @phpstan-ignore-line Intentionally dynamic
}
Expand Down

0 comments on commit f02c1f0

Please sign in to comment.