@@ -48,8 +48,8 @@ protected function getEnvironmentSetUp($app)
4848 'options ' => [
4949 //'database' => 'admin' // sets the authentication database required by mongo 3
5050 ]
51- ],]
52- );
51+ ],
52+ ] );
5353
5454 $ app ['config ' ]->set ('logging.default ' , 'stack ' );
5555 $ app ['config ' ]->set ('logging.channels ' , [
@@ -100,11 +100,21 @@ protected function getPackageProviders($app)
100100 ];
101101 }
102102
103+ /**
104+ * Basic test to see if class can be instanced.
105+ *
106+ * @group basic
107+ */
103108 public function testClassInit () {
104109 $ test = new LogToDB ();
105110 $ this ->assertInstanceOf ('danielme85\LaravelLogToDB\LogToDB ' , $ test );
106111 }
107112
113+ /**
114+ * Run basic log levels
115+ *
116+ * @group basic
117+ */
108118 public function testLogLevels () {
109119 Log::debug ("This is an test DEBUG log event " );
110120 Log::info ("This is an test INFO log event " );
@@ -118,12 +128,17 @@ public function testLogLevels() {
118128 //Check mysql
119129 $ logReader = LogToDB::model ()->get ()->toArray ();
120130 $ logReaderMongoDB = LogToDB::model ('mongodb ' )->get ()->toArray ();
121- $ logReaderSpecific = LogToDB::model ('database ' , 'mysql ' , 'log ' )->get ()->toArray ();
131+ $ logReaderSpecific = LogToDB::model ('database ' , 'mysql ' , 'LogSql ' )->get ()->toArray ();
122132 $ this ->assertCount (8 , $ logReader );
123133 $ this ->assertCount (8 , $ logReaderMongoDB );
124134 $ this ->assertCount (8 , $ logReaderSpecific );
125135 }
126136
137+ /**
138+ * Test logging to specific channels
139+ *
140+ * @group advanced
141+ */
127142 public function testLoggingToChannels () {
128143 //Test limited config, with limited rows and level
129144 Log::channel ('limited ' )->debug ("This message should not be stored because DEBUG is LOWER then WARNING " );
@@ -134,6 +149,11 @@ public function testLoggingToChannels() {
134149 $ this ->assertNotEmpty (LogToDB::model ('limited ' )->where ('channel ' , 'limited ' )->where ('level_name ' , 'WARNING ' )->get ()->toArray ());
135150 }
136151
152+ /**
153+ * Test an exception error.
154+ *
155+ * @group advanced
156+ */
137157 public function testException () {
138158 $ e = new Symfony \Component \HttpKernel \Exception \BadRequestHttpException ("This is a fake 500 error " , null , 500 , ['fake-header ' => 'value ' ]);
139159 Log::warning ("Error " , ['exception ' => $ e , 'more ' => 'infohere ' ]);
@@ -142,8 +162,9 @@ public function testException() {
142162 }
143163
144164 /**
145- * @group queue
165+ * Test queuing the log events.
146166 *
167+ * @group queue
147168 */
148169 public function testQueue () {
149170 Queue::fake ();
@@ -167,8 +188,87 @@ public function testQueue() {
167188 }
168189
169190 /**
170- * @group cleanup
171191 *
192+ * @group model
193+ */
194+ public function testModelInteraction () {
195+ $ model = LogToDB::model ();
196+ //Get all
197+ $ all = $ model ->get ();
198+ $ this ->assertNotEmpty ($ all ->toArray ());
199+ //Get Debug
200+ $ logs = $ model ->where ('level_name ' , '= ' , 'DEBUG ' )->get ()->toArray ();
201+ $ this ->assertNotEmpty ($ logs );
202+ $ this ->assertEquals ('DEBUG ' , $ logs [0 ]['level_name ' ]);
203+
204+ $ model = LogToDB::model ('database ' );
205+ //Get all
206+ $ all = $ model ->get ();
207+ $ this ->assertNotEmpty ($ all ->toArray ());
208+ //Get Debug
209+ $ logs = $ model ->where ('level_name ' , '= ' , 'DEBUG ' )->get ()->toArray ();
210+ $ this ->assertNotEmpty ($ logs );
211+ $ this ->assertEquals ('DEBUG ' , $ logs [0 ]['level_name ' ]);
212+
213+ $ model = LogToDB::model (null , 'mysql ' );
214+ //Get all
215+ $ all = $ model ->get ();
216+ $ this ->assertNotEmpty ($ all ->toArray ());
217+ //Get Debug
218+ $ logs = $ model ->where ('level_name ' , '= ' , 'DEBUG ' )->get ()->toArray ();
219+ $ this ->assertNotEmpty ($ logs );
220+ $ this ->assertEquals ('DEBUG ' , $ logs [0 ]['level_name ' ]);
221+
222+ $ model = LogToDB::model ('database ' , 'mysql ' , 'log ' );
223+ //Get all
224+ $ all = $ model ->get ();
225+ $ this ->assertNotEmpty ($ all ->toArray ());
226+ //Get Debug
227+ $ logs = $ model ->where ('level_name ' , '= ' , 'DEBUG ' )->get ()->toArray ();
228+ $ this ->assertNotEmpty ($ logs );
229+ $ this ->assertEquals ('DEBUG ' , $ logs [0 ]['level_name ' ]);
230+
231+ //Same tests for mongoDB
232+ $ modelMongo = LogToDB::model ('mongodb ' );
233+ //Get all
234+ $ all = $ modelMongo ->get ();
235+ $ this ->assertNotEmpty ($ all ->toArray ());
236+ //Get Debug
237+ $ logs = $ modelMongo ->where ('level_name ' , '= ' , 'DEBUG ' )->get ()->toArray ();
238+ $ this ->assertNotEmpty ($ logs );
239+ $ this ->assertEquals ('DEBUG ' , $ logs [0 ]['level_name ' ]);
240+
241+ //Same tests for mongoDB
242+ $ modelMongo = LogToDB::model ('mongodb ' , 'mongodb ' , 'log ' );
243+ //Get all
244+ $ all = $ modelMongo ->get ();
245+ $ this ->assertNotEmpty ($ all ->toArray ());
246+ //Get Debug
247+ $ logs = $ modelMongo ->where ('level_name ' , '= ' , 'DEBUG ' )->get ()->toArray ();
248+ $ this ->assertNotEmpty ($ logs );
249+ $ this ->assertEquals ('DEBUG ' , $ logs [0 ]['level_name ' ]);
250+
251+ //Same tests for mongoDB
252+ $ modelMongo = LogToDB::model (null , 'mongodb ' );
253+ //Get all
254+ $ all = $ modelMongo ->get ();
255+ $ this ->assertNotEmpty ($ all ->toArray ());
256+ //Get Debug
257+ $ logs = $ modelMongo ->where ('level_name ' , '= ' , 'DEBUG ' )->get ()->toArray ();
258+ $ this ->assertNotEmpty ($ logs );
259+ $ this ->assertEquals ('DEBUG ' , $ logs [0 ]['level_name ' ]);
260+
261+ }
262+
263+ public function testStandAloneModels () {
264+ $ this ->assertNotEmpty (LogSql::get ()->toArray ());
265+ $ this ->assertNotEmpty (LogMongo::get ()->toArray ());
266+ }
267+
268+ /**
269+ * Test the cleanup functions.
270+ *
271+ * @group cleanup
172272 */
173273 public function testRemoves () {
174274 $ this ->assertTrue (LogToDB::model ()->removeOldestIfMoreThen (1 ));
@@ -178,6 +278,9 @@ public function testRemoves() {
178278 $ this ->assertFalse (LogToDB::model ('mongodb ' )->removeOlderThen (date ('Y-m-d ' )));
179279 }
180280
281+ /**
282+ * Clear all data from the test.
283+ */
181284 public function testCleanup () {
182285 LogToDB::model ()->truncate ();
183286 LogToDB::model ('mongodb ' )->truncate ();
0 commit comments