tests: code coverage cleanup

main
Igor Scheller 5 years ago
parent 5c54d4787f
commit d27bcabc8b

@ -13,6 +13,7 @@ use stdClass;
class EngelsystemLoggerTest extends ApplicationFeatureTest class EngelsystemLoggerTest extends ApplicationFeatureTest
{ {
/** /**
* @covers \Engelsystem\Logger\EngelsystemLogger::__construct
* @return LoggerInterface * @return LoggerInterface
*/ */
public function getLogger() public function getLogger()
@ -47,7 +48,7 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest
} }
/** /**
* @covers \Engelsystem\Models\LogEntry * @covers \Engelsystem\Logger\EngelsystemLogger::log
* @dataProvider provideLogLevels * @dataProvider provideLogLevels
* @param string $level * @param string $level
*/ */
@ -148,10 +149,7 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest
*/ */
protected function getLastEntry() protected function getLastEntry()
{ {
$entries = LogEntry::all(); return LogEntry::all()->last();
$entry = $entries->last();
return $entry;
} }
/** /**

@ -9,6 +9,9 @@ use PHPUnit\Framework\TestCase;
class MigrationTest extends TestCase class MigrationTest extends TestCase
{ {
/**
* @covers \Engelsystem\Database\Migration\Migration::__construct
*/
public function testConstructor() public function testConstructor()
{ {
require_once __DIR__ . '/Stub/2017_12_24_053300_another_stuff.php'; require_once __DIR__ . '/Stub/2017_12_24_053300_another_stuff.php';

@ -17,7 +17,11 @@ use Whoops\RunInterface as WhoopsRunnerInterface;
class WhoopsTest extends TestCase class WhoopsTest extends TestCase
{ {
/** /**
* @covers \Engelsystem\Exceptions\Handlers\Whoops * @covers \Engelsystem\Exceptions\Handlers\Whoops::__construct
* @covers \Engelsystem\Exceptions\Handlers\Whoops::render
* @covers \Engelsystem\Exceptions\Handlers\Whoops::getPrettyPageHandler
* @covers \Engelsystem\Exceptions\Handlers\Whoops::getJsonResponseHandler
* @covers \Engelsystem\Exceptions\Handlers\Whoops::getData
*/ */
public function testRender() public function testRender()
{ {

@ -16,7 +16,7 @@ class AuthenticatorTest extends ServiceProviderTest
use HasDatabase; use HasDatabase;
/** /**
* @covers \Engelsystem\Helpers\Authenticator::__construct( * @covers \Engelsystem\Helpers\Authenticator::__construct
* @covers \Engelsystem\Helpers\Authenticator::user * @covers \Engelsystem\Helpers\Authenticator::user
*/ */
public function testUser() public function testUser()

@ -54,6 +54,9 @@ class GettextTranslatorTest extends ServiceProviderTest
$this->assertEquals('Translations!', $translator->dnpgettext(null, null, 'test.value', 'test.values', 2)); $this->assertEquals('Translations!', $translator->dnpgettext(null, null, 'test.value', 'test.values', 2));
} }
/**
* @return Translations
*/
protected function getTranslations(): Translations protected function getTranslations(): Translations
{ {
$translations = new Translations(); $translations = new Translations();

@ -28,8 +28,6 @@ class NewsCommentsTest extends TestCase
/** /**
* Sets up some test objects and test data. * Sets up some test objects and test data.
*
* @return void
*/ */
protected function setUp(): void protected function setUp(): void
{ {
@ -59,7 +57,7 @@ class NewsCommentsTest extends TestCase
/** /**
* Tests that a NewsComment can be created and loaded. * Tests that a NewsComment can be created and loaded.
* *
* @return void * @covers \Engelsystem\Models\NewsComment
*/ */
public function testCreate(): void public function testCreate(): void
{ {
@ -75,7 +73,7 @@ class NewsCommentsTest extends TestCase
/** /**
* Tests that accessing the User of a NewsComment works. * Tests that accessing the User of a NewsComment works.
* *
* @return void * @covers \Engelsystem\Models\NewsComment::user
*/ */
public function testUser(): void public function testUser(): void
{ {
@ -87,7 +85,7 @@ class NewsCommentsTest extends TestCase
/** /**
* Tests that accessing the News of a NewsComment works. * Tests that accessing the News of a NewsComment works.
* *
* @return void * @covers \Engelsystem\Models\NewsComment::news
*/ */
public function testNews(): void public function testNews(): void
{ {
@ -95,32 +93,4 @@ class NewsCommentsTest extends TestCase
$this->assertInstanceOf(News::class, $newsComment->news); $this->assertInstanceOf(News::class, $newsComment->news);
$this->assertSame($this->news->id, $newsComment->news->id); $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);
}
} }

@ -47,7 +47,7 @@ class NewsTest extends TestCase
/** /**
* Tests that creating a News item with default values works. * Tests that creating a News item with default values works.
* *
* @return void * @covers \Engelsystem\Models\News
*/ */
public function testCreateDefault(): void public function testCreateDefault(): void
{ {
@ -60,10 +60,25 @@ class NewsTest extends TestCase
$this->assertFalse($news->is_meeting); $this->assertFalse($news->is_meeting);
} }
/**
* 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. * Tests that creating a News item with all fill values works.
* *
* @return void * @covers \Engelsystem\Models\News
*/ */
public function testCreate(): void public function testCreate(): void
{ {

@ -5,6 +5,7 @@ namespace Engelsystem\Test\Unit\Models;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Models\BaseModel; use Engelsystem\Models\BaseModel;
use Engelsystem\Models\News; use Engelsystem\Models\News;
use Engelsystem\Models\NewsComment;
use Engelsystem\Models\Question; use Engelsystem\Models\Question;
use Engelsystem\Models\User\Contact; use Engelsystem\Models\User\Contact;
use Engelsystem\Models\User\HasUserModel; use Engelsystem\Models\User\HasUserModel;
@ -148,6 +149,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 * @covers \Engelsystem\Models\User\User::questionsAsked
*/ */

@ -10,6 +10,10 @@ use Psr\Log\LoggerInterface;
class RendererTest extends TestCase class RendererTest extends TestCase
{ {
/**
* @covers \Engelsystem\Renderer\Renderer::render
* @covers \Engelsystem\Renderer\Renderer::addRenderer
*/
public function testGet() public function testGet()
{ {
$renderer = new Renderer(); $renderer = new Renderer();
@ -41,6 +45,9 @@ class RendererTest extends TestCase
$this->assertEquals('Rendered content', $data); $this->assertEquals('Rendered content', $data);
} }
/**
* @covers \Engelsystem\Renderer\Renderer::render
*/
public function testError() public function testError()
{ {
$renderer = new Renderer(); $renderer = new Renderer();

Loading…
Cancel
Save