-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
1 parent
e286f45
commit 7d75938
Showing
2 changed files
with
104 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace rjapitest\unit\transformers; | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use League\Fractal\Resource\Item; | ||
use League\Fractal\TransformerAbstract; | ||
use Modules\V2\Entities\Article; | ||
use Modules\V2\Http\Middleware\ArticleMiddleware; | ||
use PHPUnit\Framework\Constraint\IsType; | ||
use rjapi\extension\BaseModel; | ||
use rjapi\transformers\DefaultTransformer; | ||
use rjapitest\unit\TestCase; | ||
|
||
/** | ||
* Class DefaultTransformerTest | ||
* @package rjapitest\unit\transformers | ||
* | ||
* @property DefaultTransformer transformer | ||
*/ | ||
class DefaultTransformerTest extends TestCase | ||
{ | ||
private $transformer; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$middleware = new ArticleMiddleware(); | ||
$this->transformer = new DefaultTransformer($middleware); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_transforms_objects() | ||
{ | ||
$this->assertInstanceOf(TransformerAbstract::class, $this->transformer); | ||
$collection = new Collection(); | ||
$this->assertInternalType(IsType::TYPE_ARRAY, $this->transformer->transform($collection)); | ||
$baseModel = new BaseModel(); | ||
$this->assertInternalType(IsType::TYPE_ARRAY, $this->transformer->transform($baseModel)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_includes_data() | ||
{ | ||
$article = new Article(); | ||
$article->addVisible([ | ||
'title' => 'Foo Bar Baz', | ||
'description' => 'Foo Bar Baz Foo Bar Baz Foo Bar Baz', | ||
]); | ||
$this->assertInstanceOf(Item::class, $this->transformer->includeArticle($article)); | ||
} | ||
} |