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

Mock classes with new in initializers on PHP 8.1 #1160

Merged
merged 6 commits into from Jan 14, 2022
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
79 changes: 6 additions & 73 deletions .github/workflows/tests.yml
Expand Up @@ -5,19 +5,19 @@ on:
pull_request:

jobs:
php7:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-20.04
phpunit:
name: PHPUnit on PHP ${{ matrix.php }}
runs-on: ubuntu-latest

strategy:
matrix:
php: ['7.3', '7.4']
php: ['7.4', '8.0', '8.1']

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup PHP
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
Expand All @@ -36,71 +36,4 @@ jobs:
command: composer update --no-interaction --no-progress

- name: Execute PHPUnit
run: vendor/bin/phpunit --coverage-text --testsuite="Mockery Test Suite PHP7"

php80:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-20.04

strategy:
matrix:
php: ['8.0']

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: xdebug

- name: Setup Problem Matchers
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install Dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --no-interaction --no-progress

- name: Execute PHPUnit
run: vendor/bin/phpunit --coverage-text --testsuite="Mockery Test Suite PHP8"

php81:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-20.04

strategy:
matrix:
php: ['8.1']

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

- name: Setup Problem Matchers
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Mimic PHP 8.0
run: composer config platform.php 8.0.999

- name: Install Dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --no-interaction --no-progress

- name: Execute PHPUnit
run: vendor/bin/phpunit --testsuite="Mockery Test Suite PHP8"
run: vendor/bin/phpunit
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,25 +5,30 @@
* Override default call count expectations via expects() #1146
* Mock methods with static return types #1157
* Mock methods with mixed return type #1156
* Mock classes with new in initializers on PHP 8.1 #1160

## 1.4.4 (2021-09-13)

* Fixes auto-generated return values #1144
* Adds support for tentative types #1130
* Fixes for PHP 8.1 Support (#1130 and #1140)
* Add method that allows defining a set of arguments the mock should yield #1133
* Added option to configure default matchers for objects `\Mockery::getConfiguration()->setDefaultMatcher($class, $matcherClass)` #1120

## 1.4.3 (2021-02-24)

* Fixes calls to fetchMock before initialisation #1113
* Allow shouldIgnoreMissing() to behave in a recursive fashion #1097
* Custom object formatters #766 (Needs Docs)
* Fix crash on a union type including null #1106

## 1.3.4 (2021-02-24)

* Fixes calls to fetchMock before initialisation #1113
* Fix crash on a union type including null #1106

## 1.4.2 (2020-08-11)

* Fix array to string conversion in ConstantsPass (#1086)
* Fixed nullable PHP 8.0 union types (#1088, #1089)
* Fixed support for PHP 8.0 parent type (#1088, #1089)
Expand All @@ -38,13 +43,15 @@
* Fix mocking methods with iterable return type without specifying a return value (#1075)

## 1.3.3 (2020-08-11)

* Fix array to string conversion in ConstantsPass (#1086)
* Fixed nullable PHP 8.0 union types (#1088)
* Fixed support for PHP 8.0 parent type (#1088)
* Fixed PHP 8.0 mixed type support (#1088)
* Fixed PHP 8.0 union return types (#1088)

## 1.3.2 (2020-07-09)

* Fix mocking with anonymous classes (#1039)
* Fix andAnyOthers() to properly match earlier expectations (#1051)
* Added provisional support for PHP 8.0 (#1068, #1072,#1079)
Expand All @@ -57,6 +64,7 @@
* Drops support for PHP < 7.3 and PHPUnit < 8 (#1059)

## 1.3.1 (2019-12-26)

* Revert improved exception debugging due to BC breaks (#1032)

## 1.3.0 (2019-11-24)
Expand Down
Expand Up @@ -75,7 +75,8 @@ protected function renderParams(Method $method, $config)

if (!$param->isVariadic()) {
if (false !== $param->isDefaultValueAvailable()) {
$paramDef .= ' = ' . var_export($param->getDefaultValue(), true);
$defaultValue = $param->getDefaultValue();
$paramDef .= ' = ' . (is_object($defaultValue) ? get_class($defaultValue) : var_export($defaultValue, true));
} elseif ($param->isOptional()) {
$paramDef .= ' = null';
}
Expand Down
16 changes: 9 additions & 7 deletions phpunit.xml.dist
Expand Up @@ -4,17 +4,20 @@
verbose="true"
>
<testsuites>
<testsuite name="Mockery Test Suite PHP8">
<directory suffix="Test.php">./tests</directory>
<directory phpVersion="8.0.0-dev" phpVersionOperator=">=">./tests/PHP80</directory>
<directory phpVersion="8.1.0-dev" phpVersionOperator=">=">./tests/PHP81</directory>
</testsuite>

<testsuite name="Mockery Test Suite PHP7">
<directory suffix="Test.php">./tests</directory>
<exclude>./tests/PHP80</exclude>
<exclude>./tests/PHP81</exclude>
</testsuite>

<testsuite name="Mockery Test Suite PHP80">
<directory phpVersion="8.0.0-dev" phpVersionOperator=">=">./tests</directory>
<exclude>./tests/PHP81</exclude>
</testsuite>

<testsuite name="Mockery Test Suite PHP81">
<directory phpVersion="8.1.0-dev" phpVersionOperator=">=">./tests</directory>
</testsuite>
</testsuites>

<filter>
Expand All @@ -28,5 +31,4 @@
</exclude>
</whitelist>
</filter>

</phpunit>
32 changes: 28 additions & 4 deletions tests/PHP81/Php81LanguageFeaturesTest.php
Expand Up @@ -3,10 +3,10 @@
namespace test\Mockery;

use DateTime;
use Serializable;
use Mockery as m;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use ReturnTypeWillChange;
use Serializable;

/**
* @requires PHP 8.1.0-dev
Expand Down Expand Up @@ -36,7 +36,7 @@ public function it_can_mock_an_internal_class_with_tentative_return_types()
*/
public function it_can_mock_an_internal_class_with_tentative_union_return_types()
{
$mock = m::mock('PDO');
$mock = Mockery::mock('PDO');

$this->assertInstanceOf('PDO', $mock);

Expand All @@ -45,7 +45,7 @@ public function it_can_mock_an_internal_class_with_tentative_union_return_types(
try {
$this->assertSame(0, $mock->exec('select * from foo.bar'));
} finally {
m::close();
Mockery::close();
}
}

Expand All @@ -64,6 +64,30 @@ public function it_can_mock_a_class_with_return_type_will_change_attribute_and_w

$this->assertSame(0.0, $mock->getTimestamp());
}

/** @test */
public function testMockingClassWithNewInInitializer()
{
$mock = Mockery::mock(ClassWithNewInInitializer::class);

$this->assertInstanceOf(ClassWithNewInInitializer::class, $mock);
}
}

interface LoggerInterface
{
}

class NullLogger implements LoggerInterface
{
}

class ClassWithNewInInitializer
{
public function __construct(
private Logger $logger = new NullLogger(),
) {
}
}

class ClassThatImplementsSerializable implements Serializable
Expand Down