-
Notifications
You must be signed in to change notification settings - Fork 10
exclude internal symfony urls #299
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Patchlevel\EventSourcingBundle\Tests\Fixtures; | ||
|
|
||
| use Patchlevel\EventSourcing\Attribute\Subscriber; | ||
| use Patchlevel\EventSourcing\Subscription\RunMode; | ||
|
|
||
| #[Subscriber('from-beginning', RunMode::FromBeginning)] | ||
| final class FromBeginningSubscriber | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Patchlevel\EventSourcingBundle\Tests\Fixtures; | ||
|
|
||
| use Patchlevel\EventSourcing\Attribute\Subscriber; | ||
| use Patchlevel\EventSourcing\Subscription\RunMode; | ||
|
|
||
| #[Subscriber('from-now', RunMode::FromNow)] | ||
| final class FromNowSubscriber | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Patchlevel\EventSourcingBundle\Tests\Unit\RequestListener; | ||
|
|
||
| use Patchlevel\EventSourcing\Subscription\Engine\Result; | ||
| use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine; | ||
| use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngineCriteria; | ||
| use Patchlevel\EventSourcing\Subscription\Status; | ||
| use Patchlevel\EventSourcing\Subscription\Subscription; | ||
| use Patchlevel\EventSourcingBundle\RequestListener\AutoSetupListener; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
| use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
|
||
| /** @covers \Patchlevel\EventSourcingBundle\RequestListener\AutoSetupListener */ | ||
| final class AutoSetupListenerTest extends TestCase | ||
| { | ||
| public function testSkipSubRequest(): void | ||
| { | ||
| $subscriptionEngine = $this->createMock(SubscriptionEngine::class); | ||
| $subscriptionEngine->expects($this->never())->method('subscriptions'); | ||
| $subscriptionEngine->expects($this->never())->method('setup'); | ||
|
|
||
| $listener = new AutoSetupListener($subscriptionEngine, null, null); | ||
| $listener->onKernelRequest($this->createRequestEvent('/foo', HttpKernelInterface::SUB_REQUEST)); | ||
| } | ||
|
|
||
| public function testSkipExcludedUrl(): void | ||
| { | ||
| $subscriptionEngine = $this->createMock(SubscriptionEngine::class); | ||
| $subscriptionEngine->expects($this->never())->method('subscriptions'); | ||
| $subscriptionEngine->expects($this->never())->method('setup'); | ||
|
|
||
| $listener = new AutoSetupListener($subscriptionEngine, null, null, '^/_profiler'); | ||
| $listener->onKernelRequest($this->createRequestEvent('/_profiler/test')); | ||
| } | ||
|
|
||
| public function testSetupOnlyNewSubscriptions(): void | ||
| { | ||
| $subscriptionEngine = $this->createMock(SubscriptionEngine::class); | ||
| $subscriptionEngine | ||
| ->expects($this->once()) | ||
| ->method('subscriptions') | ||
| ->with($this->callback(static function (SubscriptionEngineCriteria|null $criteria): bool { | ||
| return $criteria instanceof SubscriptionEngineCriteria | ||
| && $criteria->ids === ['id-1'] | ||
| && $criteria->groups === ['group-1']; | ||
| })) | ||
| ->willReturn([ | ||
| new Subscription('new-1'), | ||
| new Subscription('active-1', status: Status::Active), | ||
| new Subscription('new-2'), | ||
| ]); | ||
|
|
||
| $subscriptionEngine | ||
| ->expects($this->once()) | ||
| ->method('setup') | ||
| ->with($this->callback(static function (SubscriptionEngineCriteria|null $criteria): bool { | ||
| return $criteria instanceof SubscriptionEngineCriteria | ||
| && $criteria->ids === ['new-1', 'new-2'] | ||
| && $criteria->groups === null; | ||
| }), true) | ||
| ->willReturn(new Result()); | ||
|
|
||
| $listener = new AutoSetupListener($subscriptionEngine, ['id-1'], ['group-1'], '^/_profiler'); | ||
| $listener->onKernelRequest($this->createRequestEvent('/app')); | ||
| } | ||
|
|
||
| private function createRequestEvent( | ||
| string $uri, | ||
| int $requestType = HttpKernelInterface::MAIN_REQUEST, | ||
| ): RequestEvent { | ||
| return new RequestEvent( | ||
| $this->createMock(HttpKernelInterface::class), | ||
| Request::create($uri), | ||
| $requestType, | ||
| ); | ||
| } | ||
| } | ||
132 changes: 132 additions & 0 deletions
132
tests/Unit/RequestListener/SubscriptionRebuildAfterFileChangeListenerTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Patchlevel\EventSourcingBundle\Tests\Unit\RequestListener; | ||
|
|
||
| use Patchlevel\EventSourcing\Subscription\Engine\ProcessedResult; | ||
| use Patchlevel\EventSourcing\Subscription\Engine\Result; | ||
| use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine; | ||
| use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngineCriteria; | ||
| use Patchlevel\EventSourcingBundle\RequestListener\SubscriptionRebuildAfterFileChangeListener; | ||
| use Patchlevel\EventSourcingBundle\Tests\Fixtures\FromBeginningSubscriber; | ||
| use Patchlevel\EventSourcingBundle\Tests\Fixtures\FromNowSubscriber; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Psr\Cache\CacheItemInterface; | ||
| use Psr\Cache\CacheItemPoolInterface; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
| use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
|
||
| /** @covers \Patchlevel\EventSourcingBundle\RequestListener\SubscriptionRebuildAfterFileChangeListener */ | ||
| final class SubscriptionRebuildAfterFileChangeListenerTest extends TestCase | ||
| { | ||
| public function testSkipSubRequest(): void | ||
| { | ||
| $subscriptionEngine = $this->createMock(SubscriptionEngine::class); | ||
| $subscriptionEngine->expects($this->never())->method('remove'); | ||
| $subscriptionEngine->expects($this->never())->method('setup'); | ||
| $subscriptionEngine->expects($this->never())->method('boot'); | ||
|
|
||
| $cache = $this->createMock(CacheItemPoolInterface::class); | ||
| $cache->expects($this->never())->method('getItem'); | ||
|
|
||
| $listener = new SubscriptionRebuildAfterFileChangeListener( | ||
| $subscriptionEngine, | ||
| [new FromBeginningSubscriber()], | ||
| $cache, | ||
| ); | ||
|
|
||
| $listener->onKernelRequest($this->createRequestEvent('/app', HttpKernelInterface::SUB_REQUEST)); | ||
| } | ||
|
|
||
| public function testSkipExcludedUrl(): void | ||
| { | ||
| $subscriptionEngine = $this->createMock(SubscriptionEngine::class); | ||
| $subscriptionEngine->expects($this->never())->method('remove'); | ||
| $subscriptionEngine->expects($this->never())->method('setup'); | ||
| $subscriptionEngine->expects($this->never())->method('boot'); | ||
|
|
||
| $cache = $this->createMock(CacheItemPoolInterface::class); | ||
| $cache->expects($this->never())->method('getItem'); | ||
|
|
||
| $listener = new SubscriptionRebuildAfterFileChangeListener( | ||
| $subscriptionEngine, | ||
| [new FromBeginningSubscriber()], | ||
| $cache, | ||
| excludeUrl: '^/_wdt', | ||
| ); | ||
|
|
||
| $listener->onKernelRequest($this->createRequestEvent('/_wdt/abc')); | ||
| } | ||
|
|
||
| public function testRebuildChangedFromBeginningSubscriptionsOnly(): void | ||
| { | ||
| $item = $this->createMock(CacheItemInterface::class); | ||
| $item->expects($this->once())->method('get')->willReturn(1); | ||
| $item->expects($this->once())->method('set')->with($this->isType('int'))->willReturnSelf(); | ||
|
|
||
| $cache = $this->createMock(CacheItemPoolInterface::class); | ||
| $cache->expects($this->once())->method('getItem')->with('from-beginning')->willReturn($item); | ||
| $cache->expects($this->once())->method('save')->with($item)->willReturn(true); | ||
|
|
||
| $subscriptionEngine = $this->createMock(SubscriptionEngine::class); | ||
| $criteriaMatcher = $this->callback(static fn (SubscriptionEngineCriteria|null $criteria): bool => $criteria instanceof SubscriptionEngineCriteria && $criteria->ids === ['from-beginning'] && $criteria->groups === null); | ||
|
|
||
| $subscriptionEngine->expects($this->once())->method('remove')->with($criteriaMatcher)->willReturn(new Result()); | ||
| $subscriptionEngine->expects($this->once())->method('setup')->with($criteriaMatcher)->willReturn(new Result()); | ||
| $subscriptionEngine->expects($this->once())->method('boot')->with($criteriaMatcher)->willReturn(new ProcessedResult(0)); | ||
|
|
||
| $listener = new SubscriptionRebuildAfterFileChangeListener( | ||
| $subscriptionEngine, | ||
| [new FromBeginningSubscriber(), new FromNowSubscriber()], | ||
| $cache, | ||
| ); | ||
|
|
||
| $listener->onKernelRequest($this->createRequestEvent('/app')); | ||
| } | ||
|
|
||
| public function testNoRebuildWhenFileDidNotChange(): void | ||
| { | ||
| $subscriberFile = (new \ReflectionClass(FromBeginningSubscriber::class))->getFileName(); | ||
| self::assertIsString($subscriberFile); | ||
|
|
||
| $currentModified = filemtime($subscriberFile); | ||
| self::assertIsInt($currentModified); | ||
|
|
||
| $item = $this->createMock(CacheItemInterface::class); | ||
| $item->expects($this->once())->method('get')->willReturn($currentModified); | ||
| $item->expects($this->never())->method('set'); | ||
|
|
||
| $cache = $this->createMock(CacheItemPoolInterface::class); | ||
| $cache->expects($this->once())->method('getItem')->with('from-beginning')->willReturn($item); | ||
| $cache->expects($this->never())->method('save'); | ||
|
|
||
| $subscriptionEngine = $this->createMock(SubscriptionEngine::class); | ||
| $emptyCriteriaMatcher = $this->callback(static fn (SubscriptionEngineCriteria|null $criteria): bool => $criteria instanceof SubscriptionEngineCriteria && $criteria->ids === []); | ||
|
|
||
| $subscriptionEngine->expects($this->once())->method('remove')->with($emptyCriteriaMatcher)->willReturn(new Result()); | ||
| $subscriptionEngine->expects($this->once())->method('setup')->with($emptyCriteriaMatcher)->willReturn(new Result()); | ||
| $subscriptionEngine->expects($this->once())->method('boot')->with($emptyCriteriaMatcher)->willReturn(new ProcessedResult(0)); | ||
|
|
||
| $listener = new SubscriptionRebuildAfterFileChangeListener( | ||
| $subscriptionEngine, | ||
| [new FromBeginningSubscriber()], | ||
| $cache, | ||
| excludeUrl: '^/_profiler', | ||
| ); | ||
|
|
||
| $listener->onKernelRequest($this->createRequestEvent('/app')); | ||
| } | ||
|
|
||
| private function createRequestEvent( | ||
| string $uri, | ||
| int $requestType = HttpKernelInterface::MAIN_REQUEST, | ||
| ): RequestEvent { | ||
| return new RequestEvent( | ||
| $this->createMock(HttpKernelInterface::class), | ||
| Request::create($uri), | ||
| $requestType, | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.