Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CI job to run automatic tests #19

Merged
merged 1 commit into from
Oct 31, 2024
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
90 changes: 90 additions & 0 deletions .github/workflows/backend-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Backend build

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

jobs:
cs-fix:
name: Run code style check
runs-on: "ubuntu-22.04"
strategy:
matrix:
php:
- '8.1'
alongosz marked this conversation as resolved.
Show resolved Hide resolved
steps:
- uses: actions/checkout@v4

- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: 'pdo_sqlite, gd'
tools: cs2pr

- name: Add composer keys for private packagist
run: |
composer config http-basic.updates.ibexa.co $SATIS_NETWORK_KEY $SATIS_NETWORK_TOKEN
composer config github-oauth.github.com $TRAVIS_GITHUB_TOKEN
env:
SATIS_NETWORK_KEY: ${{ secrets.SATIS_NETWORK_KEY }}
SATIS_NETWORK_TOKEN: ${{ secrets.SATIS_NETWORK_TOKEN }}
TRAVIS_GITHUB_TOKEN: ${{ secrets.TRAVIS_GITHUB_TOKEN }}

- uses: ramsey/composer-install@v3
with:
dependency-versions: "highest"

- name: Run code style check
run: composer run-script check-cs -- --format=checkstyle | cs2pr

tests:
name: Tests
runs-on: "ubuntu-22.04"
timeout-minutes: 10

strategy:
fail-fast: false
matrix:
php:
- '7.4'
- '8.2'
- '8.3'

steps:
- uses: actions/checkout@v4

- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: pdo_sqlite, gd
tools: cs2pr

- name: Add composer keys for private packagist
run: |
composer config http-basic.updates.ibexa.co $SATIS_NETWORK_KEY $SATIS_NETWORK_TOKEN
composer config github-oauth.github.com $TRAVIS_GITHUB_TOKEN
env:
SATIS_NETWORK_KEY: ${{ secrets.SATIS_NETWORK_KEY }}
SATIS_NETWORK_TOKEN: ${{ secrets.SATIS_NETWORK_TOKEN }}
TRAVIS_GITHUB_TOKEN: ${{ secrets.TRAVIS_GITHUB_TOKEN }}

- uses: ramsey/composer-install@v3
with:
dependency-versions: "highest"
composer-options: "--prefer-dist --no-progress --no-suggest"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPStan analysis
run: composer run-script phpstan

- name: Run test suite
run: composer run-script --timeout=600 test
19 changes: 13 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"deepl",
"googletranslate"
],
"repositories": [
{
"type": "composer",
"url": "https://updates.ibexa.co"
}
],
"homepage": "https://github.com/ibexa/automated-translation",
"type": "ibexa-bundle",
"authors": [
Expand All @@ -33,15 +39,18 @@
"symfony/http-foundation": "^5.0",
"symfony/event-dispatcher": "^5.0",
"guzzlehttp/guzzle": "^6.3.0",
"ibexa/core": "~4.6.0@dev",
"ibexa/fieldtype-richtext": "~4.6.0@dev",
"ibexa/admin-ui": "~4.6.0@dev"
"ibexa/core": "~4.6.x-dev",
"ibexa/fieldtype-richtext": "~4.6.x-dev",
"ibexa/admin-ui": "~4.6.x-dev"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.2",
"phpmd/phpmd": "^2.6",
"phpunit/phpunit": "^8.5",
"ibexa/code-style": "^1.0",
"ibexa/migrations": "~4.6.x-dev",
"ibexa/fieldtype-page": "~4.6.x-dev",
"ibexa/search": "~4.6.x-dev",
"dg/bypass-finals": "^1.3",
"phpstan/phpstan": "^1.2",
"phpstan/phpstan-phpunit": "^1.0",
Expand Down Expand Up @@ -82,9 +91,7 @@
},
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true
}
"allow-plugins": false
},
"extra": {
"branch-alias": {
Expand Down
47 changes: 16 additions & 31 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,52 +1,37 @@
parameters:
ignoreErrors:
-
message: "#^Access to protected property Ibexa\\\\AdminUi\\\\Form\\\\Data\\\\ContentTranslationData\\:\\:\\$content\\.$#"
count: 4
path: src/bundle/Form/Extension/ContentEditType.php

-
message: "#^Call to method getBlockDefinition\\(\\) on an unknown class Ibexa\\\\FieldTypePage\\\\FieldType\\\\Page\\\\Block\\\\Definition\\\\BlockDefinitionFactory\\.$#"
message: "#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(mixed\\)\\: bool\\)\\|null, Closure\\(mixed\\)\\: \\(array\\|null\\) given\\.$#"
count: 1
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php

-
message: "#^Call to method getPage\\(\\) on an unknown class Ibexa\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Value\\.$#"
count: 2
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php

-
message: "#^Instantiated class Ibexa\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Value not found\\.$#"
count: 2
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php
path: src/bundle/DependencyInjection/IbexaAutomatedTranslationExtension.php

-
message: "#^Method Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\Field\\\\PageBuilderFieldEncoder\\:\\:decode\\(\\) should return Ibexa\\\\Core\\\\FieldType\\\\Value but returns Ibexa\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Value\\.$#"
count: 2
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php
message: "#^Access to protected property Ibexa\\\\AdminUi\\\\Form\\\\Data\\\\ContentTranslationData\\:\\:\\$content\\.$#"
count: 4
path: src/bundle/Form/Extension/ContentEditType.php

-
message: "#^PHPDoc tag @var for variable \\$previousFieldValue contains unknown class Ibexa\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Value\\.$#"
message: "#^Parameter \\#3 \\$remoteServiceKey of method Ibexa\\\\AutomatedTranslation\\\\Translator\\:\\:getTranslatedFields\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php
path: src/bundle/Form/Extension/ContentEditType.php

-
message: "#^PHPDoc tag @var for variable \\$value contains unknown class Ibexa\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Value\\.$#"
message: "#^Cannot call method setValue\\(\\) on Ibexa\\\\Contracts\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Model\\\\Attribute\\|null\\.$#"
count: 1
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php

-
message: "#^Parameter \\$blockDefinitionFactory of method Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\Field\\\\PageBuilderFieldEncoder\\:\\:__construct\\(\\) has invalid type Ibexa\\\\FieldTypePage\\\\FieldType\\\\Page\\\\Block\\\\Definition\\\\BlockDefinitionFactory\\.$#"
message: "#^Parameter \\#1 \\$type of method Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\Field\\\\PageBuilderFieldEncoder\\:\\:canDecode\\(\\) expects string, class\\-string\\|false given\\.$#"
count: 1
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php
path: tests/lib/Encoder/Field/PageBuilderFieldEncoderTest.php

-
message: "#^Property Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\Field\\\\PageBuilderFieldEncoder\\:\\:\\$blockDefinitionFactory has unknown class Ibexa\\\\FieldTypePage\\\\FieldType\\\\Page\\\\Block\\\\Definition\\\\BlockDefinitionFactory as its type\\.$#"
count: 1
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\MockObject\\\\MockBuilder\\<Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\RichText\\\\RichTextEncoder\\>\\:\\:getMock\\(\\) contains unresolvable type\\.$#"
count: 2
path: tests/lib/Encoder/Field/RichTextFieldEncoderTest.php

-
message: "#^Parameter \\#1 \\$function of function call_user_func_array expects callable\\(\\)\\: mixed, array\\{Ibexa\\\\Bundle\\\\AutomatedTranslation\\\\DependencyInjection\\\\IbexaAutomatedTranslationExtension, mixed\\} given\\.$#"
count: 1
path: tests/bundle/DependencyInjection/IbexaAutomatedTranslationExtensionTest.php
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\MockObject\\\\MockBuilder\\<Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\Field\\\\FieldEncoderManager\\>\\:\\:getMock\\(\\) contains unresolvable type\\.$#"
count: 2
path: tests/lib/EncoderTest.php

14 changes: 5 additions & 9 deletions src/bundle/EventListener/ContentProxyTranslateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@

class ContentProxyTranslateListener implements EventSubscriberInterface
{
/** @var \Symfony\Component\HttpFoundation\RequestStack */
private $requestStack;
private RequestStack $requestStack;

/** @var \Ibexa\AutomatedTranslation\Translator */
private $translator;
private Translator $translator;

/** @var \Ibexa\Contracts\Core\Repository\ContentService */
private $contentService;
private ContentService $contentService;

/** @var \Symfony\Component\Routing\RouterInterface */
private $router;
private RouterInterface $router;

public function __construct(
RequestStack $requestStack,
Expand Down Expand Up @@ -74,7 +70,7 @@ public function translate(ContentProxyTranslateEvent $event): void
$contentDraft = $this->translator->getTranslatedContent(
$fromLanguageCode,
$toLanguageCode,
$request->query->get('translatorAlias'),
$request->query->get('translatorAlias') ?? '',
$content
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

use InvalidArgumentException;

final class BlockAttributeEncoderManager
/**
* @final
*/
class BlockAttributeEncoderManager
{
/** @var iterable|\Ibexa\Contracts\AutomatedTranslation\Encoder\BlockAttribute\BlockAttributeEncoderInterface[] */
private $blockAttributeEncoders;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Encoder/Field/PageBuilderFieldEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Field;
use Ibexa\Core\FieldType\Value as APIValue;
use Ibexa\FieldTypePage\FieldType\LandingPage\Value;
use Ibexa\FieldTypePage\FieldType\Page\Block\Definition\BlockDefinitionFactory;
use Ibexa\FieldTypePage\FieldType\Page\Block\Definition\BlockDefinitionFactoryInterface;
use InvalidArgumentException;
use Symfony\Component\Serializer\Encoder\XmlEncoder;

Expand All @@ -24,11 +24,11 @@ final class PageBuilderFieldEncoder implements FieldEncoderInterface

private BlockAttributeEncoderManager $blockAttributeEncoderManager;

private BlockDefinitionFactory $blockDefinitionFactory;
private BlockDefinitionFactoryInterface $blockDefinitionFactory;

public function __construct(
BlockAttributeEncoderManager $blockAttributeEncoderManager,
BlockDefinitionFactory $blockDefinitionFactory
BlockDefinitionFactoryInterface $blockDefinitionFactory
) {
$this->blockAttributeEncoderManager = $blockAttributeEncoderManager;
$this->blockDefinitionFactory = $blockDefinitionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class IbexaAutomatedTranslationExtensionTest extends TestCase
final class IbexaAutomatedTranslationExtensionTest extends TestCase
{
/**
* @return array{array{array{system: array{default: array{configurations: array{}}}}, bool}}
Expand Down Expand Up @@ -63,7 +63,8 @@ public function clientConfigurationDataProvider(): array
}

/**
* @param array<mixed> $input
* @param array{system: array{configurations: mixed}} $input
*
* @dataProvider clientConfigurationDataProvider
*/
public function testHasConfiguredClients(array $input, bool $expected): void
Expand All @@ -73,21 +74,20 @@ public function testHasConfiguredClients(array $input, bool $expected): void
->getMock();

$containerMock
->expects($this->any())
->method('resolveEnvPlaceholders')
->withConsecutive(['value1'], ['value2'], ['ENV_TEST1'])
->willReturnOnConsecutiveCalls(['value1'], ['value2'], ['test1']);

$subject = new IbexaAutomatedTranslationExtension();

// call for private method hasConfiguredClients on $subject object
$hasConfiguredClientsResult = call_user_func_array(\Closure::bind(
function ($method, $params) {
return call_user_func_array([$this, $method], $params);
$hasConfiguredClientsResult = (\Closure::bind(
function () use ($input, $containerMock): bool {
return $this->hasConfiguredClients($input, $containerMock);
},
$subject,
IbexaAutomatedTranslationExtension::class
), ['hasConfiguredClients', [$input, $containerMock]]);
))();

$this->assertEquals($expected, $hasConfiguredClientsResult);
}
Expand Down
10 changes: 6 additions & 4 deletions tests/lib/Encoder/Field/PageBuilderFieldEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,26 @@
use Ibexa\Contracts\FieldTypePage\FieldType\LandingPage\Model\BlockValue;
use Ibexa\Contracts\FieldTypePage\FieldType\LandingPage\Model\Page;
use Ibexa\Contracts\FieldTypePage\FieldType\LandingPage\Model\Zone;
use Ibexa\Contracts\FieldTypePage\FieldType\LandingPage\Value;
use Ibexa\Contracts\FieldTypePage\FieldType\Page\Block\Definition\BlockAttributeDefinition;
use Ibexa\Contracts\FieldTypePage\FieldType\Page\Block\Definition\BlockDefinition;
use Ibexa\Contracts\FieldTypePage\FieldType\Page\Block\Definition\BlockDefinitionFactory;
use Ibexa\FieldTypePage\FieldType\LandingPage\Value;
use Ibexa\FieldTypePage\FieldType\Page\Block\Definition\BlockDefinitionFactoryInterface;
use PHPUnit\Framework\TestCase;

final class PageBuilderFieldEncoderTest extends TestCase
{
public const ATTRIBUTE_VALUE = 'ibexa';

/** @var \Ibexa\AutomatedTranslation\Encoder\BlockAttribute\BlockAttributeEncoderManager&\PHPUnit\Framework\MockObject\MockObject */
private BlockAttributeEncoderManager $blockAttributeEncoderManagerMock;

private BlockDefinitionFactory $blockDefinitionFactoryMock;
/** @var \Ibexa\FieldTypePage\FieldType\Page\Block\Definition\BlockDefinitionFactoryInterface&\PHPUnit\Framework\MockObject\MockObject */
private BlockDefinitionFactoryInterface $blockDefinitionFactoryMock;

public function setUp(): void
{
$this->blockAttributeEncoderManagerMock = $this->createMock(BlockAttributeEncoderManager::class);
$this->blockDefinitionFactoryMock = $this->createMock(BlockDefinitionFactory::class);
$this->blockDefinitionFactoryMock = $this->createMock(BlockDefinitionFactoryInterface::class);
}

public function testEncode(): void
Expand Down
Loading