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
12 changes: 6 additions & 6 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4

- name: Download dependencies
uses: ramsey/composer-install@v3
uses: ramsey/composer-install@v4

- name: Install PHPStan
uses: ramsey/composer-install@v3
uses: ramsey/composer-install@v4
with:
working-directory: "tools/phpstan"

Expand All @@ -36,7 +36,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4

- name: Install php-cs-fixer
uses: ramsey/composer-install@v3
Expand All @@ -57,7 +57,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4

- name: Download dependencies
uses: ramsey/composer-install@v3
Expand Down
43 changes: 19 additions & 24 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,40 @@ name: PHPUnit
jobs:
tests:
name: Tests
runs-on: Ubuntu-20.04
runs-on: ubuntu-latest

strategy:
matrix:
include:
# Lowest Deps
- php: 8.3
symfony-version: 7.1.*
composer-flags: '--prefer-stable --ignore-platform-req=php+'
# Active release
- php: 8.4
symfony-version: 7.1.*
composer-flags: '--prefer-stable --ignore-platform-req=php+'
- php: 8.4
symfony-version: 7.2.*
composer-flags: '--prefer-stable --ignore-platform-req=php+'
- php: 8.4
symfony-version: 7.3.*
composer-flags: '--prefer-stable --ignore-platform-req=php+'
fail-fast: false
matrix:
php: [ 8.4, 8.5 ]
symfony: [ 7.4.*, 8.0.*, 8.1.* ]

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Setup PHP
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Configure Composer minimum stability
if: matrix.stability
run: composer config minimum-stability ${{ matrix.stability }}
- name: Cache Composer
uses: actions/cache@v5
with:
path: ~/.cache/composer
key: composer-${{ matrix.php }}-sf${{ matrix.symfony }}-${{ hashFiles('composer.json') }}
restore-keys: composer-${{ matrix.php }}-sf${{ matrix.symfony }}-

- name: Activate Symfony Flex
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require --no-progress --no-scripts --no-plugins symfony/flex

- name: Install dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-require }}
run: composer update ${{ matrix.composer-flags }} --no-interaction --no-progress --optimize-autoloader
SYMFONY_REQUIRE: ${{ matrix.symfony }}
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: Run PHPUnit
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.php_cs.cache
.phpunit.cache
/composer.lock
/vendor
/tools/**/vendor
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
}
],
"require": {
"php": "^8.2",
"symfony/config": "^5.4|^6.4|^7.0",
"symfony/console": "^5.4|^6.4|^7.0",
"symfony/dependency-injection": "^5.4|^6.4|^7.0",
"symfony/event-dispatcher": "^5.4|^6.4|^7.0",
"symfony/http-kernel": "^5.4|^6.4|^7.0"
"php": "^8.4",
"symfony/config": "^7.4|^8.0",
"symfony/console": "^7.4|^8.0",
"symfony/dependency-injection": "^7.4|^8.0",
"symfony/event-dispatcher": "^7.4|^8.0",
"symfony/http-kernel": "^7.4|^8.0"
},
"require-dev": {
"matthiasnoback/symfony-dependency-injection-test": "^5.1",
"symfony/framework-bundle": "^5.4|^6.4|^7.0",
"symfony/phpunit-bridge": "^7.1",
"matthiasnoback/symfony-dependency-injection-test": "^6.3",
"symfony/framework-bundle": "^7.4|^8.0",
"symfony/phpunit-bridge": "^7.4|^8.0",
"twig/twig": "^3.10",
"monolog/monolog": "^3.0",
"phpunit/phpunit": "^9.6"
"phpunit/phpunit": "^11.5"
},
"autoload": {
"psr-4": { "Tiime\\NewRelicBundle\\": "src/" }
Expand Down
28 changes: 6 additions & 22 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<testsuites>
<testsuite name="Tiime New Relic Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Tiime New Relic Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 4 additions & 4 deletions src/Command/NotifyDeploymentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

class NotifyDeploymentCommand extends Command
{
public const EXIT_NO_APP_NAMES = 1;
public const EXIT_UNAUTHORIZED = 2;
public const EXIT_HTTP_ERROR = 3;
public const int EXIT_NO_APP_NAMES = 1;
public const int EXIT_UNAUTHORIZED = 2;
public const int EXIT_HTTP_ERROR = 3;

public function __construct(private Config $newrelic)
public function __construct(private readonly Config $newrelic)
{
parent::__construct('newrelic:notify-deployment');
}
Expand Down
26 changes: 13 additions & 13 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function getConfigTreeBuilder(): TreeBuilder
->prototype('scalar')
->end()
->beforeNormalization()
->ifTrue(function ($v) { return !\is_array($v); })
->then(function ($v) { return array_values(array_filter(explode(';', (string) $v))); })
->ifTrue(static fn ($v) => !\is_array($v))
->then(static fn ($v) => array_values(array_filter(explode(';', (string) $v))))
->end()
->end()
->scalarNode('xmit')->defaultValue(false)->end()
Expand All @@ -56,8 +56,8 @@ public function getConfigTreeBuilder(): TreeBuilder
->prototype('scalar')
->end()
->beforeNormalization()
->ifTrue(function ($v) { return !\is_array($v); })
->then(function ($v) { return (array) $v; })
->ifTrue(static fn ($v) => !\is_array($v))
->then(static fn ($v) => (array) $v)
->end()
->end()
->end()
Expand All @@ -80,16 +80,16 @@ public function getConfigTreeBuilder(): TreeBuilder
->prototype('scalar')
->end()
->beforeNormalization()
->ifTrue(function ($v) { return !\is_array($v); })
->then(function ($v) { return (array) $v; })
->ifTrue(static function ($v) { return !\is_array($v); })
->then(static function ($v) { return (array) $v; })
->end()
->end()
->arrayNode('ignored_paths')
->prototype('scalar')
->end()
->beforeNormalization()
->ifTrue(function ($v) { return !\is_array($v); })
->then(function ($v) { return (array) $v; })
->ifTrue(static function ($v) { return !\is_array($v); })
->then(static function ($v) { return (array) $v; })
->end()
->end()
->scalarNode('using_symfony_cache')->defaultFalse()->end()
Expand All @@ -106,18 +106,18 @@ public function getConfigTreeBuilder(): TreeBuilder
->canBeUnset()
->beforeNormalization()
->ifString()
->then(function ($v) { return ['elements' => [$v]]; })
->then(static fn ($v) => ['elements' => [$v]])
->end()
->beforeNormalization()
->ifTrue(function ($v) { return \is_array($v) && is_numeric(key($v)); })
->then(function ($v) { return ['elements' => $v]; })
->ifTrue(static fn ($v) => \is_array($v) && is_numeric(key($v)))
->then(static fn ($v) => ['elements' => $v])
->end()
->validate()
->ifTrue(function ($v) { return empty($v); })
->ifTrue(static fn ($v) => empty($v))
->thenUnset()
->end()
->validate()
->always(function ($v) {
->always(static function ($v) {
$isExclusive = null;
if (isset($v['type'])) {
$isExclusive = 'exclusive' === $v['type'];
Expand Down
13 changes: 5 additions & 8 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Tiime\NewRelicBundle\Tests\DependencyInjection;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Definition\PrototypedArrayNode;
Expand Down Expand Up @@ -142,9 +143,8 @@ public static function deploymentNamesProvider(): array
/**
* @param string|string[] $deploymentNameConfig
* @param string[] $expected
*
* @dataProvider deploymentNamesProvider
*/
#[DataProvider('deploymentNamesProvider')]
public function testDeploymentNames(string|array $deploymentNameConfig, array $expected): void
{
$processor = new Processor();
Expand All @@ -159,9 +159,8 @@ public function testDeploymentNames(string|array $deploymentNameConfig, array $e
/**
* @param string|string[] $ignoredRoutesConfig
* @param string[] $expected
*
* @dataProvider ignoredRoutesProvider
*/
#[DataProvider('ignoredRoutesProvider')]
public function testIgnoreRoutes(string|array $ignoredRoutesConfig, array $expected): void
{
$processor = new Processor();
Expand All @@ -174,9 +173,8 @@ public function testIgnoreRoutes(string|array $ignoredRoutesConfig, array $expec
/**
* @param string|string[] $ignoredPathsConfig
* @param string[] $expected
*
* @dataProvider ignoredPathsProvider
*/
#[DataProvider('ignoredPathsProvider')]
public function testIgnorePaths(string|array $ignoredPathsConfig, array $expected): void
{
$processor = new Processor();
Expand All @@ -189,9 +187,8 @@ public function testIgnorePaths(string|array $ignoredPathsConfig, array $expecte
/**
* @param string|string[] $ignoredCommandsConfig
* @param string[] $expected
*
* @dataProvider ignoredCommandsProvider
*/
#[DataProvider('ignoredCommandsProvider')]
public function testIgnoreCommands(string|array $ignoredCommandsConfig, array $expected): void
{
$processor = new Processor();
Expand Down
28 changes: 23 additions & 5 deletions tests/Listener/CommandListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public function testCommandMarkedAsBackgroundJob(): void
$interactor->expects($this->once())->method('setTransactionName')->with($this->equalTo('test:newrelic'));
$interactor->expects($this->once())->method('enableBackgroundJob');

$interactor->expects($this->exactly(4))->method('addCustomParameter')->withConsecutive(
['--foo', true],
['--foobar[0]', 'baz'],
['--foobar[1]', 'baz_2'],
['name', 'bar']
$interactor->expects($this->exactly(4))->method('addCustomParameter')->willReturnCallback(
$this->sequentialAssertionCallback([
['--foo', true],
['--foobar[0]', 'baz'],
['--foobar[1]', 'baz_2'],
['name', 'bar'],
], true)
);

$command = new Command('test:newrelic');
Expand Down Expand Up @@ -114,4 +116,20 @@ public function testConsoleErrorsWithThrowable(): void
$listener = new CommandListener($newrelic, $interactor, ['test:exception']);
$listener->onConsoleError($event);
}

/**
* @param array<int, array<int, mixed>> $expectedCalls
*/
private function sequentialAssertionCallback(array $expectedCalls, mixed $returnValue = null): \Closure
{
$index = 0;

return static function (...$arguments) use (&$index, $expectedCalls, $returnValue): mixed {
self::assertArrayHasKey($index, $expectedCalls);
self::assertSame($expectedCalls[$index], $arguments);
++$index;

return $returnValue;
};
}
}
12 changes: 8 additions & 4 deletions tests/Listener/DeprecationListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function testDeprecationIsReported(): void

$listener = new DeprecationListener($interactor);

set_error_handler(function () { return false; });
set_error_handler(static fn () => false);

try {
$listener->register();
@trigger_error('This is a deprecation', \E_USER_DEPRECATED);
Expand All @@ -44,7 +45,8 @@ public function testDeprecationIsReportedRegardlessErrorReporting(): void

$listener = new DeprecationListener($interactor);

set_error_handler(function () { return false; });
set_error_handler(static fn () => false);

$e = error_reporting(0);
try {
$listener->register();
Expand All @@ -63,7 +65,8 @@ public function testOtherErrorAreIgnored(): void

$listener = new DeprecationListener($interactor);

set_error_handler(function () { return false; });
set_error_handler(static fn () => false);

try {
$listener->register();
@trigger_error('This is a notice', \E_USER_NOTICE);
Expand Down Expand Up @@ -100,7 +103,8 @@ public function testUnregisterRemovesHandler(): void

$listener = new DeprecationListener($interactor);

set_error_handler(function () { return false; });
set_error_handler(static fn () => false);

try {
$listener->register();
$listener->unregister();
Expand Down
4 changes: 1 addition & 3 deletions tests/Listener/RequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public function testMasterRequest(): void
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();
$interactor->expects($this->once())->method('setTransactionName');

$namingStrategy = $this->getMockBuilder(TransactionNamingStrategyInterface::class)
->setMethods(['getTransactionName'])
->getMock();
$namingStrategy = $this->getMockBuilder(TransactionNamingStrategyInterface::class)->getMock();
$namingStrategy->expects($this->once())->method('getTransactionName')->willReturn('foobar');

$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
Expand Down
Loading
Loading