Skip to content

Clean up impossible test conditions and fix broken CI #787

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

Merged
merged 5 commits into from
Nov 30, 2023
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
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ parameters:
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Parameter \\#2 \\$callback of function array_filter expects callable\\(mixed\\)\\: mixed, Closure\\(string\\)\\: bool given\\.$#"
message: "#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: bool given\\.$#"
count: 1
path: src/DependencyInjection/SentryExtension.php

Expand Down
4 changes: 4 additions & 0 deletions tests/End2End/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
$loader->load(__DIR__ . '/deprecations_for_6.yml');
}

if (self::VERSION_ID >= 60400) {
$loader->load(__DIR__ . '/deprecations_for_64.yml');
}

if (interface_exists(MessageBusInterface::class) && self::VERSION_ID >= 40300) {
$loader->load(__DIR__ . '/messenger.yml');
}
Expand Down
3 changes: 3 additions & 0 deletions tests/End2End/App/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ framework:
router: { resource: "%routing_config_dir%/routing.yml" }
secret: secret
test: ~
annotations: false
php_errors:
log: true

services:
test.hub:
Expand Down
2 changes: 2 additions & 0 deletions tests/End2End/App/deprecations_for_64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
framework:
handle_all_throwables: true
43 changes: 19 additions & 24 deletions tests/Integration/RequestFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

declare(strict_types=1);

namespace Sentry\SentryBundle\Test\Integration;
namespace Sentry\SentryBundle\Tests\Integration;

use GuzzleHttp\Psr7\ServerRequest;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -37,24 +36,36 @@ protected function setUp(): void
$this->requestFetcher = new RequestFetcher($this->requestStack, $this->httpMessageFactory);
}

/**
* @dataProvider fetchRequestDataProvider
*/
public function testFetchRequest(?Request $request, ?ServerRequestInterface $expectedRequest): void
public function testFetchRequest(): void
{
$request = Request::create('https://www.example.com');
$expectedRequest = $this->createMock(ServerRequestInterface::class);

$this->requestStack->expects($this->once())
->method('getCurrentRequest')
->willReturn($request);

$this->httpMessageFactory->expects(null !== $expectedRequest ? $this->once() : $this->never())
$this->httpMessageFactory->expects($this->once())
->method('createRequest')
->with($request)
->willReturn($expectedRequest);

$this->assertSame($expectedRequest, $this->requestFetcher->fetchRequest());
}

public function testFetchRequestFailsSilently(): void
public function testFetchRequestReturnsNullIfTheRequestStackIsEmpty(): void
{
$this->requestStack->expects($this->once())
->method('getCurrentRequest')
->willReturn(null);

$this->httpMessageFactory->expects($this->never())
->method('createRequest');

$this->assertNull($this->requestFetcher->fetchRequest());
}

public function testFetchRequestReturnsNullIfTheRequestFactoryThrowsAnException(): void
{
$this->requestStack->expects($this->once())
->method('getCurrentRequest')
Expand All @@ -66,20 +77,4 @@ public function testFetchRequestFailsSilently(): void

$this->assertNull($this->requestFetcher->fetchRequest());
}

/**
* @return \Generator<array{Request|null,ServerRequest|null}>
*/
public function fetchRequestDataProvider(): \Generator
{
yield [
null,
null,
];

yield [
Request::create('http://www.example.com'),
new ServerRequest('GET', 'http://www.example.com'),
];
}
}