Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/backend-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: CI
name: Backend CI

on:
push:
branches:
- '[0-9]+.[0-9]+'
pull_request: ~
workflow_dispatch: ~

jobs:
cs-fix:
Expand All @@ -19,13 +20,17 @@ jobs:

- uses: ibexa/gh-workflows/actions/composer-install@main
with:
php-version: ${{ matrix.php }}
gh-client-id: ${{ secrets.AUTOMATION_CLIENT_ID }}
gh-client-secret: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
satis-network-key: ${{ secrets.SATIS_NETWORK_KEY }}
satis-network-token: ${{ secrets.SATIS_NETWORK_TOKEN }}

- name: Run code style check
run: composer run-script check-cs -- --format=checkstyle | cs2pr
shell: bash
run: |
set -euo pipefail
composer run-script check-cs -- --format=checkstyle | cs2pr

tests:
name: Unit tests & SQLite integration tests
Expand All @@ -44,6 +49,7 @@ jobs:

- uses: ibexa/gh-workflows/actions/composer-install@main
with:
php-version: ${{ matrix.php }}
gh-client-id: ${{ secrets.AUTOMATION_CLIENT_ID }}
gh-client-secret: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
satis-network-key: ${{ secrets.SATIS_NETWORK_KEY }}
Expand Down Expand Up @@ -96,6 +102,7 @@ jobs:

- uses: ibexa/gh-workflows/actions/composer-install@main
with:
php-version: ${{ matrix.php }}
gh-client-id: ${{ secrets.AUTOMATION_CLIENT_ID }}
gh-client-secret: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
satis-network-key: ${{ secrets.SATIS_NETWORK_KEY }}
Expand Down Expand Up @@ -148,6 +155,7 @@ jobs:

- uses: ibexa/gh-workflows/actions/composer-install@main
with:
php-version: ${{ matrix.php }}
gh-client-id: ${{ secrets.AUTOMATION_CLIENT_ID }}
gh-client-secret: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
satis-network-key: ${{ secrets.SATIS_NETWORK_KEY }}
Expand Down Expand Up @@ -210,6 +218,7 @@ jobs:
- name: Install Composer dependencies
uses: ibexa/gh-workflows/actions/composer-install@main
with:
php-version: ${{ matrix.php }}
gh-client-id: ${{ secrets.AUTOMATION_CLIENT_ID }}
gh-client-secret: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
satis-network-key: ${{ secrets.SATIS_NETWORK_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gha-docker-solr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
CORES_SETUP: single

- name: Log in to the Container registry
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/rector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ on:

jobs:
rector:
name: Run rector
uses: ibexa/gh-workflows/.github/workflows/rector.yml@main
with:
php-version: '8.3'
secrets:
AUTOMATION_CLIENT_ID: ${{ secrets.AUTOMATION_CLIENT_ID }}
AUTOMATION_CLIENT_SECRET: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ parameters:
ignoreErrors:
-
message: "#^Cannot call method warning\\(\\) on Psr\\\\Log\\\\LoggerInterface\\|null\\.$#"
-
# ObjectManager::find() declares 2 parameters, but the runtime EntityManager
# supports $lockMode and $lockVersion, forwarded like Doctrine\ORM\Decorator\EntityManagerDecorator does
message: '#^Method Doctrine\\Persistence\\ObjectManager\:\:find\(\) invoked with 4 parameters, 2 required\.$#'
identifier: arguments.count
count: 1
path: src/lib/Persistence/Doctrine/SiteAccessAwareEntityManager.php
paths:
- src
- tests
Expand Down
17 changes: 15 additions & 2 deletions src/lib/Persistence/Doctrine/SiteAccessAwareEntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,22 @@ public function getCache(): ?Cache
return $this->getWrapped()->getCache();
}

public function find($className, $id): ?object
/**
* @template T of object
*
* @phpstan-param class-string<T> $className
* @phpstan-param \Doctrine\DBAL\LockMode::*|null $lockMode
*
* @param string $className
* @param mixed $id
* @param int|null $lockMode
* @param int|null $lockVersion
*
* @return T|null
*/
public function find($className, $id, ?int $lockMode = null, ?int $lockVersion = null): ?object
{
return $this->getWrapped()->find($className, $id);
return $this->getWrapped()->find($className, $id, $lockMode, $lockVersion);
}

public function persist(object $object): void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Core\Persistence\Doctrine;

use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManagerInterface;
use Ibexa\Bundle\Core\Entity\EntityManagerFactory;
use Ibexa\Core\Persistence\Doctrine\SiteAccessAwareEntityManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use stdClass;

final class SiteAccessAwareEntityManagerTest extends TestCase
{
private EntityManagerInterface&MockObject $wrappedEntityManager;

private SiteAccessAwareEntityManager $entityManager;

protected function setUp(): void
{
$this->wrappedEntityManager = $this->createMock(EntityManagerInterface::class);

$entityManagerFactory = $this->createMock(EntityManagerFactory::class);
$entityManagerFactory
->method('getEntityManager')
->willReturn($this->wrappedEntityManager);

$this->entityManager = new SiteAccessAwareEntityManager($entityManagerFactory);
}

public function testFindForwardsLockModeAndLockVersion(): void
{
$entity = new stdClass();

$this->wrappedEntityManager
->expects(self::once())
->method('find')
->with(stdClass::class, 1, LockMode::PESSIMISTIC_WRITE, 2)
->willReturn($entity);

self::assertSame(
$entity,
$this->entityManager->find(stdClass::class, 1, LockMode::PESSIMISTIC_WRITE, 2)
);
}

public function testFindWithoutLockArgumentsForwardsNullDefaults(): void
{
$entity = new stdClass();

$this->wrappedEntityManager
->expects(self::once())
->method('find')
->with(stdClass::class, 1, null, null)
->willReturn($entity);

self::assertSame(
$entity,
$this->entityManager->find(stdClass::class, 1)
);
}
}
Loading