Skip to content

Commit

Permalink
Merge pull request #2393 from doctrine/2.2.x-merge-up-into-2.3.x_Tn8I…
Browse files Browse the repository at this point in the history
…KURv

Merge release 2.2.3 into 2.3.x
  • Loading branch information
malarzm authored Nov 30, 2021
2 parents 127da81 + fe4d27d commit 9cb4d51
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 152 deletions.
50 changes: 1 addition & 49 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,4 @@ on:
jobs:
coding-standards:
name: "Coding Standards"
runs-on: "ubuntu-20.04"

strategy:
matrix:
php-version:
- "8.0"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: "mongodb-${{ matrix.driver-version }}, bcmath"
key: "extcache-v1"

- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "mongodb, bcmath"
php-version: "${{ matrix.php-version }}"
tools: "cs2pr"

- name: "Show driver information"
run: "php --ri mongodb"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Upload composer.lock as build artifact"
uses: actions/upload-artifact@v2
with:
name: composer.lock
path: composer.lock

# https://github.com/doctrine/.github/issues/3
- name: "Run PHP_CodeSniffer"
run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr"
uses: "doctrine/.github/.github/workflows/[email protected]"
55 changes: 7 additions & 48 deletions .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,10 @@ on:
jobs:
release:
name: "Git tag, release & create merge-up PR"
runs-on: "ubuntu-20.04"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Release"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:release"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}

- name: "Create Merge-Up Pull Request"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:create-merge-up-pull-request"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}

# Uncomment this step if the repository uses a "next minor as default
# branch" policy.
#
# - name: "Create and/or Switch to new Release Branch"
# uses: "laminas/automatic-releases@v1"
# with:
# command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor"
# env:
# "GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
# "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
# "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
# "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}

- name: "Create new milestones"
uses: "laminas/automatic-releases@v1"
with:
command-name: "laminas:automatic-releases:create-milestones"
env:
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
uses: "doctrine/.github/.github/workflows/[email protected]"
secrets:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
ORGANIZATION_ADMIN_TOKEN: ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }}
2 changes: 1 addition & 1 deletion doctrine-mongo-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
<xs:element name="partial-filter-expression" type="odm:partial-filter-expression" minOccurs="0" />
</xs:choice>

<xs:attribute name="name" type="xs:NMTOKEN" />
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="drop-dups" type="xs:boolean" />
<xs:attribute name="background" type="xs:boolean" />
<xs:attribute name="unique" type="xs:boolean" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
use ReturnTypeWillChange;
use Traversable;

use function array_udiff;
use function array_combine;
use function array_diff_key;
use function array_map;
use function array_udiff_assoc;
use function array_values;
use function count;
use function get_class;
use function is_object;
use function spl_object_hash;

/**
* Trait with methods needed to implement PersistentCollectionInterface.
Expand Down Expand Up @@ -252,18 +253,11 @@ static function ($a, $b) {

public function getDeletedDocuments()
{
$compare = static function ($a, $b) {
$compareA = is_object($a) ? spl_object_hash($a) : $a;
$compareb = is_object($b) ? spl_object_hash($b) : $b;
$coll = $this->coll->toArray();
$loadedObjectsByOid = array_combine(array_map('spl_object_id', $this->snapshot), $this->snapshot);
$newObjectsByOid = array_combine(array_map('spl_object_id', $coll), $coll);

return $compareA === $compareb ? 0 : ($compareA > $compareb ? 1 : -1);
};

return array_values(array_udiff(
$this->snapshot,
$this->coll->toArray(),
$compare
));
return array_values(array_diff_key($loadedObjectsByOid, $newObjectsByOid));
}

public function getInsertDiff()
Expand All @@ -279,18 +273,11 @@ static function ($a, $b) {

public function getInsertedDocuments()
{
$compare = static function ($a, $b) {
$compareA = is_object($a) ? spl_object_hash($a) : $a;
$compareb = is_object($b) ? spl_object_hash($b) : $b;
$coll = $this->coll->toArray();
$newObjectsByOid = array_combine(array_map('spl_object_id', $coll), $coll);
$loadedObjectsByOid = array_combine(array_map('spl_object_id', $this->snapshot), $this->snapshot);

return $compareA === $compareb ? 0 : ($compareA > $compareb ? 1 : -1);
};

return array_values(array_udiff(
$this->coll->toArray(),
$this->snapshot,
$compare
));
return array_values(array_diff_key($newObjectsByOid, $loadedObjectsByOid));
}

public function getOwner(): ?object
Expand Down
15 changes: 3 additions & 12 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2310Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@
use Documents74\GH2310Embedded;
use MongoDB\BSON\ObjectId;

use function phpversion;
use function version_compare;

/**
* @requires PHP 7.4
*/
class GH2310Test extends BaseTest
{
public function setUp(): void
{
if (version_compare((string) phpversion(), '7.4.0', '<')) {
self::markTestSkipped('PHP 7.4 is required to run this test');
}

parent::setUp();
}

public function testFindWithNullableEmbeddedAfterUpsert(): void
{
$document = new GH2310Container((string) new ObjectId(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@
use MongoDB\BSON\ObjectId;

use function assert;
use function phpversion;
use function version_compare;

/**
* @requires PHP 7.4
*/
class TypedPropertiesTest extends BaseTest
{
public function setUp(): void
{
if (version_compare((string) phpversion(), '7.4.0', '<')) {
$this->markTestSkipped('PHP 7.4 is required to run this test');
}

parent::setUp();
}

public function testPersistNew(): void
{
$ref = new TypedDocument();
Expand Down
14 changes: 14 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use TestDocuments\SchemaValidatedDocument;
use TestDocuments\UserCustomIdGenerator;
use TestDocuments\UserNonStringOptions;
use TestDocuments\WildcardIndexDocument;

use function MongoDB\BSON\fromJSON;
use function MongoDB\BSON\toPHP;
Expand Down Expand Up @@ -76,6 +77,19 @@ public function testInvalidPartialFilterExpressions(): void
$this->driver->loadMetadataForClass(InvalidPartialFilterDocument::class, $classMetadata);
}

public function testWildcardIndexName(): void
{
$classMetadata = new ClassMetadata(WildcardIndexDocument::class);
$this->driver->loadMetadataForClass(WildcardIndexDocument::class, $classMetadata);

$this->assertSame([
[
'keys' => ['fieldA.$**' => 1],
'options' => ['name' => 'fieldA.$**_1'],
],
], $classMetadata->getIndexes());
}

public function testAlsoLoadFieldMapping(): void
{
$classMetadata = new ClassMetadata(AlsoLoadDocument::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace TestDocuments;

class WildcardIndexDocument
{
/** @var string|null */
protected $id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<document name="TestDocuments\WildcardIndexDocument" db="documents" collection="wildcardIndexDocument">
<id />
<indexes>
<index name="fieldA.$**_1">
<key name="fieldA.$**" />
</index>
</indexes>
</document>
</doctrine-mongo-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Doctrine\ODM\MongoDB\PersistentCollection\DefaultPersistentCollectionGenerator;
use Doctrine\ODM\MongoDB\Tests\BaseTest;

use function phpversion;
use function version_compare;

/**
* Tests aims to check if classes generated for various PHP versions are correct (i.e. parses).
*/
Expand Down Expand Up @@ -49,12 +46,11 @@ public function testWithNullableReturnType(): void
$this->assertInstanceOf(CollWithNullableReturnType::class, $coll);
}

/**
* @requires PHP 8.0
*/
public function testPHP80Types(): void
{
if (version_compare((string) phpversion(), '8.0.0', '<')) {
$this->markTestSkipped('PHP 8.0 is required to run this test');
}

$class = $this->generator->loadClass(CollWithPHP80Types::class, Configuration::AUTOGENERATE_EVAL);
$coll = new $class(new CollWithPHP80Types(), $this->dm, $this->uow);
$this->assertInstanceOf(CollWithPHP80Types::class, $coll);
Expand Down

0 comments on commit 9cb4d51

Please sign in to comment.