Skip to content

Commit 2f52f1b

Browse files
committed
use Closure instead of callback and drop call_user_func
- per @mvorisek
1 parent 8b2f19e commit 2f52f1b

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

classes/MockDisablerPHPUnit10.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace phpmock\phpunit;
44

5+
use Closure;
56
use phpmock\Deactivatable;
67
use PHPUnit\Event\Test\Finished;
78
use PHPUnit\Event\Test\FinishedSubscriber;
@@ -24,17 +25,17 @@ class MockDisablerPHPUnit10 implements FinishedSubscriber
2425
private $deactivatable;
2526

2627
/**
27-
* @var callable|null The callback to execute after the test.
28+
* @var Closure|null The callback to execute after the test.
2829
*/
2930
private $callback;
3031

3132
/**
3233
* Sets the function mocks.
3334
*
3435
* @param Deactivatable $deactivatable The function mocks.
35-
* @param callback|null $callback The callback to execute after the test.
36+
* @param Closure|null $callback The callback to execute after the test.
3637
*/
37-
public function __construct(Deactivatable $deactivatable, ?callable $callback = null)
38+
public function __construct(Deactivatable $deactivatable, ?Closure $callback = null)
3839
{
3940
$this->deactivatable = $deactivatable;
4041
$this->callback = $callback;
@@ -47,15 +48,15 @@ public function notify(Finished $event) : void
4748
{
4849
$this->deactivatable->disable();
4950
if ($this->callback !== null) {
50-
call_user_func($this->callback, $this);
51+
($this->callback)($this);
5152
}
5253
}
5354

5455
public function endTest(): void
5556
{
5657
$this->deactivatable->disable();
5758
if ($this->callback !== null) {
58-
call_user_func($this->callback, $this);
59+
($this->callback)($this);
5960
}
6061
}
6162
}

classes/MockDisablerPHPUnit6.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace phpmock\phpunit;
44

5+
use Closure;
56
use phpmock\Deactivatable;
67
use PHPUnit\Framework\BaseTestListener;
78
use PHPUnit\Framework\Test;
@@ -24,17 +25,17 @@ class MockDisablerPHPUnit6 extends BaseTestListener
2425
private $deactivatable;
2526

2627
/**
27-
* @var callable|null The callback to execute after the test.
28+
* @var Closure|null The callback to execute after the test.
2829
*/
2930
private $callback;
3031

3132
/**
3233
* Sets the function mocks.
3334
*
3435
* @param Deactivatable $deactivatable The function mocks.
35-
* @param callable|null $callback The callback to execute after the test.
36+
* @param Closure|null $callback The callback to execute after the test.
3637
*/
37-
public function __construct(Deactivatable $deactivatable, callable $callback = null)
38+
public function __construct(Deactivatable $deactivatable, Closure $callback = null)
3839
{
3940
$this->deactivatable = $deactivatable;
4041
$this->callback = $callback;
@@ -54,7 +55,7 @@ public function endTest(Test $test, $time)
5455

5556
$this->deactivatable->disable();
5657
if ($this->callback !== null) {
57-
call_user_func($this->callback, $this);
58+
($this->callback)($this);
5859
}
5960
}
6061
}

classes/MockDisablerPHPUnit7.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace phpmock\phpunit;
44

5+
use Closure;
56
use phpmock\Deactivatable;
67
use PHPUnit\Framework\BaseTestListener;
78
use PHPUnit\Framework\Test;
@@ -24,17 +25,17 @@ class MockDisablerPHPUnit7 extends BaseTestListener
2425
private $deactivatable;
2526

2627
/**
27-
* @var callable|null The callback to execute after the test.
28+
* @var Closure|null The callback to execute after the test.
2829
*/
2930
private $callback;
3031

3132
/**
3233
* Sets the function mocks.
3334
*
3435
* @param Deactivatable $deactivatable The function mocks.
35-
* @param callable|null $callback The callback to execute after the test.
36+
* @param Closure|null $callback The callback to execute after the test.
3637
*/
37-
public function __construct(Deactivatable $deactivatable, $callback = null)
38+
public function __construct(Deactivatable $deactivatable, Closure $callback = null)
3839
{
3940
$this->deactivatable = $deactivatable;
4041
$this->callback = $callback;
@@ -54,7 +55,7 @@ public function endTest(Test $test, float $time) : void
5455

5556
$this->deactivatable->disable();
5657
if ($this->callback !== null) {
57-
call_user_func($this->callback, $this);
58+
($this->callback)($this);
5859
}
5960
}
6061
}

0 commit comments

Comments
 (0)