Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PHPUnit 8.0 #942

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ phpunit.xml
.php_cs.cache
docs/api
phpDocumentor.phar*
.phpunit.result.cache
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"hamcrest/hamcrest-php": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7.10|~6.5|~7.0"
"phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0"
},
"autoload": {
"psr-0": {
Expand Down
10 changes: 9 additions & 1 deletion library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,27 @@

use Mockery;

if (class_exists('PHPUnit_Framework_TestCase') || version_compare(\PHPUnit\Runner\Version::id(), '8.0.0', '<')) {
class_alias(MockeryPHPUnitIntegrationAssertPostConditionsForV7AndPrevious::class, MockeryPHPUnitIntegrationAssertPostConditions::class);
} else {
class_alias(MockeryPHPUnitIntegrationAssertPostConditionsForV8::class, MockeryPHPUnitIntegrationAssertPostConditions::class);
}

/**
* Integrates Mockery into PHPUnit. Ensures Mockery expectations are verified
* for each test and are included by the assertion counter.
*/
trait MockeryPHPUnitIntegration
{
use MockeryPHPUnitIntegrationAssertPostConditions;

protected $mockeryOpen;

/**
* Performs assertions shared by all tests of a test case. This method is
* called before execution of a test ends and before the tearDown method.
*/
protected function assertPostConditions()
protected function mockeryAssertPostConditions()
{
$this->addMockeryExpectationsToAssertionCount();
$this->checkMockeryExceptions();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Mockery
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://github.com/padraic/mockery/blob/master/LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to padraic@php.net so we can send you a copy immediately.
*
* @category Mockery
* @package Mockery
* @copyright Copyright (c) 2019 Enalean
* @license https://github.com/mockery/mockery/blob/master/LICENSE New BSD License
*/

declare(strict_types=1);

namespace Mockery\Adapter\Phpunit;

trait MockeryPHPUnitIntegrationAssertPostConditionsForV7AndPrevious
{
protected function assertPostConditions()
{
$this->mockeryAssertPostConditions();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Mockery
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://github.com/padraic/mockery/blob/master/LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to padraic@php.net so we can send you a copy immediately.
*
* @category Mockery
* @package Mockery
* @copyright Copyright (c) 2019 Enalean
* @license https://github.com/mockery/mockery/blob/master/LICENSE New BSD License
*/

declare(strict_types=1);

namespace Mockery\Adapter\Phpunit;

trait MockeryPHPUnitIntegrationAssertPostConditionsForV8
{
protected function assertPostConditions() : void
{
$this->mockeryAssertPostConditions();
}
}
15 changes: 14 additions & 1 deletion library/Mockery/Adapter/Phpunit/MockeryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@

namespace Mockery\Adapter\Phpunit;

if (class_exists('PHPUnit_Framework_TestCase') || version_compare(\PHPUnit\Runner\Version::id(), '8.0.0', '<')) {
class_alias(MockeryTestCaseSetUpForV7AndPrevious::class, MockeryTestCaseSetUp::class);
} else {
class_alias(MockeryTestCaseSetUpForV8::class, MockeryTestCaseSetUp::class);
}
abstract class MockeryTestCase extends \PHPUnit\Framework\TestCase
{
use MockeryPHPUnitIntegration;
use MockeryPHPUnitIntegration, MockeryTestCaseSetUp;

protected function mockeryTestSetUp()
{
}

protected function mockeryTestTearDown()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Mockery
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://github.com/padraic/mockery/blob/master/LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to padraic@php.net so we can send you a copy immediately.
*
* @category Mockery
* @package Mockery
* @copyright Copyright (c) 2019 Enalean
* @license https://github.com/mockery/mockery/blob/master/LICENSE New BSD License
*/

namespace Mockery\Adapter\Phpunit;

trait MockeryTestCaseSetUpForV7AndPrevious
{
protected function setUp()
{
parent::setUp();
$this->mockeryTestSetUp();
}

protected function tearDown()
{
$this->mockeryTestTearDown();
parent::tearDown();
}
}
38 changes: 38 additions & 0 deletions library/Mockery/Adapter/Phpunit/MockeryTestCaseSetUpForV8.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Mockery
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://github.com/padraic/mockery/blob/master/LICENSE
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to padraic@php.net so we can send you a copy immediately.
*
* @category Mockery
* @package Mockery
* @copyright Copyright (c) 2019 Enalean
* @license https://github.com/mockery/mockery/blob/master/LICENSE New BSD License
*/

declare(strict_types=1);

namespace Mockery\Adapter\Phpunit;

trait MockeryTestCaseSetUpForV8
{
protected function setUp() : void
{
parent::setUp();
$this->mockeryTestSetUp();
}

protected function tearDown() : void
{
$this->mockeryTestTearDown();
parent::tearDown();
}
}
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<exclude>
<directory>./library/Mockery/Adapter/Phpunit/Legacy</directory>
<file>./library/Mockery/Adapter/Phpunit/TestListener.php</file>
<file>./library/Mockery/Adapter/Phpunit/MockeryPHPUnitIntegrationAssertPostConditionsForV8.php</file>
<file>./library/Mockery/Adapter/Phpunit/MockeryTestCaseSetUpForV8.php</file>
</exclude>
</whitelist>
</filter>
Expand Down
6 changes: 3 additions & 3 deletions tests/Mockery/Adapter/Phpunit/TestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace tests\Mockery\Adapter\Phpunit;

use PHPUnit\Framework\TestCase;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use PHPUnit\Framework\TestResult;
use Mockery\Adapter\Phpunit\TestListener;

Expand All @@ -33,9 +33,9 @@ class_alias('test\Mockery\Fixtures\EmptyTestCaseV6', 'tests\Mockery\Adapter\Phpu
class_alias('test\Mockery\Fixtures\EmptyTestCaseV7', 'tests\Mockery\Adapter\Phpunit\EmptyTestCase');
}

class TestListenerTest extends TestCase
class TestListenerTest extends MockeryTestCase
{
protected function setUp()
protected function mockeryTestSetUp()
{
/**
* Skip all tests here if PHPUnit is less than 6.0.0
Expand Down
4 changes: 2 additions & 2 deletions tests/Mockery/AdhocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
*/
class Mockery_AdhocTest extends MockeryTestCase
{
public function setup()
public function mockeryTestSetUp()
{
$this->container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader());
}

public function teardown()
public function mockeryTestTearDown()
{
$this->container->mockery_close();
}
Expand Down