-
-
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.
#111. Add more coverage on BaseRelationsTrait
- Loading branch information
1 parent
9a89c3d
commit f20bb70
Showing
6 changed files
with
276 additions
and
171 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
<?php | ||
namespace rjapitest\_data; | ||
|
||
use Modules\V2\Entities\Tag; | ||
|
||
class TagFixture | ||
{ | ||
/** | ||
* @return Tag | ||
*/ | ||
public static function createAndGet() : Tag | ||
{ | ||
$user = new Tag(); | ||
$user->title = 'Foo Bar Baz'; | ||
$user->save(); | ||
|
||
return $user; | ||
} | ||
|
||
/** | ||
* @param $id | ||
*/ | ||
public static function delete($id) : void | ||
{ | ||
Tag::destroy($id); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace rjapitest\_data; | ||
|
||
use Modules\V2\Entities\Topic; | ||
|
||
class TopicFixture | ||
{ | ||
/** | ||
* @return Topic | ||
*/ | ||
public static function createAndGet() : Topic | ||
{ | ||
$user = new Topic(); | ||
$user->title = 'Foo Bar Baz'; | ||
$user->save(); | ||
|
||
return $user; | ||
} | ||
|
||
/** | ||
* @param $id | ||
*/ | ||
public static function delete($id) : void | ||
{ | ||
Topic::destroy($id); | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
namespace rjapitest\unit\extensions; | ||
|
||
|
||
use Modules\V2\Entities\Article; | ||
use rjapi\extension\BaseRelationsTrait; | ||
use rjapi\types\RamlInterface; | ||
use rjapitest\_data\ArticleFixture; | ||
use rjapitest\_data\TopicFixture; | ||
use rjapitest\unit\TestCase; | ||
|
||
|
||
class BaseRelationsTraitTest extends TestCase | ||
{ | ||
use BaseRelationsTrait; | ||
|
||
private $article; | ||
private $entity; | ||
private $topic; | ||
private $modelEntity; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->article = ArticleFixture::createAndGet(); | ||
$this->topic = TopicFixture::createAndGet(); | ||
$this->entity = 'Article'; | ||
$this->modelEntity = Article::class; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_sets_relationships() | ||
{ | ||
$this->setRelationships([ | ||
RamlInterface::RAML_DATA => [ | ||
'type' => 'article', | ||
'id' => $this->article->id, | ||
RamlInterface::RAML_RELATIONSHIPS => [ | ||
'topic' => [ | ||
'data' => ['type' => 'topic', 'id' => $this->topic->id] | ||
], | ||
], | ||
]], $this->article->id); | ||
$article = $this->getEntity($this->article->id); | ||
$this->assertEquals($this->topic->id, $article->topic_id); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
ArticleFixture::delete($this->article->id); | ||
TopicFixture::delete($this->topic->id); | ||
parent::tearDown(); | ||
} | ||
} |