Fixed error when formatting empty hook.

Prop @kellymears Closes #30
This commit is contained in:
Andrey Savchenko committed 2019-03-24 19:52:42 +02:00
1 parent 739ed7dd90
commit ba72763486
3 files changed
+11

No files matched your search

+3
View File
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed ### Changed
- unit tests for PHPUnit 8 - unit tests for PHPUnit 8
### Fixed
- error when formatting empty hook.
## 3.2 - 2019-01-30 ## 3.2 - 2019-01-30
### Added ### Added
+6
View File
@@ -16,6 +16,7 @@ class Hook_Formatter {
*/ */
public function __construct() { public function __construct() {
// TODO inject paths instead of reaching for global constants.
$this->truncate_paths = [ $this->truncate_paths = [
wp_normalize_path( WP_CONTENT_DIR ), wp_normalize_path( WP_CONTENT_DIR ),
wp_normalize_path( ABSPATH ), wp_normalize_path( ABSPATH ),
@@ -35,6 +36,11 @@ class Hook_Formatter {
if ( $hook instanceof \WP_Hook ) { if ( $hook instanceof \WP_Hook ) {
$hook = $hook->callbacks; $hook = $hook->callbacks;
} }
if ( empty( $hook ) ) {
return $callbacks;
}
ksort( $hook ); ksort( $hook );
$functions = array_merge( ...$hook ); $functions = array_merge( ...$hook );
+2
View File
@@ -55,6 +55,8 @@ class HookTest extends LapsTestCase {
$this->assertEquals( 'class::method', $result[1] ); $this->assertEquals( 'class::method', $result[1] );
$this->assertStringStartsWith( 'closure from', $result[2] ); $this->assertStringStartsWith( 'closure from', $result[2] );
$this->assertStringStartsWith( 'anonymous class from', $result[3] ); $this->assertStringStartsWith( 'anonymous class from', $result[3] );
$this->assertEquals( [], $formatter->format( [] ) );
} }
} }