Skip to content

Commit

Permalink
Merge pull request #3 from conduit-innovation/develop-1.0
Browse files Browse the repository at this point in the history
Improve test coverage / metrics
  • Loading branch information
talss89 authored Apr 30, 2023
2 parents f62ac08 + d870d4d commit 040bb5b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ composer.phar
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
clover.xml
cov.xml
.DS_Store
phpunit.xml.bak
/.phpunit.cache/
/.phpunit.cache/
/coverage/
3 changes: 2 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
</source>
<coverage pathCoverage="true">
<report>
<clover outputFile="clover.xml" />
<clover outputFile="cov.xml" />
<html outputDirectory="coverage/" />
</report>
</coverage>
</phpunit>
6 changes: 3 additions & 3 deletions src/class/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ private function find_callbacks(string | \Closure | array $needle, $haystack): a
* @param mixed $priority
* @return void
*/
private function add_to_wp_filter_structure(array &$wp_filter, string $hook_name, callable | array $callbacks, int $priority) {

private function add_to_wp_filter_structure(array &$wp_filter, string $hook_name, array $callbacks, int $priority) {
if(!isset($wp_filter[$hook_name])) {
$wp_filter[$hook_name] = [$priority => []];
}
Expand All @@ -136,6 +136,6 @@ private function add_to_wp_filter_structure(array &$wp_filter, string $hook_name
$wp_filter[$hook_name][$priority] = [];
}

$wp_filter[$hook_name][$priority] += is_array($callbacks) ? $callbacks : [$callbacks];
$wp_filter[$hook_name][$priority] += $callbacks;
}
}
17 changes: 17 additions & 0 deletions tests/HookCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use MonkeyHook\HookCollection;
use MonkeyHook\Hook;

use function MonkeyHook\find_filters;

final class HookCollectionTest extends WPFilterTestCase {
public function testArrayAccessIterable() {

Expand Down Expand Up @@ -50,4 +52,19 @@ public function testArrayAccessIterable() {
$this->assertEquals('bar', $collection->current()->hook_name);
}

public function testRemoveOnCollection() {

global $wp_filters;

add_action('foo', 'foo');
add_action('foo', 'bar');
add_action('foo', 'baz');

$hooks = find_filters('foo');

$hooks->remove();

$this->assertCount(3, $hooks);
}

}
1 change: 0 additions & 1 deletion tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ public function testFindAllStaticMethods() {
$hooks = find_filters('test', 'MonkeyHook\Mock\MockClass::');
$this->assertCount(2, $hooks);
}

}

0 comments on commit 040bb5b

Please sign in to comment.