summaryrefslogtreecommitdiff
path: root/tests/Feature/Model
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Feature/Model')
-rw-r--r--tests/Feature/Model/LogEntriesModelTest.php33
-rw-r--r--tests/Feature/Model/LogEntryTest.php56
2 files changed, 56 insertions, 33 deletions
diff --git a/tests/Feature/Model/LogEntriesModelTest.php b/tests/Feature/Model/LogEntriesModelTest.php
deleted file mode 100644
index c032a94c..00000000
--- a/tests/Feature/Model/LogEntriesModelTest.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-namespace Engelsystem\Test\Feature\Model;
-
-use Engelsystem\Test\Feature\ApplicationFeatureTest;
-use Psr\Log\LogLevel;
-
-class LogEntriesModelTest extends ApplicationFeatureTest
-{
- public function testCreateLogEntry()
- {
- LogEntries_clear_all();
- $count = count(LogEntries());
- $this->assertNotFalse(LogEntry_create(LogLevel::WARNING, 'test_LogEntry_create'));
-
- // There should be one more log entry now
- $this->assertEquals(count(LogEntries()), $count + 1);
- }
-
- public function testClearAllLogEntries()
- {
- LogEntry_create(LogLevel::WARNING, 'test');
- $this->assertTrue(count(LogEntries()) > 0);
-
- $this->assertNotFalse(LogEntries_clear_all());
- $this->assertCount(0, LogEntries());
- }
-
- public function tearDown()
- {
- LogEntries_clear_all();
- }
-}
diff --git a/tests/Feature/Model/LogEntryTest.php b/tests/Feature/Model/LogEntryTest.php
new file mode 100644
index 00000000..25b35676
--- /dev/null
+++ b/tests/Feature/Model/LogEntryTest.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Engelsystem\Test\Feature\Model;
+
+use Engelsystem\Models\LogEntry;
+use PHPUnit\Framework\TestCase;
+use Psr\Log\LogLevel;
+
+class LogEntryTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Models\LogEntry::filter
+ */
+ public function testFilter()
+ {
+ foreach ([
+ 'Lorem Ipsum' => LogLevel::INFO,
+ 'Some test content' => LogLevel::ERROR,
+ 'Foo bar bartz!' => LogLevel::INFO,
+ 'Someone did something?' => LogLevel::NOTICE,
+ 'This is a Test!' => LogLevel::INFO,
+ 'I\'m verbose notice!' => LogLevel::DEBUG,
+ 'The newest stuff!!' => LogLevel::ERROR,
+ ] as $message => $level) {
+ $entry = new LogEntry(['level' => $level, 'message' => $message]);
+ $entry->save();
+ }
+
+ $model = new LogEntry();
+
+ $return = $model->filter();
+ $this->assertCount(7, $return);
+
+ /** @var LogEntry $first */
+ $first = $return->first();
+
+ $this->assertEquals('The newest stuff!!', $first->message);
+
+ $return = $model->filter(LogLevel::INFO);
+ $this->assertCount(3, $return);
+
+ $return = $model->filter('notice');
+ $this->assertCount(2, $return);
+
+ $return = $model->filter('bartz');
+ $this->assertCount(1, $return);
+ }
+
+ /**
+ * This method is called before a test is executed.
+ */
+ public function setUp()
+ {
+ LogEntry::query()->truncate();
+ }
+}