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
29 changes: 8 additions & 21 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,20 @@ permissions:

jobs:
test:
name: "linting: php: ${{ matrix.php }} TYPO3: ${{ matrix.typo3 }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '8.3', '8.4']
typo3: [ '12', '13' ]
php: [ '8.3', '8.4', '8.5' ]
typo3: [ '13', '14' ]
steps:
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- uses: actions/checkout@v4

- name: Install dependencies
run: composer install

- name: Update dependencies
run: composer update

- name: Normalize dependencies
run: composer normalize

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: GrumPHP
run: vendor/bin/grumphp run

- name: Run test suite
run: composer test
- uses: actions/checkout@v7
- run: composer update --with=typo3/cms-core:^${{ matrix.typo3 }}
- run: vendor/bin/grumphp run
- run: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var/
vendor/
public/
composer.lock
42 changes: 0 additions & 42 deletions .gitlab-ci.yml

This file was deleted.

19 changes: 8 additions & 11 deletions Classes/Service/DsnService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@ public function __construct(private ?Dsn $dsn = null)

public function provideUrl(string $orgName): string
{
$this->getDsn();

return $this->dsn->getScheme() . '://' . $this->dsn->getHost() . '/api/0/projects/' . $orgName . '/' . $this->dsn->getProjectId() . '/rules/';
$dsn = $this->getDsn();
return $dsn->getScheme() . '://' . $dsn->getHost() . '/api/0/projects/' . $orgName . '/' . $dsn->getProjectId() . '/rules/';
}

public function provideSentry(): string {
$this->getDsn();
return $this->dsn->getScheme() . '://' . $this->dsn->getHost();
public function provideSentry(): string
{
$dsn = $this->getDsn();
return $dsn->getScheme() . '://' . $dsn->getHost();
}

/**
* @return void
*/
public function getDsn(): void
public function getDsn(): Dsn
{
$this->dsn ??= SentrySdk::getCurrentHub()->getClient()?->getOptions()?->getDsn() ??
return $this->dsn ??= SentrySdk::getCurrentHub()->getClient()?->getOptions()?->getDsn() ??
throw new RuntimeException('Sentry is not initialized', 6020020999);
}
}
9 changes: 3 additions & 6 deletions Classes/Xclass/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AUS\SentryCronMonitor\Xclass;

use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use AUS\SentryCronMonitor\Service\DsnService;
use RuntimeException;
use AUS\SentryCronMonitor\Service\AlertService;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function executeTask(AbstractTask $task): bool
? MonitorSchedule::crontab($execution->getCronCmd())
: MonitorSchedule::interval((int) ceil($execution->getInterval() / 60), MonitorScheduleUnit::minute());

$extensionConfiguration = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class);
$extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
$timezone = $extensionConfiguration->get('sentry_cron_monitor', 'timezone');
$monitorConfig = new MonitorConfig($monitorSchedule, timezone: $timezone);

Expand Down Expand Up @@ -74,10 +75,6 @@ private function isSentryReachable(): bool
{
$dsnService = GeneralUtility::makeInstance(DsnService::class);
$url = $dsnService->provideSentry();
if (@fopen($url,"r")) {
return true;
} else {
return false;
}
return (bool) @fopen($url, "r");
}
}
13 changes: 13 additions & 0 deletions Tests/RequestStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace AUS\SentryCronMonitor\Tests;

final class RequestStore
{
/**
* @var list<array{uri: string, method: string, options: array<string, mixed>, context: string|null}>
*/
public array $requests = [];
}
17 changes: 17 additions & 0 deletions Tests/ResponseStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace AUS\SentryCronMonitor\Tests;

use Psr\Http\Message\ResponseInterface;

final class ResponseStore
{
/**
* @param array<ResponseInterface> $responses
*/
public function __construct(public array $responses)
{
}
}
36 changes: 9 additions & 27 deletions Tests/TestingRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,19 @@

namespace AUS\SentryCronMonitor\Tests;

use Override;
use Exception;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Information\Typo3Version;

final class TestingRequestFactory extends RequestFactory
{
/**
* @var list<array{uri: string, method: string, options: array<string, mixed>, context: string|null}>
*/
public array $requests = [];

/**
* @param array<ResponseInterface> $responses
*/
public function __construct(private array $responses)
if ((new Typo3Version())->getMajorVersion() >= 14) {
// phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
final readonly class TestingRequestFactory extends RequestFactory
{
use TestingRequestFactoryTrait;
}

/**
* @param array<string, string>|array<string, mixed> $options
*/
#[Override]
public function request(string $uri, string $method = 'GET', array $options = [], ?string $context = null): ResponseInterface
} else {
// phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
final class TestingRequestFactory extends RequestFactory
{
$this->requests[] = [
'uri' => $uri,
'method' => $method,
'options' => $options,
'context' => $context,
];
return array_shift($this->responses) ?? throw new Exception('to many requests made for this test.', 3414962574);
use TestingRequestFactoryTrait;
}
}
41 changes: 41 additions & 0 deletions Tests/TestingRequestFactoryTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace AUS\SentryCronMonitor\Tests;

use Exception;
use Override;
use Psr\Http\Message\ResponseInterface;

use function array_shift;

trait TestingRequestFactoryTrait
{
public readonly RequestStore $requestStore;

private readonly ResponseStore $responseStore;

/**
* @param array<ResponseInterface> $responses
*/
public function __construct(array $responses)
{
$this->requestStore = new RequestStore();
$this->responseStore = new ResponseStore($responses);
}

/**
* @param array<string, string>|array<string, mixed> $options
*/
public function request(string $uri, string $method = 'GET', array $options = [], ?string $context = null): ResponseInterface
{
$this->requestStore->requests[] = [
'uri' => $uri,
'method' => $method,
'options' => $options,
'context' => $context,
];
return array_shift($this->responseStore->responses) ?? throw new Exception('to many requests made for this test.', 3414962574);
}
}
23 changes: 8 additions & 15 deletions Tests/Unit/Service/AlertServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,19 @@ class AlertServiceTest extends TestCase
#[DataProvider('provideCreateAlertData')]
public function createIfNotExists(string $title, array $responses, array $expectedRequests): void
{
$extensionConfiguration = new class extends ExtensionConfiguration {
public function get(string $extension, string $path = ''): mixed
{
Assert::assertEquals($extension, 'sentry_cron_monitor');

return match ($path) {
'integrationIdMsTeams' => 'integrationIdMsTeams',
'teamsChannelName' => 'teamsChannelName',
'orgName' => 'orgName',
'authToken' => 'authToken123',
default => null,
};
}
};
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['sentry_cron_monitor'] = [
'integrationIdMsTeams' => 'integrationIdMsTeams',
'teamsChannelName' => 'teamsChannelName',
'orgName' => 'orgName',
'authToken' => 'authToken123',
];
$extensionConfiguration = new ExtensionConfiguration();
$requestFactory = new TestingRequestFactory($responses);
$dsnService = new DsnService(Dsn::createFromString('https://12345@example.com/42'));
$service = new AlertService($extensionConfiguration, $requestFactory, $dsnService);

$service->createIfNotExists($title);
$this->assertEquals($expectedRequests, $requestFactory->requests, 'The requests made are not as expected');
$this->assertEquals($expectedRequests, $requestFactory->requestStore->requests, 'The requests made are not as expected');
}

public static function provideCreateAlertData(): Generator
Expand Down
46 changes: 0 additions & 46 deletions bitbucket-pipelines.yml

This file was deleted.

23 changes: 15 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
],
"type": "typo3-cms-extension",
"require": {
"sentry/sentry": "^4.15",
"typo3/cms-core": "^12.4 || ^13.4",
"typo3/cms-scheduler": "^12.4 || ^13.4",
"php": "~8.3.0 || ~8.4.0"
"php": "~8.3.0 || ~8.4.0 || ~8.5.0",
"sentry/sentry": "^4.15.2",
"typo3/cms-core": "^13.4 || ^14.3",
"typo3/cms-scheduler": "^13.4 || ^14.3"
},
"require-dev": {
"phpunit/phpunit": "^12.3",
"saschaegerer/phpstan-typo3": "^2.1.1",
"phpunit/phpunit": "^12.5.33",
"pluswerk/grumphp-config": "^10.1.3 || ^11",
"saschaegerer/phpstan-typo3": "^2.1.1 || ^3.1.0",
"ssch/typo3-rector": "^3.6.2",
"typo3/testing-framework": "^9.2",
"andersundsehr/phpstan-git-files": "^10.1.1"
"typo3/testing-framework": "^9.6.1"
},
"autoload": {
"psr-4": {
Expand All @@ -30,11 +30,18 @@
},
"config": {
"allow-plugins": {
"a9f/fractor-extension-installer": true,
"ergebnis/composer-normalize": true,
"phpro/grumphp": true,
"phpstan/extension-installer": true,
"pluswerk/grumphp-config": true,
"typo3/class-alias-loader": true,
"typo3/cms-composer-installers": true
},
"policy": {
"advisories": {
"block": false
}
}
},
"extra": {
Expand Down
Loading