-
Notifications
You must be signed in to change notification settings - Fork 139
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
[WIP] Higher-Order Marble tests #153
Open
davidwdan
wants to merge
20
commits into
ReactiveX:master
Choose a base branch
from
davidwdan:marbleTest
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1a1b2e1
Preliminary marble testing
mbonneau fbeff95
more marble testing features
martinsik 16e7304
fix correct type for str_repeat()
martinsik 637d3fe
added marker groups support
martinsik 654614a
Added expectObservable and expectSubscriptions to FunctionalTestCase
davidwdan 4b91912
Added exception message support to expectObservable()->toBe()
davidwdan b2a3ae6
Added dispose support to expectObservable()
davidwdan 3ea6d38
Rename MarbleDiagramError to MarbleDiagramException
mbonneau 6147c65
Grouped marbles now happen at the same time
mbonneau a619b72
Grouped subscription marbles happen at the same time
mbonneau 6e35541
Added interfaces so we get type hinting for `toBe`
davidwdan 416034c
Fixed continues to actually continue the loop
davidwdan 14b7fd3
Merge branch '2.x' of github.com:ReactiveX/RxPHP into marbleTest
davidwdan c1d2d4a
Cherry picked higher-order observable test from v1
davidwdan 08b0e0a
use single instance of TestScheduler in all Notification objects
martinsik eb24667
Materialize the inner observable when converting the OnNextNotificati…
davidwdan 8d219fa
Simplified `materializeObservable`
davidwdan c153965
Removed unused use statement
davidwdan ee4ec61
remove redundant test
martinsik 58d185d
`toBe` now does a string comparison
davidwdan 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 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,52 @@ | ||
<?php | ||
|
||
namespace Rx\Notification; | ||
|
||
use Rx\Observable; | ||
use Rx\Testing\ColdObservable; | ||
use Rx\Testing\HotObservable; | ||
use Rx\Testing\MockHigherOrderObserver; | ||
use Rx\Testing\TestScheduler; | ||
|
||
class OnNextObservableNotification extends OnNextNotification | ||
{ | ||
/** @var MockHigherOrderObserver */ | ||
private $observer; | ||
|
||
public function __construct(Observable $value, TestScheduler $scheduler) | ||
{ | ||
parent::__construct($value); | ||
|
||
$this->observer = new MockHigherOrderObserver($scheduler, $scheduler->getClock()); | ||
$value->subscribe($this->observer); | ||
} | ||
|
||
public function equals($other): bool | ||
{ | ||
$messages1 = $this->getMessages(); | ||
/** @var OnNextObservableNotification $other */ | ||
$messages2 = $other->getMessages(); | ||
|
||
if (count($messages1) != count($messages2)) { | ||
return false; | ||
} | ||
|
||
for ($i = 0; $i < count($messages1); $i++) { | ||
if (!$messages1[$i]->equals($messages2[$i])) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function getMessages() | ||
{ | ||
return $this->observer->getMessages(); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return '[' . implode(', ', $this->getMessages()) . ']'; | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -26,13 +26,16 @@ public function __construct(TestScheduler $scheduler, array $messages = []) | |
|
||
protected function _subscribe(ObserverInterface $observer): DisposableInterface | ||
{ | ||
$this->subscriptions[] = new Subscription($this->scheduler->getClock()); | ||
$index = count($this->subscriptions) - 1; | ||
|
||
$currentObservable = $this; | ||
$disposable = new CompositeDisposable(); | ||
$scheduler = $this->scheduler; | ||
$isDisposed = false; | ||
$index = null; | ||
|
||
if (!($observer instanceof MockHigherOrderObserver)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need all these |
||
$this->subscriptions[] = new Subscription($this->scheduler->getClock()); | ||
$index = count($this->subscriptions) - 1; | ||
} | ||
|
||
foreach ($this->messages as $message) { | ||
$notification = $message->getValue(); | ||
|
@@ -53,8 +56,10 @@ protected function _subscribe(ObserverInterface $observer): DisposableInterface | |
$subscriptions = &$this->subscriptions; | ||
|
||
return new CallbackDisposable(function () use (&$currentObservable, $index, $observer, $scheduler, &$subscriptions, &$isDisposed) { | ||
$isDisposed = true; | ||
$subscriptions[$index] = new Subscription($subscriptions[$index]->getSubscribed(), $scheduler->getClock()); | ||
$isDisposed = true; | ||
if (!($observer instanceof MockHigherOrderObserver)) { | ||
$subscriptions[$index] = new Subscription($subscriptions[$index]->getSubscribed(), $scheduler->getClock()); | ||
} | ||
}); | ||
|
||
} | ||
|
This file contains 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 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,7 @@ | ||
<?php | ||
|
||
namespace Rx\Testing; | ||
|
||
class MockHigherOrderObserver extends MockObserver | ||
{ | ||
} |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should this live in
Rx\Testing
instead? It depends on theTestScheduler
?