Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
880729b1
Commit
880729b1
authored
Apr 03, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MonologExtension] initial test case, Monolog submodule, minor adjustments to ease testability
parent
29242300
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
2 deletions
+86
-2
.gitmodules
.gitmodules
+3
-0
src/Silex/Extension/MonologExtension.php
src/Silex/Extension/MonologExtension.php
+11
-2
tests/Silex/Tests/Extension/MonologExtensionTest.php
tests/Silex/Tests/Extension/MonologExtensionTest.php
+71
-0
vendor/monolog
vendor/monolog
+1
-0
No files found.
.gitmodules
View file @
880729b1
...
...
@@ -31,3 +31,6 @@
[submodule "vendor/twig"]
path = vendor/twig
url = https://github.com/fabpot/Twig
[submodule "vendor/monolog"]
path = vendor/monolog
url = https://github.com/Seldaek/monolog.git
src/Silex/Extension/MonologExtension.php
View file @
880729b1
...
...
@@ -32,10 +32,19 @@ class MonologExtension implements ExtensionInterface
});
$app
[
'monolog.configure'
]
=
$app
->
protect
(
function
(
$log
)
use
(
$app
)
{
$level
=
isset
(
$app
[
'monolog.level'
])
?
$app
[
'monolog.level'
]
:
Logger
::
DEBUG
;
$log
->
pushHandler
(
new
StreamHandler
(
$app
[
'monolog.logfile'
],
$level
));
$log
->
pushHandler
(
$app
[
'monolog.handler'
]);
});
$app
[
'monolog.handler'
]
=
function
()
use
(
$app
)
{
return
new
StreamHandler
(
$app
[
'monolog.logfile'
],
$app
[
'monolog.level'
]);
};
if
(
!
isset
(
$app
[
'monolog.level'
]))
{
$app
[
'monolog.level'
]
=
function
()
{
return
Logger
::
DEBUG
;
};
}
if
(
isset
(
$app
[
'monolog.class_path'
]))
{
$app
[
'autoloader'
]
->
registerNamespace
(
'Monolog'
,
$app
[
'monolog.class_path'
]);
}
...
...
tests/Silex/Tests/Extension/MonologExtensionTest.php
0 → 100644
View file @
880729b1
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests
;
use
Monolog\Handler\TestHandler
;
use
Silex\Application
;
use
Silex\Extension\MonologExtension
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* MonologExtension test cases.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class
MonologExtensionTest
extends
\PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
if
(
!
is_dir
(
__DIR__
.
'/../../../../vendor/monolog/src'
))
{
$this
->
markTestSkipped
(
'Monolog submodule was not installed.'
);
}
}
public
function
testRegisterAndRender
()
{
$app
=
new
Application
();
$app
->
register
(
new
MonologExtension
(),
array
(
'monolog.class_path'
=>
__DIR__
.
'/../../../../vendor/monolog/src'
,
));
$app
[
'monolog.handler'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
return
new
TestHandler
(
$app
[
'monolog.level'
]);
});
$app
->
get
(
'/log'
,
function
()
use
(
$app
)
{
$app
[
'monolog'
]
->
addDebug
(
'logging a message'
);
});
$app
->
get
(
'/error'
,
function
()
{
throw
new
\RuntimeException
(
'very bad error'
);
});
$app
->
error
(
function
(
\Exception
$e
)
{
return
'error handled'
;
});
$this
->
assertFalse
(
$app
[
'monolog.handler'
]
->
hasDebugRecords
());
$this
->
assertFalse
(
$app
[
'monolog.handler'
]
->
hasErrorRecords
());
$request
=
Request
::
create
(
'/log'
);
$app
->
handle
(
$request
);
$request
=
Request
::
create
(
'/error'
);
$app
->
handle
(
$request
);
$this
->
assertTrue
(
$app
[
'monolog.handler'
]
->
hasDebugRecords
());
$this
->
assertTrue
(
$app
[
'monolog.handler'
]
->
hasErrorRecords
());
}
}
monolog
@
b90eddd5
Subproject commit b90eddd5130c4ca5238cb497a4a743a5145a509d
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