Skip to content

Commit

Permalink
Merge branch '2.20.x' into 3.3.x
Browse files Browse the repository at this point in the history
* 2.20.x:
  Bump doctrine/.github from 5.1.0 to 5.2.0 (doctrine#11680)
  Psalm 5.26.1 (doctrine#11677)
  Update README (doctrine#11673)
  Fix PHPUnit deprecations
  Bump doctrine/.github from 5.1.0 to 5.2.0 (doctrine#11671)
  Experiment with literalinclude
  • Loading branch information
derrabus committed Oct 14, 2024
2 parents 6dae89c + 982d606 commit 62609b1
Show file tree
Hide file tree
Showing 23 changed files with 249 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ on:

jobs:
coding-standards:
uses: "doctrine/.github/.github/workflows/coding-standards.yml@5.1.0"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@5.2.0"
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ on:
jobs:
documentation:
name: "Documentation"
uses: "doctrine/.github/.github/workflows/documentation.yml@5.1.0"
uses: "doctrine/.github/.github/workflows/documentation.yml@5.2.0"
2 changes: 1 addition & 1 deletion .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
release:
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@5.1.0"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@5.2.0"
secrets:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
| [4.0.x][4.0] | [3.3.x][3.3] | [3.2.x][3.2] | [2.20.x][2.20] | [2.19.x][2.19] |
| [4.0.x][4.0] | [3.4.x][3.4] | [3.3.x][3.3] | [2.21.x][2.21] | [2.20.x][2.20] |
|:------------------------------------------------------:|:------------------------------------------------------:|:------------------------------------------------------:|:--------------------------------------------------------:|:--------------------------------------------------------:|
| [![Build status][4.0 image]][4.0] | [![Build status][3.3 image]][3.3] | [![Build status][3.2 image]][3.2] | [![Build status][2.20 image]][2.20] | [![Build status][2.19 image]][2.19] |
| [![Coverage Status][4.0 coverage image]][4.0 coverage] | [![Coverage Status][3.3 coverage image]][3.3 coverage] | [![Coverage Status][3.2 coverage image]][3.2 coverage] | [![Coverage Status][2.20 coverage image]][2.20 coverage] | [![Coverage Status][2.19 coverage image]][2.19 coverage] |
| [![Build status][4.0 image]][4.0] | [![Build status][3.4 image]][3.4] | [![Build status][3.3 image]][3.3] | [![Build status][2.21 image]][2.21] | [![Build status][2.20 image]][2.20] |
| [![Coverage Status][4.0 coverage image]][4.0 coverage] | [![Coverage Status][3.4 coverage image]][3.4 coverage] | [![Coverage Status][3.3 coverage image]][3.3 coverage] | [![Coverage Status][2.21 coverage image]][2.21 coverage] | [![Coverage Status][2.20 coverage image]][2.20 coverage] |

[<h1 align="center">🇺🇦 UKRAINE NEEDS YOUR HELP NOW!</h1>](https://www.doctrine-project.org/stop-war.html)

Expand All @@ -22,19 +22,19 @@ without requiring unnecessary code duplication.
[4.0]: https://github.com/doctrine/orm/tree/4.0.x
[4.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/4.0.x/graph/badge.svg
[4.0 coverage]: https://codecov.io/gh/doctrine/orm/branch/4.0.x
[3.4 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.4.x
[3.4]: https://github.com/doctrine/orm/tree/3.4.x
[3.4 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.4.x/graph/badge.svg
[3.4 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.4.x
[3.3 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.3.x
[3.3]: https://github.com/doctrine/orm/tree/3.3.x
[3.3 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.3.x/graph/badge.svg
[3.3 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.3.x
[3.2 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.2.x
[3.2]: https://github.com/doctrine/orm/tree/3.2.x
[3.2 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.2.x/graph/badge.svg
[3.2 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.2.x
[2.21 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.21.x
[2.21]: https://github.com/doctrine/orm/tree/2.21.x
[2.21 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.21.x/graph/badge.svg
[2.21 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.21.x
[2.20 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.20.x
[2.20]: https://github.com/doctrine/orm/tree/2.20.x
[2.20 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.20.x/graph/badge.svg
[2.20 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.20.x
[2.19 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.19.x
[2.19]: https://github.com/doctrine/orm/tree/2.19.x
[2.19 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.19.x/graph/badge.svg
[2.19 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.19.x
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.2",
"symfony/cache": "^5.4 || ^6.2 || ^7.0",
"vimeo/psalm": "5.24.0"
"vimeo/psalm": "5.26.1"
},
"suggest": {
"ext-dom": "Provides support for XSD validation for XML mapping files",
Expand Down
81 changes: 8 additions & 73 deletions docs/en/tutorials/working-with-indexed-associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,83 +29,18 @@ You can map indexed associations by adding:
The code and mappings for the Market entity looks like this:

.. configuration-block::
.. code-block:: attribute
<?php
namespace Doctrine\Tests\Models\StockExchange;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
#[Entity]
#[Table(name: 'exchange_markets')]
class Market
{
#[Id, Column(type: 'integer'), GeneratedValue]
private int|null $id = null;
#[Column(type: 'string')]
private string $name;
/** @var Collection<string, Stock> */
#[OneToMany(targetEntity: Stock::class, mappedBy: 'market', indexBy: 'symbol')]
private Collection $stocks;
public function __construct(string $name)
{
$this->name = $name;
$this->stocks = new ArrayCollection();
}
public function getId(): int|null
{
return $this->id;
}
public function getName(): string
{
return $this->name;
}
public function addStock(Stock $stock): void
{
$this->stocks[$stock->getSymbol()] = $stock;
}
public function getStock(string $symbol): Stock
{
if (!isset($this->stocks[$symbol])) {
throw new \InvalidArgumentException("Symbol is not traded on this market.");
}
return $this->stocks[$symbol];
}
/** @return array<string, Stock> */
public function getStocks(): array
{
return $this->stocks->toArray();
}
}
.. code-block:: xml
.. literalinclude:: working-with-indexed-associations/Market.php
:language: attribute

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
.. literalinclude:: working-with-indexed-associations/Market-annotations.php
:language: annotation

<entity name="Doctrine\Tests\Models\StockExchange\Market">
<id name="id" type="integer">
<generator strategy="AUTO" />
</id>
.. literalinclude:: working-with-indexed-associations/market.xml
:language: xml

<field name="name" type="string"/>
.. literalinclude:: working-with-indexed-associations/market.xml
:language: yaml

<one-to-many target-entity="Stock" mapped-by="market" field="stocks" index-by="symbol" />
</entity>
</doctrine-mapping>

Inside the ``addStock()`` method you can see how we directly set the key of the association to the symbol,
so that we can work with the indexed association directly after invoking ``addStock()``. Inside ``getStock($symbol)``
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Doctrine\Tests\Models\StockExchange;

use Doctrine\Common\Collections\ArrayCollection;
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;
use Doctrine\ORM\Mapping\Table;
use InvalidArgumentException;

/**
* @Entity
* @Table(name="exchange_markets")
*/
class Market
{
/**
* @Id @Column(type="integer") @GeneratedValue
* @var int
*/
private int|null $id = null;

/**
* @Column(type="string")
* @var string
*/
private string $name;

/**
* @OneToMany(targetEntity="Stock", mappedBy="market", indexBy="symbol")
* @var Collection<int, Stock>
*/
private Collection $stocks;

public function __construct($name)
{
$this->name = $name;
$this->stocks = new ArrayCollection();
}

public function getId(): int|null
{
return $this->id;
}

public function getName(): string
{
return $this->name;
}

public function addStock(Stock $stock): void
{
$this->stocks[$stock->getSymbol()] = $stock;
}

public function getStock($symbol): Stock
{
if (!isset($this->stocks[$symbol])) {
throw new InvalidArgumentException("Symbol is not traded on this market.");
}

return $this->stocks[$symbol];
}

/** @return array<string, Stock> */
public function getStocks(): array
{
return $this->stocks->toArray();
}
}
68 changes: 68 additions & 0 deletions docs/en/tutorials/working-with-indexed-associations/Market.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\StockExchange;

use Doctrine\Common\Collections\ArrayCollection;
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;
use Doctrine\ORM\Mapping\Table;
use InvalidArgumentException;

#[Entity]
#[Table(name: 'exchange_markets')]
class Market
{
#[Id]
#[Column(type: 'integer')]
#[GeneratedValue]
private int|null $id = null;

#[Column(type: 'string')]
private string $name;

/** @var Collection<string, Stock> */
#[OneToMany(targetEntity: Stock::class, mappedBy: 'market', indexBy: 'symbol')]
private Collection $stocks;

public function __construct(string $name)
{
$this->name = $name;
$this->stocks = new ArrayCollection();
}

public function getId(): int|null
{
return $this->id;
}

public function getName(): string
{
return $this->name;
}

public function addStock(Stock $stock): void
{
$this->stocks[$stock->getSymbol()] = $stock;
}

public function getStock(string $symbol): Stock
{
if (! isset($this->stocks[$symbol])) {
throw new InvalidArgumentException('Symbol is not traded on this market.');
}

return $this->stocks[$symbol];
}

/** @return array<string, Stock> */
public function getStocks(): array
{
return $this->stocks->toArray();
}
}
16 changes: 16 additions & 0 deletions docs/en/tutorials/working-with-indexed-associations/market.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Doctrine\Tests\Models\StockExchange\Market">
<id name="id" type="integer">
<generator strategy="AUTO" />
</id>

<field name="name" type="string"/>

<one-to-many target-entity="Stock" mapped-by="market" field="stocks" index-by="symbol" />
</entity>
</doctrine-mapping>
15 changes: 15 additions & 0 deletions docs/en/tutorials/working-with-indexed-associations/market.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Doctrine\Tests\Models\StockExchange\Market:
type: entity
id:
id:
type: integer
generator:
strategy: AUTO
fields:
name:
type:string
oneToMany:
stocks:
targetEntity: Stock
mappedBy: market
indexBy: symbol
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.24.0@462c80e31c34e58cc4f750c656be3927e80e550e">
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/AbstractQuery.php">
<FalsableReturnStatement>
<code><![CDATA[! $filteredParameters->isEmpty() ? $filteredParameters->first() : null]]></code>
Expand Down
12 changes: 6 additions & 6 deletions tests/Tests/ORM/Cache/DefaultCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testBuildCachedEntityPersisterReadOnly(): void
$this->factory->expects(self::once())
->method('getRegion')
->with(self::equalTo($metadata->cache))
->will(self::returnValue($region));
->willReturn($region);

$cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata);

Expand All @@ -91,7 +91,7 @@ public function testBuildCachedEntityPersisterReadWrite(): void
$this->factory->expects(self::once())
->method('getRegion')
->with(self::equalTo($metadata->cache))
->will(self::returnValue($region));
->willReturn($region);

$cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata);

Expand All @@ -111,7 +111,7 @@ public function testBuildCachedEntityPersisterNonStrictReadWrite(): void
$this->factory->expects(self::once())
->method('getRegion')
->with(self::equalTo($metadata->cache))
->will(self::returnValue($region));
->willReturn($region);

$cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata);

Expand All @@ -132,7 +132,7 @@ public function testBuildCachedCollectionPersisterReadOnly(): void
$this->factory->expects(self::once())
->method('getRegion')
->with(self::equalTo($mapping->cache))
->will(self::returnValue($region));
->willReturn($region);

$cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping);

Expand All @@ -153,7 +153,7 @@ public function testBuildCachedCollectionPersisterReadWrite(): void
$this->factory->expects(self::once())
->method('getRegion')
->with(self::equalTo($mapping->cache))
->will(self::returnValue($region));
->willReturn($region);

$cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping);

Expand All @@ -174,7 +174,7 @@ public function testBuildCachedCollectionPersisterNonStrictReadWrite(): void
$this->factory->expects(self::once())
->method('getRegion')
->with(self::equalTo($mapping->cache))
->will(self::returnValue($region));
->willReturn($region);

$cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping);

Expand Down
Loading

0 comments on commit 62609b1

Please sign in to comment.