-
Notifications
You must be signed in to change notification settings - Fork 142
Marble testing #133
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
Marble testing #133
Conversation
|
You guys rock! LOL Looking good...!! |
|
Nice! :) Off-topic, but are the slides for that talk somewhere? Cool to hear people are doing talks about RxPHP! |
| return new TestScheduler(); | ||
| } | ||
|
|
||
| protected function convertMarblesToMessages(string $marbles, array $eventMap = [], \Exception $customError = null, $subscribePoint = 0) |
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: perhaps extract this to some util? It might be useful in other contexts as well. E.g. demos and auto extracting marbles/tests from docs at some point.
|
|
||
| protected function convertMarblesToMessages(string $marbles, array $eventMap = [], \Exception $customError = null, $subscribePoint = 0) | ||
| { | ||
| var_dump($eventMap); |
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: remove
|
|
||
| for ($i = 0; $i < strlen($marbles); $i++) { | ||
| switch ($marbles[$i]) { | ||
| case '-': // nothing |
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.
In RxJS 5 they very often use also spaces " " (https://github.com/ReactiveX/rxjs/blob/master/spec/operators/window-spec.ts).
This is what I used in #144
case '-': // nothing
case ' ':
continue;
| $events[] = onCompleted($i * 10); | ||
| continue; | ||
| default: | ||
| $events[] = onNext($i * 10, isset($eventMap[$i]) ? $eventMap[$i] : $marbles[$i]); |
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.
Just $eventMap[$i] assumes that the $eventMap array is indexed by time (eg. [0 => 'abc', 13 => 'def', 16 => ...])
For #144 I updated it to use the same approach as RxJS 5:
$eventKey = $marbles[$i];
$events[] = onNext($i * 10, isset($eventMap[$eventKey]) ? $eventMap[$eventKey] : $marbles[$i]);
So I can use it as [ 'x' => $x, 'y' => $y, 'z' => $z ]
|
I think I can't commit to your PR (or I don't know how) but when testing #144 I made also a method to convert subscription marbles to proper This is then automatically used when calling |
This PR is a preliminary implementation of marble testing as requested at SunshinePHP at the talk by @luijar see: https://github.com/ReactiveX/rxjs/blob/master/doc/writing-marble-tests.md
Example: