-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
namespace NwLaravel\Transformer; | ||
|
||
use League\Fractal\TransformerAbstract; | ||
use \DateTime; | ||
|
||
/** | ||
* Class AbstractTransformer | ||
* @abstract | ||
*/ | ||
abstract class AbstractTransformer extends TransformerAbstract | ||
{ | ||
/** | ||
* @var boolean | ||
*/ | ||
protected $includeData = false; | ||
|
||
/** | ||
* Construct | ||
* | ||
* @param boolean $includeData Boolean Include Data | ||
*/ | ||
public function __construct($includeData = false) | ||
{ | ||
$this->includeData = $includeData; | ||
} | ||
|
||
/** | ||
* Has Include Data | ||
* | ||
* @return boolean | ||
*/ | ||
public function hasIncludeData() | ||
{ | ||
return $this->includeData; | ||
} | ||
|
||
/** | ||
* Format Date | ||
* | ||
* @param DateTime $date Date Time | ||
* @param string $format String Format | ||
* | ||
* @return string | ||
*/ | ||
public function formatDate($date, $format) | ||
{ | ||
if ($date instanceof DateTime) { | ||
return $date->format($format); | ||
} | ||
|
||
return null; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
namespace Tests\Transformer; | ||
|
||
use Tests\TestCase; | ||
use Mockery as m; | ||
use NwLaravel\Transformer\AbstractTransformer; | ||
|
||
class AbstractTransformerTest extends TestCase | ||
{ | ||
public function testConstructInstanceOf() | ||
{ | ||
$transformer = m::mock(AbstractTransformer::class.'[]'); | ||
$this->assertAttributeEquals(false, 'includeData', $transformer); | ||
$this->assertFalse($transformer->hasIncludeData()); | ||
} | ||
|
||
public function testMethods() | ||
{ | ||
$transformer = m::mock(AbstractTransformer::class.'[]', [true]); | ||
|
||
$this->assertAttributeEquals(true, 'includeData', $transformer); | ||
$this->assertTrue($transformer->hasIncludeData()); | ||
$this->assertNull($transformer->formatDate('', 'd/m/Y')); | ||
$this->assertEquals('04/12/1982', $transformer->formatDate(new \Datetime('1982-12-04'), 'd/m/Y')); | ||
} | ||
} |