-
-
Notifications
You must be signed in to change notification settings - Fork 27
Replace StubAdapter to InMemoryAdapter + Add stubs to CS Fixer config
#285
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2f679f1
Add `InMemoryAdapter` + Add stubs to CS Fixer config
vjik d998d66
tests
vjik aca9e91
fix psalm
vjik 08bd0e1
Merge branch 'master' into in-memory-adapter
vjik c772d0e
Improve tests
vjik 8cb225a
Merge remote-tracking branch 'origin/in-memory-adapter' into in-memor…
vjik 7d176c2
Apply PHP CS Fixer and Rector changes (CI)
vjik 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 was deleted.
Oops, something went wrong.
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,173 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Queue\Tests\Unit\Stubs; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Yiisoft\Queue\Message\IdEnvelope; | ||
| use Yiisoft\Queue\Message\Message; | ||
| use Yiisoft\Queue\Message\MessageInterface; | ||
| use Yiisoft\Queue\MessageStatus; | ||
| use Yiisoft\Queue\Stubs\InMemoryAdapter; | ||
|
|
||
| final class InMemoryAdapterTest extends TestCase | ||
| { | ||
| public function testPush(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
|
|
||
| $envelope1 = $adapter->push(new Message('test', 'a')); | ||
| $envelope2 = $adapter->push(new Message('test', 'b')); | ||
| $envelope3 = $adapter->push(new Message('test', 'c')); | ||
|
|
||
| $this->assertInstanceOf(IdEnvelope::class, $envelope1); | ||
| $this->assertInstanceOf(IdEnvelope::class, $envelope2); | ||
| $this->assertInstanceOf(IdEnvelope::class, $envelope3); | ||
|
|
||
| $this->assertSame(0, $envelope1->getId()); | ||
| $this->assertSame('a', $envelope1->getMessage()->getData()); | ||
| $this->assertSame(1, $envelope2->getId()); | ||
| $this->assertSame('b', $envelope2->getMessage()->getData()); | ||
| $this->assertSame(2, $envelope3->getId()); | ||
| $this->assertSame('c', $envelope3->getMessage()->getData()); | ||
| } | ||
|
|
||
| public function testStatusWaitingForPushedMessage(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
| $envelope = $adapter->push(new Message('test', null)); | ||
|
|
||
| $this->assertInstanceOf(IdEnvelope::class, $envelope); | ||
| $this->assertSame(MessageStatus::WAITING, $adapter->status($envelope->getId())); | ||
| } | ||
|
|
||
| public function testStatusDoneAfterProcessing(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
| $envelope = $adapter->push(new Message('test', null)); | ||
|
|
||
| $adapter->runExisting(static fn() => true); | ||
|
|
||
| $this->assertInstanceOf(IdEnvelope::class, $envelope); | ||
| $this->assertSame(MessageStatus::DONE, $adapter->status($envelope->getId())); | ||
|
vjik marked this conversation as resolved.
|
||
| } | ||
|
|
||
| public function testStatusNotFoundForNonExistentId(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
|
|
||
| $this->assertSame(MessageStatus::NOT_FOUND, $adapter->status(99)); | ||
| } | ||
|
|
||
| public function testStatusNotFoundForNegativeId(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
|
|
||
| $this->assertSame(MessageStatus::NOT_FOUND, $adapter->status(-1)); | ||
| } | ||
|
|
||
| public function testStatusAcceptsStringId(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
| $envelope = $adapter->push(new Message('test', null)); | ||
|
|
||
| $this->assertInstanceOf(IdEnvelope::class, $envelope); | ||
| $this->assertSame(MessageStatus::WAITING, $adapter->status((string) $envelope->getId())); | ||
| } | ||
|
|
||
| public function testRunExistingProcessesAllMessages(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
| $adapter->push(new Message('test', 'a')); | ||
| $adapter->push(new Message('test', 'b')); | ||
| $adapter->push(new Message('test', 'c')); | ||
|
|
||
| $processed = []; | ||
| $adapter->runExisting( | ||
| static function (MessageInterface $message) use (&$processed): bool { | ||
| $processed[] = $message->getData(); | ||
| return true; | ||
| }, | ||
| ); | ||
|
|
||
| $this->assertSame(['a', 'b', 'c'], $processed); | ||
| } | ||
|
|
||
| public function testRunExistingStopsWhenHandlerReturnsFalse(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
| $adapter->push(new Message('test', 'a')); | ||
| $adapter->push(new Message('test', 'b')); | ||
| $adapter->push(new Message('test', 'c')); | ||
|
|
||
| $processed = []; | ||
| $adapter->runExisting( | ||
| static function (MessageInterface $message) use (&$processed): bool { | ||
| $processed[] = $message->getData(); | ||
| return false; | ||
| }, | ||
| ); | ||
|
|
||
| $this->assertSame(['a'], $processed); | ||
| } | ||
|
|
||
| public function testRunExistingOnEmptyQueue(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
|
|
||
| $called = false; | ||
| $adapter->runExisting(static function () use (&$called): bool { | ||
| $called = true; | ||
| return true; | ||
| }); | ||
|
|
||
| $this->assertFalse($called); | ||
| } | ||
|
|
||
| public function testRunExistingDoesNotReprocessMessages(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
| $adapter->push(new Message('test', 'x')); | ||
|
|
||
| $count = 0; | ||
| $handler = static function () use (&$count): bool { | ||
| $count++; | ||
| return true; | ||
| }; | ||
| $adapter->runExisting($handler); | ||
| $adapter->runExisting($handler); | ||
|
|
||
| $this->assertSame(1, $count); | ||
| } | ||
|
|
||
| public function testIdContinuesAfterProcessing(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
| $adapter->push(new Message('test', null)); | ||
| $adapter->runExisting(static fn() => true); | ||
|
|
||
| $envelope = $adapter->push(new Message('test', null)); | ||
|
|
||
| $this->assertInstanceOf(IdEnvelope::class, $envelope); | ||
| $this->assertSame(1, $envelope->getId()); | ||
| $this->assertSame(MessageStatus::WAITING, $adapter->status($envelope->getId())); | ||
| } | ||
|
|
||
| public function testSubscribeProcessesExistingMessages(): void | ||
| { | ||
| $adapter = new InMemoryAdapter(); | ||
| $adapter->push(new Message('test', 'a')); | ||
| $adapter->push(new Message('test', 'b')); | ||
|
|
||
| $processed = []; | ||
| $adapter->subscribe( | ||
| static function (MessageInterface $message) use (&$processed): bool { | ||
| $processed[] = $message->getData(); | ||
| return true; | ||
| }, | ||
| ); | ||
|
|
||
| $this->assertSame(['a', 'b'], $processed); | ||
| } | ||
| } | ||
This file was deleted.
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.