-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from prooph/reset_pj
Add ProjectionsManager::reset method
- Loading branch information
Showing
4 changed files
with
131 additions
and
0 deletions.
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
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
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,93 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of `prooph/event-store-client`. | ||
* (c) 2018-2018 prooph software GmbH <contact@prooph.de> | ||
* (c) 2018-2018 Sascha-Oliver Prolic <saschaprolic@googlemail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ProophTest\EventStoreClient; | ||
|
||
use Amp\Delayed; | ||
use Generator; | ||
use PHPUnit\Framework\TestCase; | ||
use Prooph\EventStoreClient\Util\Guid; | ||
use Throwable; | ||
|
||
class when_resetting_projections extends TestCase | ||
{ | ||
use ProjectionSpecification; | ||
|
||
/** @var string */ | ||
private $projectionName; | ||
/** @var string */ | ||
private $streamName; | ||
/** @var string */ | ||
private $query; | ||
|
||
public function given(): Generator | ||
{ | ||
$id = Guid::generateAsHex(); | ||
$this->projectionName = 'when_resetting_projections-' . $id; | ||
$this->streamName = 'test-stream-' . $id; | ||
|
||
yield $this->postEvent($this->streamName, 'testEvent', '{"A": 1}'); | ||
yield $this->postEvent($this->streamName, 'testEvent', '{"A": 2}'); | ||
|
||
$this->query = $this->createStandardQuery($this->streamName); | ||
|
||
yield $this->projectionsManager->createContinuousAsync( | ||
$this->projectionName, | ||
$this->query, | ||
false, | ||
'JS', | ||
$this->credentials | ||
); | ||
} | ||
|
||
protected function when(): Generator | ||
{ | ||
yield $this->projectionsManager->resetAsync( | ||
$this->projectionName, | ||
$this->credentials | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
* @throws Throwable | ||
*/ | ||
public function should_reset_the_projection(): void | ||
{ | ||
$this->execute(function () { | ||
$projectionStatus = \json_decode( | ||
yield $this->projectionsManager->getStatusAsync( | ||
$this->projectionName, | ||
$this->credentials | ||
), | ||
true | ||
); | ||
$status = $projectionStatus['status']; | ||
|
||
$this->assertStringStartsWith('Preparing', $status); | ||
|
||
yield new Delayed(500); | ||
|
||
$projectionStatus = \json_decode( | ||
yield $this->projectionsManager->getStatusAsync( | ||
$this->projectionName, | ||
$this->credentials | ||
), | ||
true | ||
); | ||
$status = $projectionStatus['status']; | ||
|
||
$this->assertSame('Running', $status); | ||
}); | ||
} | ||
} |