-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom prettifiers wrapper tests, #17
- Loading branch information
1 parent
6063e2a
commit 4f9b80d
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
tests/Unit/Application/ReadModel/Prettifiers/CustomPrettifiersTest.php
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,87 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace hollodotme\Readis\Tests\Unit\Application\ReadModel\Prettifiers; | ||
|
||
use hollodotme\Readis\Application\ReadModel\Prettifiers\CustomPrettifiers; | ||
use hollodotme\Readis\Tests\Unit\Traits\CustomPrettifierMocking; | ||
use PHPUnit\Framework\TestCase; | ||
use function base64_encode; | ||
|
||
final class CustomPrettifiersTest extends TestCase | ||
{ | ||
use CustomPrettifierMocking; | ||
|
||
/** @var CustomPrettifiers */ | ||
private $prettifiers; | ||
|
||
protected function setUp() | ||
{ | ||
$this->prettifiers = new CustomPrettifiers(); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$this->prettifiers = null; | ||
} | ||
|
||
/** | ||
* @throws \PHPUnit\Framework\ExpectationFailedException | ||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException | ||
*/ | ||
public function testAddPrettifiers() : void | ||
{ | ||
$this->prettifiers->addPrettifiers( | ||
$this->getRawPrettifierMock(), | ||
$this->getCustomBase64Prettifier() | ||
); | ||
|
||
$this->assertTrue( $this->prettifiers->canPrettify( 'some data' ) ); | ||
} | ||
|
||
/** | ||
* @throws \PHPUnit\Framework\ExpectationFailedException | ||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException | ||
*/ | ||
public function testCanPrettifyReturnsFalseIfNoPrettifiersWereAdded() : void | ||
{ | ||
$this->assertFalse( $this->prettifiers->canPrettify( 'some data' ) ); | ||
} | ||
|
||
/** | ||
* @param string $data | ||
* @param string $expectedResult | ||
* | ||
* @throws \PHPUnit\Framework\ExpectationFailedException | ||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException | ||
* | ||
* @dataProvider customPrettifierDataProvider | ||
*/ | ||
public function testPrettify( string $data, string $expectedResult ) : void | ||
{ | ||
$this->prettifiers->addPrettifiers( | ||
$this->getCustomBase64Prettifier(), | ||
$this->getCustomHtmlEntityPrettifier() | ||
); | ||
|
||
$this->assertTrue( $this->prettifiers->canPrettify( $data ) ); | ||
$this->assertSame( $expectedResult, $this->prettifiers->prettify( $data ) ); | ||
} | ||
|
||
public function customPrettifierDataProvider() : array | ||
{ | ||
return [ | ||
[ | ||
'data' => 'some plain data', | ||
'expectedResult' => 'some plain data', | ||
], | ||
[ | ||
'data' => 'base64:' . base64_encode( 'some base64 data' ), | ||
'expectedResult' => 'some base64 data', | ||
], | ||
[ | ||
'data' => 'html:<html>', | ||
'expectedResult' => '<html>', | ||
], | ||
]; | ||
} | ||
} |