Skip to content

Commit

Permalink
Add return type to setup() and teardown()
Browse files Browse the repository at this point in the history
  • Loading branch information
cj-watts committed Feb 13, 2019
1 parent 9f3525a commit dcdab67
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:30:"PHPUnit\Runner\TestResultCache":2867:{a:2:{s:7:"defects";a:6:{s:58:"DeprecatedMethodsTest::testWpFunctionLogsDeprecationNotice";i:5;s:66:"DeprecatedMethodsTest::testWpPassthruFunctionLogsDeprecationNotice";i:5;s:47:"FunctionMocksTest::testDefaultFailsInStrictMode";i:6;s:53:"WP_Mock\DeprecatedListenerTest::testCheckCallsNoCalls";i:5;s:58:"WP_Mock\DeprecatedListenerTest::testCheckCalls_scalar_only";i:4;s:58:"WP_Mock\DeprecatedListenerTest::testCheckCalls_non_scalars";i:4;}s:5:"times";a:31:{s:58:"DeprecatedMethodsTest::testWpFunctionLogsDeprecationNotice";d:0.035;s:66:"DeprecatedMethodsTest::testWpPassthruFunctionLogsDeprecationNotice";d:0;s:48:"FunctionMocksTest::testCommonFunctionsAreDefined";d:0.003;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #0";d:0;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #1";d:0;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #2";d:0;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #3";d:0;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #4";d:0;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #5";d:0;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #6";d:0;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #7";d:0;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #8";d:0;s:75:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #9";d:0;s:76:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #10";d:0;s:76:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #11";d:0;s:76:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #12";d:0;s:76:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #13";d:0;s:76:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #14";d:0;s:76:"FunctionMocksTest::testCommonFunctionsDefaultFunctionality with data set #15";d:0;s:47:"FunctionMocksTest::testDefaultFailsInStrictMode";d:0.003;s:47:"FunctionMocksTest::testMockingOverridesDefaults";d:0;s:55:"FunctionMocksTest::testBotchedMocksStillOverrideDefault";d:0;s:53:"WP_Mock\DeprecatedListenerTest::testLogDeprecatedCall";d:0;s:41:"WP_Mock\DeprecatedListenerTest::testReset";d:0;s:53:"WP_Mock\DeprecatedListenerTest::testCheckCallsNoCalls";d:0;s:58:"WP_Mock\DeprecatedListenerTest::testCheckCalls_scalar_only";d:0.002;s:58:"WP_Mock\DeprecatedListenerTest::testCheckCalls_non_scalars";d:0.005;s:43:"WP_MockTest::test_strictMode_off_by_default";d:0.002;s:57:"WP_MockTest::test_activateStrictMode_turns_strict_mode_on";d:0.003;s:66:"WP_MockTest::test_activateStrictMode_does_not_work_after_bootstrap";d:0.002;s:50:"WP_MockTest::test_userFunction_returns_expectation";d:0;}}}
4 changes: 2 additions & 2 deletions php/WP_Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function bootstrap() {
/**
* Make sure Mockery doesn't have anything set up already.
*/
public static function setUp() {
public static function setUp():void {
if ( self::$__bootstrapped ) {
\Mockery::close();

Expand All @@ -128,7 +128,7 @@ public static function setUp() {
/**
* Tear down anything built up inside Mockery when we're ready to do so.
*/
public static function tearDown() {
public static function tearDown():void {
self::$event_manager->flush();
self::$function_manager->flush();

Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
colors="true"
verbose="true">
<testsuites>
<testsuite>
<testsuite name="All Tests">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
Expand Down
10 changes: 6 additions & 4 deletions tests/DeprecatedMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

class DeprecatedMethodsTest extends \PHPUnit\Framework\TestCase {

public function setUp() {
public function setUp():void {
WP_Mock::setUp();
WP_Mock::getDeprecatedListener()->reset();
}

protected function tearDown() {
protected function tearDown():void {
WP_Mock::getDeprecatedListener()->reset();
WP_Mock::tearDown();
}

public function testWpFunctionLogsDeprecationNotice() {
$listener = WP_Mock::getDeprecatedListener();
$result = Mockery::mock( '\PHPUnit\Framework\TestResult' );
$testResult = new \PHPUnit\Framework\TestResult();
$result = Mockery::mock( $testResult );
$case = Mockery::mock( '\PHPUnit\Framework\TestCase' );
$listener->setTestCase( $case );
$listener->setTestResult( $result );
Expand All @@ -27,7 +28,8 @@ public function testWpFunctionLogsDeprecationNotice() {

public function testWpPassthruFunctionLogsDeprecationNotice() {
$listener = WP_Mock::getDeprecatedListener();
$result = Mockery::mock( '\PHPUnit\Framework\TestResult' );
$testResult = new \PHPUnit\Framework\TestResult();
$result = Mockery::mock( $testResult );
$case = Mockery::mock( '\PHPUnit\Framework\TestCase' );
$listener->setTestCase( $case );
$listener->setTestResult( $result );
Expand Down
8 changes: 4 additions & 4 deletions tests/FunctionMocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FunctionMocksTest extends \PHPUnit\Framework\TestCase {
'_n',
);

protected function setUp() {
protected function setUp(): void {
if ( ! $this->isInIsolation() ) {
WP_Mock::setUp();
}
Expand Down Expand Up @@ -56,11 +56,11 @@ public function testCommonFunctionsDefaultFunctionality( $function, $action ) {
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
* @expectedException \PHPUnit\Framework\ExpectationFailedException
* @expectedExceptionMessageRegExp /No handler found for \w+/
*/
public function testDefaultFailsInStrictMode() {
WP_Mock::activateStrictMode();
$this->expectExceptionMessageRegExp('/No handler found for \w+/');
$this->expectException('\PHPUnit\Framework\ExpectationFailedException');
WP_Mock::activateStrictMode();
WP_Mock::bootstrap();
_e('Test');
}
Expand Down
13 changes: 8 additions & 5 deletions tests/WP_Mock/DeprecatedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class DeprecatedListenerTest extends \PHPUnit\Framework\TestCase {
/** @var DeprecatedListener */
protected $object;

protected function setUp() {
protected function setUp(): void {
$this->object = new DeprecatedListener();
}

public function tearDown() {
public function tearDown(): void {
$this->object->reset();
}

Expand All @@ -37,7 +37,8 @@ public function testReset() {
}

public function testCheckCallsNoCalls() {
$result = Mockery::mock( '\PHPUnit\Framework\TestResult' );
$testResult = new \PHPUnit\Framework\TestResult();
$result = Mockery::mock( $testResult );
$result->shouldReceive( 'addFailure' )->never();
/** @var \\PHPUnit\Framework\TestResult $result */
$this->object->setTestResult( $result );
Expand All @@ -51,7 +52,8 @@ public function testCheckCalls_scalar_only() {
$testCase = Mockery::mock( '\PHPUnit\Framework\TestCase' );
/** @var \PHPUnit\Framework\TestCase $testCase */
$this->object->setTestCase( $testCase );
$result = Mockery::mock( '\PHPUnit\Framework\TestResult' );
$testResult = new \PHPUnit\Framework\TestResult();
$result = Mockery::mock( $testResult );
$result->shouldReceive( 'addFailure' )
->once()
->andReturnUsing( function ( $case, $exception, $int ) use ( $testCase ) {
Expand Down Expand Up @@ -85,7 +87,8 @@ public function testCheckCalls_non_scalars() {
$testCase = Mockery::mock( '\PHPUnit\Framework\TestCase' );
/** @var \PHPUnit\Framework\TestCase $testCase */
$this->object->setTestCase( $testCase );
$result = Mockery::mock( '\PHPUnit\Framework\TestResult' );
$testResult = new \PHPUnit\Framework\TestResult();
$result = Mockery::mock( $testResult );;
$testClosure = function ( $case, $exception, $int ) use ( $testCase, $callback1, $object1, $range ) {
$int = (int) $int; // It's coming as 0.0
$callback1 = get_class( $callback1 ) . ':' . spl_object_hash( $callback1 );
Expand Down

0 comments on commit dcdab67

Please sign in to comment.