Skip to content
Closed
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
45 changes: 17 additions & 28 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,26 @@ jobs:
matrix:
php:
- '7.4'
- '8.0'
- '8.1'
- '8.3'
- '8.4'
composer_options: [ "" ]

steps:
- uses: actions/checkout@v2

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

- uses: "ramsey/composer-install@v1"
- uses: ibexa/gh-workflows/actions/composer-install@main
with:
dependency-versions: "highest"
composer-options: "${{ matrix.composer_options }}"
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: 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

Expand All @@ -52,22 +49,14 @@ jobs:
php:
- '8.1'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

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

- uses: "ramsey/composer-install@v1"
with:
dependency-versions: "highest"
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

- name: Run PHPStan analysis
run: composer run-script phpstan
46 changes: 0 additions & 46 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -276,30 +276,6 @@ parameters:
count: 1
path: src/bundle/Initializer/BehatSiteAccessInitializer.php

-
message: '#^Call to an undefined method Behat\\Gherkin\\Node\\ScenarioLikeInterface\:\:hasTag\(\)\.$#'
identifier: method.notFound
count: 1
path: src/bundle/Subscriber/StartScenarioSubscriber.php

-
message: '#^Cannot call method isStarted\(\) on object\|null\.$#'
identifier: method.nonObject
count: 1
path: src/bundle/Subscriber/StartScenarioSubscriber.php

-
message: '#^Cannot call method resizeWindow\(\) on object\|null\.$#'
identifier: method.nonObject
count: 1
path: src/bundle/Subscriber/StartScenarioSubscriber.php

-
message: '#^Cannot call method start\(\) on object\|null\.$#'
identifier: method.nonObject
count: 1
path: src/bundle/Subscriber/StartScenarioSubscriber.php

-
message: '#^Method Ibexa\\Behat\\API\\ContentData\\ContentDataProvider\:\:addFieldTypeDataProvider\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -864,12 +840,6 @@ parameters:
count: 1
path: src/lib/API/Context/ContentTypeContext.php

-
message: '#^Parameter \#1 \$array \(list\<string\>\) of array_values is already a list, call has no effect\.$#'
identifier: arrayValues.list
count: 1
path: src/lib/API/Context/ContentTypeContext.php

-
message: '#^Method Ibexa\\Behat\\API\\Context\\LanguageContext\:\:createLanguageIfNotExists\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -2148,11 +2118,6 @@ parameters:
count: 1
path: src/lib/Browser/FileUpload/FileUploadHelper.php

-
message: '#^Parameter \#1 \$string of function base64_encode expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: src/lib/Browser/FileUpload/FileUploadHelper.php

-
message: '#^Method Ibexa\\Behat\\Browser\\Filter\\BrowserLogFilter\:\:filter\(\) has parameter \$logEntries with no value type specified in iterable type array\.$#'
Expand Down Expand Up @@ -2304,12 +2269,6 @@ parameters:
count: 1
path: src/lib/Browser/Routing/Router.php

-
message: '#^Access to an undefined property Ibexa\\Behat\\Core\\Behat\\ArgumentParser\:\:\$roleFacade\.$#'
identifier: property.notFound
count: 2
path: src/lib/Core/Behat/ArgumentParser.php

-
message: '#^Method Ibexa\\Behat\\Core\\Behat\\ArgumentParser\:\:parseLimitations\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down Expand Up @@ -2838,11 +2797,6 @@ parameters:
count: 1
path: src/lib/Core/Log/LogFileReader.php

-
message: '#^Cannot call method execute\(\) on Facebook\\WebDriver\\Remote\\RemoteWebDriver\|null\.$#'
identifier: method.nonObject
count: 1
path: src/lib/Core/Log/TestLogProvider.php

-
message: '#^Method Ibexa\\Behat\\Core\\Log\\TestLogProvider\:\:cacheLogs\(\) has parameter \$logs with no value type specified in iterable type array\.$#'
Expand Down
53 changes: 1 addition & 52 deletions src/bundle/Subscriber/StartScenarioSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,12 @@
use Behat\Behat\EventDispatcher\Event\BeforeScenarioTested;
use Behat\Behat\EventDispatcher\Event\ExampleTested;
use Behat\Behat\EventDispatcher\Event\ScenarioTested;
use Facebook\WebDriver\Exception\UnknownErrorException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class StartScenarioSubscriber implements EventSubscriberInterface
{
private const RETRY_LIMIT = 2;

public const PRIORITY = -1000;

private KernelInterface $kernel;

private int $width;

private int $height;

public function __construct(KernelInterface $kernel, int $width, int $height)
{
$this->kernel = $kernel;
$this->width = $width;
$this->height = $height;
}

public static function getSubscribedEvents()
{
return [
Expand All @@ -44,40 +27,6 @@ public static function getSubscribedEvents()

public function resizeWindow(BeforeScenarioTested $event): void
{
if (!$event->getScenario()->hasTag('javascript') && !$event->getFeature()->hasTag('javascript')) {
return;
}

$session = $this->kernel->getContainer()->get('behat.mink.default_session');
if (!$session->isStarted()) {
$session->start();
}

$this->executeWithRetry(function () use ($session): void {
$session->resizeWindow($this->width, $this->height);
});
}

/**
* @template T
*
* @param callable(mixed ...$args): T $fn
*
* @return T
*/
private function executeWithRetry(callable $fn)
{
$counter = 0;
while (true) {
try {
return $fn();
} catch (UnknownErrorException $e) {
if ($counter > self::RETRY_LIMIT) {
throw $e;
}
++$counter;
usleep(100000 * 2 ** $counter);
}
}
// No usages, so simplest fix is to remove the function
}
}
2 changes: 1 addition & 1 deletion src/lib/API/Context/ContentTypeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function parseSelectionSettings(string $settings): array
$fields = explode(',', $settings);
$isMultiple = $this->parseBool(explode(':', $fields[0])[1]);
$options = explode(':', $fields[1])[1];
$parsedOptions = array_values(explode('-', $options));
$parsedOptions = explode('-', $options);
$parsedSettings['isMultiple'] = $isMultiple;
$parsedSettings['options'] = $parsedOptions;

Expand Down
11 changes: 9 additions & 2 deletions src/lib/Browser/Component/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
use Ibexa\Behat\Browser\Locator\LocatorInterface;
use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException;
use OAndreyev\Mink\Driver\WebDriver;
use RuntimeException;

class DevToolsDriverUnavailableException extends \RuntimeException
{
}

abstract class Component implements ComponentInterface
{
Expand Down Expand Up @@ -79,7 +82,11 @@ protected function getDevToolsDriver(): ChromeDevToolsDriver
$webDriver = $driver->getWebDriver();

if (null === $webDriver) {
throw new RuntimeException('Error happened when accessing the WebDriver');
throw new DevToolsDriverUnavailableException('Error happened when accessing the WebDriver');
}

if (!($webDriver instanceof \Facebook\WebDriver\Remote\RemoteWebDriver)) {
throw new DevToolsDriverUnavailableException('Expected instance of Facebook\\WebDriver\\Remote\\RemoteWebDriver, got ' . (is_object($webDriver) ? get_class($webDriver) : gettype($webDriver)));
}

return new ChromeDevToolsDriver($webDriver);
Expand Down
13 changes: 11 additions & 2 deletions src/lib/Browser/FileUpload/FileUploadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
use Behat\Mink\Session;
use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters;

class FileReadException extends \RuntimeException
{
}

class FileUploadHelper
{
/** @var \Behat\Mink\Session */
Expand All @@ -32,12 +36,17 @@ public function getRemoteFileUploadPath($filename)
$driver = $this->session->getDriver();

if ($driver instanceof Selenium2Driver) {
if (!preg_match('#[\w\\\/\.]*\.zip$#', $filename)) {
if (!preg_match('#[\w/.]*\.zip$#', $filename)) {
throw new \InvalidArgumentException('Zip archive required to upload to remote browser machine.');
}

$fileContents = file_get_contents($localFile);
if ($fileContents === false) {
throw new FileReadException("Failed to read file: $localFile");
}

return $driver->getWebDriverSession()->file([
'file' => base64_encode(file_get_contents($localFile)),
'file' => base64_encode($fileContents),
]);
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib/Core/Behat/ArgumentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class ArgumentParser
/** @var \Ibexa\Behat\Browser\Environment\ParameterProviderInterface */
private $parameterProvider;

/** @var \Ibexa\Behat\API\Facade\RoleFacade */
private $roleFacade;

public function __construct(RoleFacade $roleFacade, ParameterProviderInterface $parameterProvider)
{
$this->roleFacade = $roleFacade;
Expand Down
10 changes: 8 additions & 2 deletions src/lib/Core/Log/TestLogProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace Ibexa\Behat\Core\Log;

use Behat\Mink\Session;
use Facebook\WebDriver\Remote\DriverCommand;
use Ibexa\Behat\Browser\Filter\BrowserLogFilter;
use OAndreyev\Mink\Driver\WebDriver;

Expand Down Expand Up @@ -57,7 +56,14 @@ public function getBrowserLogs(): array

private function getSeleniumLog(WebDriver $driver): array
{
return $driver->getWebDriver()->execute(DriverCommand::GET_LOG, ['type' => 'browser']) ?? [];
$webDriver = $driver->getWebDriver();
if (is_object($webDriver) && method_exists($webDriver, 'getLog')) {
return $webDriver->getLog('browser') ?? [];
}

// Log a warning or handle gracefully if getLog is not available
// error_log('WebDriver does not support getLog method.');
return [];
}

public function getApplicationLogs(): array
Expand Down
Loading