Skip to content

Commit

Permalink
Added CI job to run automatic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Oct 31, 2024
1 parent 2485d26 commit ba93b2c
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 48 deletions.
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'
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
54 changes: 32 additions & 22 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(mixed\\)\\: bool\\)\\|null, Closure\\(mixed\\)\\: \\(array\\|null\\) given\\.$#"
count: 1
path: src/bundle/DependencyInjection/IbexaAutomatedTranslationExtension.php

-
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 \\#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: "#^Call to method getPage\\(\\) on an unknown class Ibexa\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Value\\.$#"
count: 2
message: "#^Cannot call method setValue\\(\\) on Ibexa\\\\Contracts\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Model\\\\Attribute\\|null\\.$#"
count: 1
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
message: "#^Call to an undefined method Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\BlockAttribute\\\\BlockAttributeEncoderManager\\:\\:expects\\(\\)\\.$#"
count: 1
path: tests/lib/Encoder/Field/PageBuilderFieldEncoderTest.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: "#^Call to an undefined method Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\BlockAttribute\\\\BlockAttributeEncoderManager\\:\\:method\\(\\)\\.$#"
count: 1
path: tests/lib/Encoder/Field/PageBuilderFieldEncoderTest.php

-
message: "#^PHPDoc tag @var for variable \\$previousFieldValue contains unknown class Ibexa\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Value\\.$#"
message: "#^Call to an undefined method Ibexa\\\\FieldTypePage\\\\FieldType\\\\Page\\\\Block\\\\Definition\\\\BlockDefinitionFactoryInterface\\:\\:method\\(\\)\\.$#"
count: 1
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php
path: tests/lib/Encoder/Field/PageBuilderFieldEncoderTest.php

-
message: "#^PHPDoc tag @var for variable \\$value contains unknown class Ibexa\\\\FieldTypePage\\\\FieldType\\\\LandingPage\\\\Value\\.$#"
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: "#^Parameter \\$blockDefinitionFactory of method Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\Field\\\\PageBuilderFieldEncoder\\:\\:__construct\\(\\) has invalid type Ibexa\\\\FieldTypePage\\\\FieldType\\\\Page\\\\Block\\\\Definition\\\\BlockDefinitionFactory\\.$#"
count: 1
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php
message: "#^Parameter \\#2 \\$blockDefinitionFactory of class Ibexa\\\\AutomatedTranslation\\\\Encoder\\\\Field\\\\PageBuilderFieldEncoder constructor expects Ibexa\\\\FieldTypePage\\\\FieldType\\\\Page\\\\Block\\\\Definition\\\\BlockDefinitionFactory, Ibexa\\\\FieldTypePage\\\\FieldType\\\\Page\\\\Block\\\\Definition\\\\BlockDefinitionFactoryInterface given\\.$#"
count: 4
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\\.$#"
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
count: 1
path: src/lib/Encoder/Field/PageBuilderFieldEncoder.php
path: tests/lib/Encoder/Field/PageBuilderFieldEncoderTest.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\\\\RichText\\\\RichTextEncoder\\>\\:\\:getMock\\(\\) contains unresolvable type\\.$#"
count: 2
path: tests/lib/Encoder/Field/RichTextFieldEncoderTest.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 @@ -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
8 changes: 4 additions & 4 deletions tests/lib/Encoder/Field/PageBuilderFieldEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
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
Expand All @@ -27,12 +27,12 @@ final class PageBuilderFieldEncoderTest extends TestCase

private BlockAttributeEncoderManager $blockAttributeEncoderManagerMock;

private BlockDefinitionFactory $blockDefinitionFactoryMock;
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

0 comments on commit ba93b2c

Please sign in to comment.