From 4dbcddad8de39233f8e890f2833295136931ad55 Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Mon, 26 Mar 2018 19:43:49 +0300 Subject: [PATCH] Added backtrace formatter test. --- tests/Formatter/BacktraceTest.php | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/Formatter/BacktraceTest.php diff --git a/tests/Formatter/BacktraceTest.php b/tests/Formatter/BacktraceTest.php new file mode 100644 index 0000000..eba951c --- /dev/null +++ b/tests/Formatter/BacktraceTest.php @@ -0,0 +1,58 @@ +zeroOrMoreTimes()->andReturnFirstArg(); + + return new Backtrace_Formatter(); + } + + /** + * @depends test__construct + */ + public function testFormat( Backtrace_Formatter $formatter ) { + + if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', '/wp' ); + define( 'WP_CONTENT_DIR', '/wp-content/' ); + } + + Functions\expect( 'wp_normalize_path' )->zeroOrMoreTimes()->andReturnFirstArg(); + + $backtrace = [ + 'template-loader.php', + 'WP_Hook->do_action', + 'foo', + "include('/wp/path.php')", + ]; + + $backtrace = implode( ', ', $backtrace ); + + $result = $formatter->format( $backtrace ); + + $this->assertInternalType( 'array', $result ); + $this->assertArraySubset( [ 'foo', 'path.php' ], array_values( $result ) ); + } +} +