summaryrefslogtreecommitdiff
path: root/tests/Unit/Models
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Models')
-rw-r--r--tests/Unit/Models/NewsCommentsTest.php36
-rw-r--r--tests/Unit/Models/NewsTest.php19
-rw-r--r--tests/Unit/Models/User/UserTest.php17
3 files changed, 37 insertions, 35 deletions
diff --git a/tests/Unit/Models/NewsCommentsTest.php b/tests/Unit/Models/NewsCommentsTest.php
index dfded712..1749e988 100644
--- a/tests/Unit/Models/NewsCommentsTest.php
+++ b/tests/Unit/Models/NewsCommentsTest.php
@@ -28,8 +28,6 @@ class NewsCommentsTest extends TestCase
/**
* Sets up some test objects and test data.
- *
- * @return void
*/
protected function setUp(): void
{
@@ -59,7 +57,7 @@ class NewsCommentsTest extends TestCase
/**
* Tests that a NewsComment can be created and loaded.
*
- * @return void
+ * @covers \Engelsystem\Models\NewsComment
*/
public function testCreate(): void
{
@@ -75,7 +73,7 @@ class NewsCommentsTest extends TestCase
/**
* Tests that accessing the User of a NewsComment works.
*
- * @return void
+ * @covers \Engelsystem\Models\NewsComment::user
*/
public function testUser(): void
{
@@ -87,7 +85,7 @@ class NewsCommentsTest extends TestCase
/**
* Tests that accessing the News of a NewsComment works.
*
- * @return void
+ * @covers \Engelsystem\Models\NewsComment::news
*/
public function testNews(): void
{
@@ -95,32 +93,4 @@ class NewsCommentsTest extends TestCase
$this->assertInstanceOf(News::class, $newsComment->news);
$this->assertSame($this->news->id, $newsComment->news->id);
}
-
- /**
- * Tests that accessing the NewsComments of a News works.
- *
- * @return void
- */
- public function testNewsComments(): void
- {
- $newsComment = NewsComment::create($this->newsCommentData);
- $comments = $this->news->comments;
- $this->assertCount(1, $comments);
- $comment = $comments->first();
- $this->assertSame($newsComment->id, $comment->id);
- }
-
- /**
- * Tests that accessing the NewsComments of an User works.
- *
- * @return void
- */
- public function testUserNewsComments(): void
- {
- $newsComment = NewsComment::create($this->newsCommentData);
- $comments = $this->user->newsComments;
- $this->assertCount(1, $comments);
- $comment = $comments->first();
- $this->assertSame($newsComment->id, $comment->id);
- }
}
diff --git a/tests/Unit/Models/NewsTest.php b/tests/Unit/Models/NewsTest.php
index 18ca2d9a..ca933686 100644
--- a/tests/Unit/Models/NewsTest.php
+++ b/tests/Unit/Models/NewsTest.php
@@ -47,7 +47,7 @@ class NewsTest extends TestCase
/**
* Tests that creating a News item with default values works.
*
- * @return void
+ * @covers \Engelsystem\Models\News
*/
public function testCreateDefault(): void
{
@@ -61,9 +61,24 @@ class NewsTest extends TestCase
}
/**
+ * Tests that accessing the NewsComments of a News works.
+ *
+ * @covers \Engelsystem\Models\News::comments
+ */
+ public function testNewsComments(): void
+ {
+ $news = (new News())->create($this->newsData);
+ $comment = $news->comments()->create(['text' => 'test comment', 'user_id' => $this->user->id]);
+
+ $comments = $news->comments;
+ $this->assertCount(1, $comments);
+ $this->assertEquals($comment->toArray(), $news->comments->first()->toArray());
+ }
+
+ /**
* Tests that creating a News item with all fill values works.
*
- * @return void
+ * @covers \Engelsystem\Models\News
*/
public function testCreate(): void
{
diff --git a/tests/Unit/Models/User/UserTest.php b/tests/Unit/Models/User/UserTest.php
index fd8e2396..7f56d0c4 100644
--- a/tests/Unit/Models/User/UserTest.php
+++ b/tests/Unit/Models/User/UserTest.php
@@ -5,6 +5,7 @@ namespace Engelsystem\Test\Unit\Models;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Models\BaseModel;
use Engelsystem\Models\News;
+use Engelsystem\Models\NewsComment;
use Engelsystem\Models\Question;
use Engelsystem\Models\User\Contact;
use Engelsystem\Models\User\HasUserModel;
@@ -149,6 +150,22 @@ class UserTest extends TestCase
}
/**
+ * Tests that accessing the NewsComments of an User works.
+ *
+ * @covers \Engelsystem\Models\User\User::newsComments
+ */
+ public function testNewsComments(): void
+ {
+ ($user = new User($this->data))->save();
+ $newsComment = NewsComment::create(['news_id' => 0, 'text' => 'test comment', 'user_id' => $user->id]);
+ $comments = $user->newsComments;
+
+ $this->assertCount(1, $comments);
+ $comment = $comments->first();
+ $this->assertSame($newsComment->id, $comment->id);
+ }
+
+ /**
* @covers \Engelsystem\Models\User\User::questionsAsked
*/
public function testQuestionsAsked(): void