Skip to content

Conversation

@mbonneau
Copy link
Member

@mbonneau mbonneau commented Feb 4, 2017

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:

    public function testMapAddOne()
    {
        $cold     = '--1--2--|';
        $expected = '--2--3--|';

        $results = $this->scheduler->startWithCreate(function () use ($cold) {
            return $this->createCold($cold)->map(function ($x) { return $x + 1; });
        });

        $this->assertEquals($expected, $this->convertMessagesToMarbles($results->getMessages()));
    }

@luijar
Copy link

luijar commented Feb 6, 2017

You guys rock! LOL Looking good...!!

@asm89
Copy link
Member

asm89 commented Feb 7, 2017

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)
Copy link
Member

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);
Copy link
Member

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$events[] = onCompleted($i * 10);
continue;
default:
$events[] = onNext($i * 10, isset($eventMap[$i]) ? $eventMap[$i] : $marbles[$i]);
Copy link
Contributor

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 ]

https://github.com/martinsik/RxPHP/blob/002671800236c56d872a68dc635a5836c4f39448/test/Rx/Functional/FunctionalTestCase.php#L169

@martinsik
Copy link
Contributor

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 Subscription objects.

https://github.com/martinsik/RxPHP/blob/002671800236c56d872a68dc635a5836c4f39448/test/Rx/Functional/FunctionalTestCase.php#L120

This is then automatically used when calling assertSubscriptions.

https://github.com/martinsik/RxPHP/blob/002671800236c56d872a68dc635a5836c4f39448/test/Rx/Functional/FunctionalTestCase.php#L64

@coveralls
Copy link

coveralls commented Feb 18, 2017

Coverage Status

Coverage increased (+0.05%) to 100.0% when pulling b2a3ae6 on mbonneau:marbleTest into 52f7b01 on ReactiveX:2.x.

@coveralls
Copy link

coveralls commented Feb 18, 2017

Coverage Status

Coverage increased (+0.05%) to 100.0% when pulling b2a3ae6 on mbonneau:marbleTest into 52f7b01 on ReactiveX:2.x.

@coveralls
Copy link

coveralls commented Feb 18, 2017

Coverage Status

Coverage increased (+0.05%) to 100.0% when pulling b2a3ae6 on mbonneau:marbleTest into 52f7b01 on ReactiveX:2.x.

@coveralls
Copy link

coveralls commented Feb 18, 2017

Coverage Status

Coverage increased (+0.05%) to 100.0% when pulling b2a3ae6 on mbonneau:marbleTest into 52f7b01 on ReactiveX:2.x.

@mbonneau mbonneau changed the title Preliminary marble testing Marble testing Feb 20, 2017
@coveralls
Copy link

coveralls commented Feb 20, 2017

Coverage Status

Coverage increased (+0.05%) to 100.0% when pulling 3ea6d38 on mbonneau:marbleTest into 52f7b01 on ReactiveX:2.x.

@coveralls
Copy link

coveralls commented Feb 20, 2017

Coverage Status

Coverage increased (+0.05%) to 100.0% when pulling a619b72 on mbonneau:marbleTest into 52f7b01 on ReactiveX:2.x.

@coveralls
Copy link

coveralls commented Feb 20, 2017

Coverage Status

Coverage increased (+0.05%) to 100.0% when pulling 6e35541 on mbonneau:marbleTest into 52f7b01 on ReactiveX:2.x.

@coveralls
Copy link

coveralls commented Feb 20, 2017

Coverage Status

Coverage increased (+0.05%) to 100.0% when pulling 416034c on mbonneau:marbleTest into 52f7b01 on ReactiveX:2.x.

@mbonneau mbonneau merged commit 23e32ca into ReactiveX:2.x Mar 10, 2017
@mbonneau mbonneau deleted the marbleTest branch June 12, 2020 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants