Skip to content

Commit

Permalink
[!]: "php": ">=7.0" v2
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Oct 19, 2018
1 parent 3cf4bda commit 80ba5dd
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 41 deletions.
9 changes: 6 additions & 3 deletions tests/HooksActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ public function testAction()
{
$done = false;

$this->hooks->add_action('bar', function () use (&$done) {
$done = true;
});
$this->hooks->add_action(
'bar',
function () use (&$done) {
$done = true;
}
);

$this->hooks->do_action('bar');

Expand Down
8 changes: 5 additions & 3 deletions tests/HooksFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class HooksFilterTest extends \PHPUnit\Framework\TestCase
*/
public function testFilter()
{
$this->hooks->add_filter('foo', function ($content) {
return '<b>' . $content . '</b>';
});
$this->hooks->add_filter(
'foo', function ($content) {
return '<b>' . $content . '</b>';
}
);

self::assertSame('<b>Hello world</b>', $this->hooks->apply_filters('foo', 'Hello world'));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/HooksFooBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public function doSomethingFunction($attrs, $content = '')

extract(
\voku\helper\Hooks::getInstance()->shortcode_atts(
array(
[
'foo',
),
],
$attrs
),
EXTR_OVERWRITE
Expand Down
6 changes: 3 additions & 3 deletions tests/HooksShortcodeStrictTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function parse_youtube($attrs)

extract(
$hooks->shortcode_atts(
array(
[
'autoplay',
'noControls',
'list' => null,
Expand All @@ -47,7 +47,7 @@ public function parse_youtube($attrs)
'color' => 'red',
'theme' => 'dark',
'start' => 0,
),
],
$attrs
),
EXTR_OVERWRITE
Expand Down Expand Up @@ -75,7 +75,7 @@ public function parse_youtube($attrs)
public function testShortcode()
{
$hooks = Hooks::getInstance();
$hooks->add_shortcode('youtube', array($this, 'parse_youtube'));
$hooks->add_shortcode('youtube', [$this, 'parse_youtube']);

$default_content = '[youtube id=iCUV3iv9xOs color=white theme=light]';
$parsed_content = $hooks->do_shortcode($default_content);
Expand Down
6 changes: 3 additions & 3 deletions tests/HooksShortcodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function parse_youtube($attrs)

extract(
$hooks->shortcode_atts(
array(
[
'autoplay',
'noControls',
'list' => null,
Expand All @@ -45,7 +45,7 @@ public function parse_youtube($attrs)
'color' => 'red',
'theme' => 'dark',
'start' => 0,
),
],
$attrs
),
EXTR_OVERWRITE
Expand Down Expand Up @@ -73,7 +73,7 @@ public function parse_youtube($attrs)
public function testShortcode()
{
$hooks = Hooks::getInstance();
$hooks->add_shortcode('youtube', array($this, 'parse_youtube'));
$hooks->add_shortcode('youtube', [$this, 'parse_youtube']);

$default_content = '[youtube id=iCUV3iv9xOs color=white theme=light]';
$parsed_content = $hooks->do_shortcode($default_content);
Expand Down
28 changes: 14 additions & 14 deletions tests/HooksStrictTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function hookTestString_2($input)
*/
public function testHooks()
{
$this->hooks->add_filter('test_strict', array($this, 'hookTestString_1'));
$this->hooks->add_filter('test_strict', array($this, 'hookTestString_2'));
$this->hooks->add_filter('test_strict', [$this, 'hookTestString_1']);
$this->hooks->add_filter('test_strict', [$this, 'hookTestString_2']);

$lall = $this->hooks->apply_filters('test_strict', '');

Expand All @@ -67,7 +67,7 @@ public function testHooksInstance()
{
$lall = $this->hooks->apply_filters('test_strict', '');

self::assertSame($this->testString_1 . $this->testString_2, $lall, );
self::assertSame($this->testString_1 . $this->testString_2, $lall);
}

public function testHasFunctions()
Expand Down Expand Up @@ -163,34 +163,34 @@ public function testRunHookFunctions()
self::assertSame(true, $hooks->remove_all_actions('testAction'));

self::assertSame(false, $hooks->do_action('testAction'));
self::assertSame(false, $hooks->do_action_ref_array('testNotExistingAction', array()));
self::assertSame(false, $hooks->do_action_ref_array('testNotExistingAction', []));
self::assertSame('Foo', $hooks->apply_filters('testFilter', 'Foo'));

self::assertSame(false, $hooks->do_action_ref_array('testAction', array('test')));
self::assertSame('Foo', $hooks->apply_filters_ref_array('testFilter', array('Foo')));
self::assertSame(false, $hooks->do_action_ref_array('testAction', ['test']));
self::assertSame('Foo', $hooks->apply_filters_ref_array('testFilter', ['Foo']));

$mock = $this->getMockBuilder('stdClass')->setMethods( array('doSomeAction', 'applySomeFilter'))->getMock();
$mock = $this->getMockBuilder('stdClass')->setMethods(['doSomeAction', 'applySomeFilter'])->getMock();
$mock->expects(self::exactly(4))->method('doSomeAction');
$mock->expects(self::exactly(10))->method('applySomeFilter')->willReturn('foo');

self::assertSame(true, $hooks->add_action('testAction', array($mock, 'doSomeAction')));
self::assertSame(true, $hooks->add_filter('testFilter', array($mock, 'applySomeFilter')));
self::assertSame(true, $hooks->add_action('testAction', [$mock, 'doSomeAction']));
self::assertSame(true, $hooks->add_filter('testFilter', [$mock, 'applySomeFilter']));

self::assertSame(2, $hooks->did_action('testAction'));
self::assertSame(true, $hooks->do_action('testAction'));
self::assertSame(3, $hooks->did_action('testAction'));
self::assertSame('foo', $hooks->apply_filters('testFilter', 'Foo'));

self::assertSame(true, $hooks->add_filter('all', array($mock, 'applySomeFilter')));
self::assertSame(true, $hooks->add_filter('all', [$mock, 'applySomeFilter']));

self::assertSame(false, $hooks->do_action('notExistingAction'));
self::assertSame('Foo', $hooks->apply_filters('notExistingFilter', 'Foo')); // unmodified value

self::assertSame(true, $hooks->do_action('testAction', (object)array('foo' => 'bar')));
self::assertSame(true, $hooks->do_action('testAction', (object)['foo' => 'bar']));
self::assertSame(true, $hooks->do_action('testAction', 'param1', 'param2', 'param3', 'param4'));
self::assertSame(true, $hooks->do_action_ref_array('testAction', array('test')));
self::assertSame(true, $hooks->do_action_ref_array('testAction', ['test']));
self::assertSame('foo', $hooks->apply_filters('testFilter', 'Foo'));
self::assertSame('foo', $hooks->apply_filters_ref_array('testFilter', array('Foo')));
self::assertSame('foo', $hooks->apply_filters_ref_array('testFilter', ['Foo']));
}

public function testRunShortcodeFunctions()
Expand All @@ -204,7 +204,7 @@ public function testRunShortcodeFunctions()
self::assertSame('testAction', $hooks->do_shortcode('testAction'));

$testClass = new HooksFooBar();
self::assertSame(true, $hooks->add_shortcode('testAction', array($testClass, 'doSomethingFunction')));
self::assertSame(true, $hooks->add_shortcode('testAction', [$testClass, 'doSomethingFunction']));
self::assertTrue($hooks->shortcode_exists('testAction'));

self::assertSame('foo bar <li class="">content</li>', $hooks->do_shortcode('foo bar [testAction foo="bar"]content[/testAction]'));
Expand Down
27 changes: 14 additions & 13 deletions tests/HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function hookTestString_2($input)
*/
public function testHooks()
{
$this->hooks->add_filter('test', array($this, 'hookTestString_1'));
$this->hooks->add_filter('test', array($this, 'hookTestString_2'));
$this->hooks->add_filter('test', [$this, 'hookTestString_1']);
$this->hooks->add_filter('test', [$this, 'hookTestString_2']);

$lall = $this->hooks->apply_filters('test', '');

Expand Down Expand Up @@ -161,33 +161,34 @@ public function testRunHookFunctions()
self::assertSame(true, $hooks->remove_all_actions('testAction'));

self::assertSame(false, $hooks->do_action('testAction'));
self::assertSame(false, $hooks->do_action_ref_array('testNotExistingAction', array()));
self::assertSame(false, $hooks->do_action_ref_array('testNotExistingAction', []));
self::assertSame('Foo', $hooks->apply_filters('testFilter', 'Foo'));

self::assertSame(false, $hooks->do_action_ref_array('testAction', array('test')));
self::assertSame('Foo', $hooks->apply_filters_ref_array('testFilter', array('Foo')));
self::assertSame(false, $hooks->do_action_ref_array('testAction', ['test']));
self::assertSame('Foo', $hooks->apply_filters_ref_array('testFilter', ['Foo']));

$mock = $this->getMockBuilder('stdClass')->setMethods( array('doSomeAction', 'applySomeFilter'))->getMock();$mock->expects(self::exactly(4))->method('doSomeAction');
$mock = $this->getMockBuilder('stdClass')->setMethods(['doSomeAction', 'applySomeFilter'])->getMock();
$mock->expects(self::exactly(4))->method('doSomeAction');
$mock->expects(self::exactly(10))->method('applySomeFilter')->willReturn('foo');

self::assertSame(true, $hooks->add_action('testAction', array($mock, 'doSomeAction')));
self::assertSame(true, $hooks->add_filter('testFilter', array($mock, 'applySomeFilter')));
self::assertSame(true, $hooks->add_action('testAction', [$mock, 'doSomeAction']));
self::assertSame(true, $hooks->add_filter('testFilter', [$mock, 'applySomeFilter']));

self::assertSame(8, $hooks->did_action('testAction'));
self::assertSame(true, $hooks->do_action('testAction'));
self::assertSame(9, $hooks->did_action('testAction'));
self::assertSame('foo', $hooks->apply_filters('testFilter', 'Foo'));

self::assertSame(true, $hooks->add_filter('all', array($mock, 'applySomeFilter')));
self::assertSame(true, $hooks->add_filter('all', [$mock, 'applySomeFilter']));

self::assertSame(false, $hooks->do_action('notExistingAction'));
self::assertSame('Foo', $hooks->apply_filters('notExistingFilter', 'Foo')); // unmodified value

self::assertSame(true, $hooks->do_action('testAction', (object)array('foo' => 'bar')));
self::assertSame(true, $hooks->do_action('testAction', (object)['foo' => 'bar']));
self::assertSame(true, $hooks->do_action('testAction', 'param1', 'param2', 'param3', 'param4'));
self::assertSame(true, $hooks->do_action_ref_array('testAction', array('test')));
self::assertSame(true, $hooks->do_action_ref_array('testAction', ['test']));
self::assertSame('foo', $hooks->apply_filters('testFilter', 'Foo'));
self::assertSame('foo', $hooks->apply_filters_ref_array('testFilter', array('Foo')));
self::assertSame('foo', $hooks->apply_filters_ref_array('testFilter', ['Foo']));
}

public function testRunShortcodeFunctions()
Expand All @@ -201,7 +202,7 @@ public function testRunShortcodeFunctions()
self::assertSame('testAction', $hooks->do_shortcode('testAction'));

$testClass = new HooksFooBar();
self::assertSame(true, $hooks->add_shortcode('testAction', array($testClass, 'doSomethingFunction')));
self::assertSame(true, $hooks->add_shortcode('testAction', [$testClass, 'doSomethingFunction']));
self::assertTrue($hooks->shortcode_exists('testAction'));

self::assertSame('foo bar <li class="">content</li>', $hooks->do_shortcode('foo bar [testAction foo="bar"]content[/testAction]'));
Expand Down

0 comments on commit 80ba5dd

Please sign in to comment.