-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GraveyardInterface and BufferedGraveyard
- Loading branch information
Showing
6 changed files
with
112 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Scheb\Tombstone; | ||
|
||
class BufferedGraveyard implements GraveyardInterface | ||
{ | ||
/** | ||
* @var GraveyardInterface | ||
*/ | ||
private $graveyard; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $tombstoneCalls = []; | ||
|
||
public function __construct(GraveyardInterface $graveyard) | ||
{ | ||
$this->graveyard = $graveyard; | ||
} | ||
|
||
public function tombstone(string $date, ?string $author, ?string $label, array $trace): void | ||
{ | ||
$this->tombstoneCalls[] = func_get_args(); | ||
} | ||
|
||
public function flush(): void | ||
{ | ||
foreach ($this->tombstoneCalls as $args) { | ||
$this->graveyard->tombstone(... $args); | ||
} | ||
$this->graveyard->flush(); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Scheb\Tombstone; | ||
|
||
interface GraveyardInterface | ||
{ | ||
public function tombstone(string $date, ?string $author, ?string $label, array $trace): void; | ||
|
||
public function flush(): void; | ||
} |
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,62 @@ | ||
<?php | ||
|
||
namespace Scheb\Tombstone\Test; | ||
|
||
use Scheb\Tombstone\BufferedGraveyard; | ||
use Scheb\Tombstone\Graveyard; | ||
use Scheb\Tombstone\GraveyardInterface; | ||
|
||
class BufferedGraveyardTest extends TestCase | ||
{ | ||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $innerGraveyard; | ||
|
||
/** | ||
* @var Graveyard | ||
*/ | ||
private $graveyard; | ||
|
||
protected function setUp() | ||
{ | ||
$this->innerGraveyard = $this->createMock(GraveyardInterface::class); | ||
$this->graveyard = new BufferedGraveyard($this->innerGraveyard); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function tombstone_tombstoneInvoked_notAddToInnerGraveyard(): void | ||
{ | ||
$this->innerGraveyard | ||
->expects($this->never()) | ||
->method($this->anything()); | ||
|
||
$this->graveyard->tombstone('2018-01-01', 'author1', 'label1', ['trace1']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function flush_tombstonesBuffered_addTombstonesAndFlush(): void | ||
{ | ||
$this->graveyard->tombstone('2018-01-01', 'author1', 'label1', ['trace1']); | ||
$this->graveyard->tombstone('2018-02-01', 'author2', 'label2', ['trace2']); | ||
|
||
$this->innerGraveyard | ||
->expects($this->exactly(2)) | ||
->method('tombstone') | ||
->withConsecutive( | ||
['2018-01-01', 'author1', 'label1', ['trace1']], | ||
['2018-02-01', 'author2', 'label2', ['trace2']] | ||
); | ||
|
||
$this->innerGraveyard | ||
->expects($this->once()) | ||
->method('flush'); | ||
|
||
$this->graveyard->flush(); | ||
|
||
} | ||
} |
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