Skip to content

Commit

Permalink
Migrate annotations to attributes in fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Oct 25, 2023
1 parent e77e0e8 commit 72263d8
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 104 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"ext-json": "*",
"ext-pdo_sqlite": "*",
"ext-zip": "*",
"doctrine/annotations": "^2.0",
"doctrine/common": "^2.6|^3.3",
"doctrine/doctrine-bundle": "^2.7|^3.0",
"doctrine/orm": "^2.13.1",
Expand Down
5 changes: 2 additions & 3 deletions src/Adapter/Doctrine/ORMAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ protected function getResults(AdapterQuery $query): \Traversable
$event = new ORMAdapterQueryEvent($query);
$state->getDataTable()->getEventDispatcher()->dispatch($event, ORMAdapterEvents::PRE_QUERY);

foreach ($query->iterate([], $this->hydrationMode) as $result) {
yield $entity = array_values($result)[0];
foreach ($query->toIterable([], $this->hydrationMode) as $entity) {
yield $entity;
if (Query::HYDRATE_OBJECT === $this->hydrationMode) {
$this->manager->detach($entity);
}
Expand All @@ -190,7 +190,6 @@ protected function buildCriteria(QueryBuilder $queryBuilder, DataTableState $sta

protected function createQueryBuilder(DataTableState $state): QueryBuilder
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $this->manager->createQueryBuilder();

// Run all query builder processors in order
Expand Down
54 changes: 17 additions & 37 deletions tests/Fixtures/AppBundle/Entity/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,26 @@
namespace Tests\Fixtures\AppBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\OneToMany;

/**
* Company.
*
* @author Niels Keurentjes <[email protected]>
*
* @ORM\Entity
*/
#[Entity]
class Company
{
/**
* @var int
*
* @ORM\Column(type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
#[Id, GeneratedValue(strategy: 'IDENTITY'), Column]
private int $id;

/**
* @var string
*
* @ORM\Column(type="string", nullable=false)
*/
private $name;
#[Column]
private string $name;

/**
* @var ArrayCollection|array
*
* @ORM\OneToMany(targetEntity="Employee", mappedBy="company")
*/
private $employees;
/** @var Collection<Employee> */
#[OneToMany(mappedBy: 'company', targetEntity: Employee::class)]
private Collection $employees;

/**
* Company constructor.
*/
public function __construct(string $name)
{
$this->name = $name;
Expand All @@ -67,17 +50,14 @@ public function getName(): string
}

/**
* @return Person[]|ArrayCollection
* @return Collection<Employee>
*/
public function getEmployees()
public function getEmployees(): Collection
{
return $this->employees;
}

/**
* @return $this
*/
public function setName(string $name): Company
public function setName(string $name): static
{
$this->name = $name;

Expand Down
40 changes: 13 additions & 27 deletions tests/Fixtures/AppBundle/Entity/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,29 @@

namespace Tests\Fixtures\AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\ManyToOne;

/**
* Employee.
*
* @author Niels Keurentjes <[email protected]>
*
* @ORM\Entity
*/
#[Entity]
class Employee extends Person
{
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $employedSince;

/**
* @var Company
*
* @ORM\ManyToOne(targetEntity="Company", inversedBy="employees")
*/
private $company;

/**
* Person constructor.
*/
public function __construct(string $firstName, string $lastName, \DateTime $employedSince = null, Company $company)
#[Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTime $employedSince;

#[ManyToOne(targetEntity: Company::class, inversedBy: 'employees')]
private Company $company;

public function __construct(string $firstName, string $lastName, ?\DateTime $employedSince, Company $company)
{
parent::__construct($firstName, $lastName);

$this->company = $company;
$this->employedSince = $employedSince;
}

public function getEmployedSince()
public function getEmployedSince(): \DateTime
{
return $this->employedSince;
}
Expand Down
44 changes: 12 additions & 32 deletions tests/Fixtures/AppBundle/Entity/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,24 @@

namespace Tests\Fixtures\AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\InheritanceType;

/**
* Person.
*
* @author Niels Keurentjes <[email protected]>
*
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
*/
#[Entity, InheritanceType('JOINED')]
class Person
{
/**
* @var int
*
* @ORM\Column(type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
#[Id, GeneratedValue(strategy: 'IDENTITY'), Column]
private int $id;

/**
* @var string
*
* @ORM\Column(type="string", nullable=false)
*/
private $firstName;
#[Column]
private string $firstName;

/**
* @var string
*
* @ORM\Column(type="string", nullable=false)
*/
private $lastName;
#[Column]
private string $lastName;

/**
* Person constructor.
*/
public function __construct(string $firstName, string $lastName)
{
$this->firstName = $firstName;
Expand Down
11 changes: 9 additions & 2 deletions tests/Fixtures/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ imports:
- { resource: services.yml }

framework:
annotations:
enabled: true
php_errors:
log: true
handle_all_throwables: true

secret: '1234567890'
router:
utf8: true
Expand Down Expand Up @@ -32,13 +34,18 @@ doctrine:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
report_fields_where_declared: true
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool

mappings:
AppBundle:
type: attribute

twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
Expand Down
3 changes: 1 addition & 2 deletions tests/Functional/Exporter/Csv/CsvExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*/
class CsvExporterTest extends WebTestCase
{
/** @var KernelBrowser */
private $client;
private KernelBrowser $client;

protected function setUp(): void
{
Expand Down

0 comments on commit 72263d8

Please sign in to comment.