Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-logs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-logs
Commits
9f68dc1f
Commit
9f68dc1f
authored
6 years ago
by
dyszczo
Browse files
Options
Downloads
Patches
Plain Diff
tests our factory
parent
4a8c2d13
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!3
Devel
,
!2
Feature/tests
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
phpunit-integration.xml
+4
-0
4 additions, 0 deletions
phpunit-integration.xml
tests/integration/TestWPDeskLoggerFactory.php
+102
-26
102 additions, 26 deletions
tests/integration/TestWPDeskLoggerFactory.php
with
106 additions
and
26 deletions
phpunit-integration.xml
+
4
−
0
View file @
9f68dc1f
<phpunit
bootstrap=
"tests/integration/bootstrap.php"
<phpunit
bootstrap=
"tests/integration/bootstrap.php"
backupGlobals=
"false"
backupGlobals=
"false"
convertErrorsToExceptions=
"true"
convertNoticesToExceptions=
"true"
convertWarningsToExceptions=
"true"
strict=
"true"
>
>
<testsuites>
<testsuites>
<testsuite>
<testsuite>
...
...
This diff is collapsed.
Click to expand it.
tests/integration/TestWPDeskLoggerFactory.php
+
102
−
26
View file @
9f68dc1f
<?php
<?php
use
Monolog\Handler\AbstractHandler
;
use
Monolog\Logger
;
use
Monolog\Logger
;
use
PHPUnit\Framework\Error\Notice
;
use
WPDesk\Logger\WC\WooCommerceMonologPlugin
;
use
WPDesk\Logger\WC\WooCommerceMonologPlugin
;
use
WPDesk\Logger\WPDeskLoggerFactory
;
use
WPDesk\Logger\WPDeskLoggerFactory
;
...
@@ -9,6 +11,11 @@ class TestWPDeskLoggerFactory extends WP_UnitTestCase
...
@@ -9,6 +11,11 @@ class TestWPDeskLoggerFactory extends WP_UnitTestCase
public
function
setUp
()
public
function
setUp
()
{
{
parent
::
setUp
();
parent
::
setUp
();
$this
->
setWordpressOptionsForWPDeskLoggerToWork
();
}
private
function
setWordpressOptionsForWPDeskLoggerToWork
()
{
update_option
(
'wpdesk_helper_options'
,
[
update_option
(
'wpdesk_helper_options'
,
[
'debug_log'
=>
'1'
'debug_log'
=>
'1'
]);
]);
...
@@ -27,36 +34,105 @@ class TestWPDeskLoggerFactory extends WP_UnitTestCase
...
@@ -27,36 +34,105 @@ class TestWPDeskLoggerFactory extends WP_UnitTestCase
$this
->
assertTrue
(
$factory
->
isWPDeskLogWorking
());
$this
->
assertTrue
(
$factory
->
isWPDeskLogWorking
());
}
}
public
function
testWCIsCaptured
()
public
function
testWCIsNotCorruptedByOtherTests
()
{
$this
->
assertInstanceOf
(
WC_Logger
::
class
,
wc_get_logger
(),
"Logger should be NOT captured by default."
);
}
public
function
testWCLoggingIsCapturedByOurLogs
()
{
{
(
new
WPDeskLoggerFactory
())
->
createWPDeskLogger
();
(
new
WPDeskLoggerFactory
())
->
createWPDeskLogger
();
$this
->
assertInstanceOf
(
WooCommerceMonologPlugin
::
class
,
wc_get_logger
(),
"Logger should be captured."
);
$this
->
assertInstanceOf
(
WooCommerceMonologPlugin
::
class
,
wc_get_logger
(),
"Logger should be captured."
);
}
}
// public function testErrorsAreCaptured()
public
function
testOurLogsGetAllErrors
()
// {
{
//
$someMessage
=
'whatever'
;
// }
$errorType
=
E_USER_NOTICE
;
//
//
$logger
=
(
new
WPDeskLoggerFactory
())
->
createWPDeskLogger
();
// public function testLoggerCanLogWC()
$logger
->
pushHandler
(
$this
->
prepareListenHandleThatIsWaitingForMessage
(
'E_USER_NOTICE: '
.
$someMessage
));
// {
$this
->
expectException
(
Notice
::
class
);
//
trigger_error
(
$someMessage
,
$errorType
);
// }
}
//
// public function testLoggerCanLogDirectly()
/**
// {
* Prepares listener that check if logger gets sent message
//
*
// }
* @param $message
//
* @return AbstractHandler
// public function testHandleToFile()
*/
// {
private
function
prepareListenHandleThatIsWaitingForMessage
(
$message
)
//
{
// }
$listenHandle
=
$this
->
createMock
(
AbstractHandler
::
class
);
//
// public function testHandleToWc()
$listenHandle
// {
->
expects
(
$this
->
atLeastOnce
())
//
->
method
(
'handle'
)
// }
->
with
(
$this
->
callback
(
function
(
$record
)
use
(
$message
)
{
$this
->
assertEquals
(
$message
,
$record
[
'message'
],
"Monolog should get message sent to logger"
);
return
$record
[
'message'
]
===
$message
;
}))
->
willReturn
(
true
);
$listenHandle
->
expects
(
$this
->
atLeastOnce
())
->
method
(
'isHandling'
)
->
willReturn
(
true
);
/** @var $listenHandle AbstractHandler */
return
$listenHandle
;
}
public
function
testOurLogsGetAllMessagesLoggedToWC
()
{
$someMessage
=
'whatever'
;
$logger
=
(
new
WPDeskLoggerFactory
())
->
createWPDeskLogger
();
$logger
->
pushHandler
(
$this
->
prepareListenHandleThatIsWaitingForMessage
(
$someMessage
));
wc_get_logger
()
->
debug
(
$someMessage
);
}
public
function
testLoggerWorksAndCanLogInGeneral
()
{
$someMessage
=
'whatever'
;
$logger
=
(
new
WPDeskLoggerFactory
())
->
createWPDeskLogger
();
$logger
->
pushHandler
(
$this
->
prepareListenHandleThatIsWaitingForMessage
(
$someMessage
));
$logger
->
debug
(
$someMessage
);
}
public
function
testAllLoggedMessagesAreWrittenToWPDeskFile
()
{
$someMessage
=
'whatever'
;
$factory
=
new
WPDeskLoggerFactory
();
$logFilename
=
$factory
->
getWPDeskFileName
();
unlink
(
$logFilename
);
$this
->
assertFileNotExists
(
$logFilename
);
$logger
=
$factory
->
createWPDeskLogger
();
$logger
->
debug
(
$someMessage
);
$this
->
assertFileExists
(
$logFilename
);
}
public
function
testAllLoggedMessagesAreWrittenToWC
()
{
$mockWcLogger
=
$this
->
createMock
(
WC_Logger
::
class
);
$mockWcLogger
->
expects
(
$this
->
atLeastOnce
())
->
method
(
'log'
)
->
willReturn
(
true
);
add_filter
(
'woocommerce_logging_class'
,
function
()
use
(
$mockWcLogger
)
{
return
$mockWcLogger
;
},
0
,
100
);
$someMessage
=
'whatever'
;
$logger
=
(
new
WPDeskLoggerFactory
())
->
createWPDeskLogger
();
$logger
->
debug
(
$someMessage
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment