Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
0ea05a64
Commit
0ea05a64
authored
Nov 06, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added unit tests for logger and log target
related to #1151
parent
086326b1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
0 deletions
+125
-0
LoggerTest.php
tests/unit/framework/log/LoggerTest.php
+34
-0
TargetTest.php
tests/unit/framework/log/TargetTest.php
+91
-0
No files found.
tests/unit/framework/log/LoggerTest.php
0 → 100644
View file @
0ea05a64
<?php
/**
* @author Carsten Brandt <mail@cebe.cc>
*/
namespace
yiiunit\framework\log
;
use
yii\debug\LogTarget
;
use
yii\log\FileTarget
;
use
yii\log\Logger
;
use
yiiunit\TestCase
;
class
LoggerTest
extends
TestCase
{
public
function
testLog
()
{
$logger
=
new
Logger
();
$logger
->
log
(
'test1'
,
Logger
::
LEVEL_INFO
);
$this
->
assertEquals
(
1
,
count
(
$logger
->
messages
));
$this
->
assertEquals
(
'test1'
,
$logger
->
messages
[
0
][
0
]);
$this
->
assertEquals
(
Logger
::
LEVEL_INFO
,
$logger
->
messages
[
0
][
1
]);
$this
->
assertEquals
(
'application'
,
$logger
->
messages
[
0
][
2
]);
$logger
->
log
(
'test2'
,
Logger
::
LEVEL_ERROR
,
'category'
);
$this
->
assertEquals
(
2
,
count
(
$logger
->
messages
));
$this
->
assertEquals
(
'test2'
,
$logger
->
messages
[
1
][
0
]);
$this
->
assertEquals
(
Logger
::
LEVEL_ERROR
,
$logger
->
messages
[
1
][
1
]);
$this
->
assertEquals
(
'category'
,
$logger
->
messages
[
1
][
2
]);
}
}
\ No newline at end of file
tests/unit/framework/log/TargetTest.php
0 → 100644
View file @
0ea05a64
<?php
/**
* @author Carsten Brandt <mail@cebe.cc>
*/
namespace
yiiunit\framework\log
;
use
yii\debug\LogTarget
;
use
yii\log\FileTarget
;
use
yii\log\Logger
;
use
yii\log\Target
;
use
yiiunit\TestCase
;
class
TargetTest
extends
TestCase
{
public
static
$messages
;
public
function
filters
()
{
return
[
[[],
[
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
,
'G'
,
'H'
]],
[[
'levels'
=>
0
],
[
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
,
'G'
,
'H'
]],
[
[
'levels'
=>
Logger
::
LEVEL_INFO
|
Logger
::
LEVEL_WARNING
|
Logger
::
LEVEL_ERROR
|
Logger
::
LEVEL_TRACE
],
[
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
,
'G'
,
'H'
]
],
[[
'levels'
=>
[
'error'
]],
[
'B'
,
'G'
,
'H'
]],
[[
'levels'
=>
Logger
::
LEVEL_ERROR
],
[
'B'
,
'G'
,
'H'
]],
[[
'levels'
=>
[
'error'
,
'warning'
]],
[
'B'
,
'C'
,
'G'
,
'H'
]],
[[
'levels'
=>
Logger
::
LEVEL_ERROR
|
Logger
::
LEVEL_WARNING
],
[
'B'
,
'C'
,
'G'
,
'H'
]],
[[
'categories'
=>
[
'application'
]],
[
'A'
,
'B'
,
'C'
,
'D'
,
'E'
]],
[[
'categories'
=>
[
'application*'
]],
[
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
]],
[[
'categories'
=>
[
'application.*'
]],
[
'F'
]],
[[
'categories'
=>
[
'application.components'
]],
[]],
[[
'categories'
=>
[
'application.components.Test'
]],
[
'F'
]],
[[
'categories'
=>
[
'application.components.*'
]],
[
'F'
]],
[[
'categories'
=>
[
'application.*'
,
'yii.db.*'
]],
[
'F'
,
'G'
,
'H'
]],
[[
'categories'
=>
[
'application.*'
,
'yii.db.*'
],
'except'
=>
[
'yii.db.Command.*'
]],
[
'F'
,
'G'
]],
[[
'categories'
=>
[
'application'
,
'yii.db.*'
],
'levels'
=>
Logger
::
LEVEL_ERROR
],
[
'B'
,
'G'
,
'H'
]],
[[
'categories'
=>
[
'application'
],
'levels'
=>
Logger
::
LEVEL_ERROR
],
[
'B'
]],
[[
'categories'
=>
[
'application'
],
'levels'
=>
Logger
::
LEVEL_ERROR
|
Logger
::
LEVEL_WARNING
],
[
'B'
,
'C'
]],
];
}
/**
* @dataProvider filters
*/
public
function
testFilter
(
$filter
,
$expected
)
{
static
::
$messages
=
[];
$logger
=
new
Logger
([
'targets'
=>
[
new
TestTarget
(
array_merge
(
$filter
,
[
'logVars'
=>
[]]))],
'flushInterval'
=>
1
,
]);
$logger
->
log
(
'testA'
,
Logger
::
LEVEL_INFO
);
$logger
->
log
(
'testB'
,
Logger
::
LEVEL_ERROR
);
$logger
->
log
(
'testC'
,
Logger
::
LEVEL_WARNING
);
$logger
->
log
(
'testD'
,
Logger
::
LEVEL_TRACE
);
$logger
->
log
(
'testE'
,
Logger
::
LEVEL_INFO
,
'application'
);
$logger
->
log
(
'testF'
,
Logger
::
LEVEL_INFO
,
'application.components.Test'
);
$logger
->
log
(
'testG'
,
Logger
::
LEVEL_ERROR
,
'yii.db.Command'
);
$logger
->
log
(
'testH'
,
Logger
::
LEVEL_ERROR
,
'yii.db.Command.whatever'
);
$this
->
assertEquals
(
count
(
$expected
),
count
(
static
::
$messages
));
$i
=
0
;
foreach
(
$expected
as
$e
)
{
$this
->
assertEquals
(
'test'
.
$e
,
static
::
$messages
[
$i
++
][
0
]);
}
}
}
class
TestTarget
extends
Target
{
public
$exportInterval
=
1
;
/**
* Exports log [[messages]] to a specific destination.
* Child classes must implement this method.
*/
public
function
export
()
{
TargetTest
::
$messages
=
array_merge
(
TargetTest
::
$messages
,
$this
->
messages
);
$this
->
messages
=
[];
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment