Skip to content

Commit

Permalink
Merge pull request #1141 from GrahamCampbell/merge-13
Browse files Browse the repository at this point in the history
[1.4] Merge 1.3 -> 1.4
  • Loading branch information
davedevelopment committed Sep 1, 2021
2 parents 5383370 + 41fca59 commit f240683
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 86 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
* text=auto

/.github export-ignore
/docker export-ignore
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs export-ignore
.scrutinizer.yml export-ignore
.styleci.yml export-ignore
.travis.yml export-ignore
Makefile export-ignore
phpunit.xml.dist export-ignore
106 changes: 106 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Tests

on:
push:
pull_request:

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

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

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
extensions: mongodb, redis
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 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"
50 changes: 0 additions & 50 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Mockery
=======

[![Build Status](https://travis-ci.org/mockery/mockery.svg?branch=master)](https://travis-ci.org/mockery/mockery)
[![Build Status](https://github.com/mockery/mockery/workflows/tests/badge.svg)](https://github.com/mockery/mockery/actions)
[![Latest Stable Version](https://poser.pugx.org/mockery/mockery/v/stable.svg)](https://packagist.org/packages/mockery/mockery)
[![Coverage Status](https://coveralls.io/repos/github/mockery/mockery/badge.svg)](https://coveralls.io/github/mockery/mockery)
[![Total Downloads](https://poser.pugx.org/mockery/mockery/downloads.svg)](https://packagist.org/packages/mockery/mockery)

Mockery is a simple yet flexible PHP mock object framework for use in unit testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
*/
class RemoveUnserializeForInternalSerializableClassesPass
{
const DUMMY_METHOD_DEFINITION = 'public function unserialize($string) {} ';
const DUMMY_METHOD_DEFINITION_LEGACY = 'public function unserialize($string) {} ';
const DUMMY_METHOD_DEFINITION = 'public function unserialize(string $data): void {} ';

public function apply($code, MockConfiguration $config)
{
Expand All @@ -44,7 +45,7 @@ public function apply($code, MockConfiguration $config)
return $code;
}

$code = $this->appendToClass($code, self::DUMMY_METHOD_DEFINITION);
$code = $this->appendToClass($code, \PHP_VERSION_ID < 80100 ? self::DUMMY_METHOD_DEFINITION_LEGACY : self::DUMMY_METHOD_DEFINITION);

return $code;
}
Expand Down
2 changes: 1 addition & 1 deletion library/Mockery/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ protected static function _mockery_handleStaticMethodCall($method, array $args)
throw new BadMethodCallException(
'Static method ' . $associatedRealObject->mockery_getName() . '::' . $method
. '() does not exist on this mock object',
null,
0,
$e
);
}
Expand Down
9 changes: 7 additions & 2 deletions library/Mockery/Reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ public static function getTypeHint(\ReflectionParameter $param, $withoutNullable
*/
public static function getReturnType(\ReflectionMethod $method, $withoutNullable = false)
{
if (!$method->hasReturnType()) {
$type = $method->getReturnType();

if (is_null($type) && method_exists($method, 'getTentativeReturnType')) {
$type = $method->getTentativeReturnType();
}

if (is_null($type)) {
return null;
}

$type = $method->getReturnType();
$declaringClass = $method->getDeclaringClass();
$typeHint = self::typeToString($type, $declaringClass);

Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
<testsuites>
<testsuite name="Mockery Test Suite PHP8">
<directory suffix="Test.php">./tests</directory>
<directory phpVersion="8.0.0" phpVersionOperator=">=">./tests/PHP80</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>
</testsuites>

Expand Down
63 changes: 37 additions & 26 deletions tests/Mockery/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,9 @@ public function testInterfacesCanHaveAssertions()
$m->foo();
}

/**
* @requires PHP < 8.0
*/
public function testMockingIteratorAggregateDoesNotImplementIterator()
{
$mock = mock('MockeryTest_ImplementsIteratorAggregate');
Expand Down Expand Up @@ -1131,6 +1134,9 @@ public function testMockingIteratorDoesNotImplementIteratorAlongside()
$this->assertInstanceOf('Traversable', $mock);
}

/**
* @requires PHP < 8.0
*/
public function testMockingIteratorDoesNotImplementIterator()
{
$mock = mock('MockeryTest_ImplementsIterator');
Expand Down Expand Up @@ -1359,6 +1365,7 @@ public function canMockClassesThatDescendFromInternalClasses()
/**
* @test
* @group issue/339
* @requires PHP <8.1
*/
public function canMockClassesThatImplementSerializable()
{
Expand Down Expand Up @@ -1754,34 +1761,36 @@ public function __toString()
}
}

class MockeryTest_ImplementsIteratorAggregate implements IteratorAggregate
{
public function getIterator()
if (\PHP_VERSION_ID < 80000) {
class MockeryTest_ImplementsIteratorAggregate implements IteratorAggregate
{
return new ArrayIterator(array());
public function getIterator()
{
return new ArrayIterator(array());
}
}
}

class MockeryTest_ImplementsIterator implements Iterator
{
public function rewind()
class MockeryTest_ImplementsIterator implements Iterator
{
}
public function rewind()
{
}

public function current()
{
}
public function current()
{
}

public function key()
{
}
public function key()
{
}

public function next()
{
}
public function next()
{
}

public function valid()
{
public function valid()
{
}
}
}

Expand Down Expand Up @@ -1845,13 +1854,15 @@ class MockeryTest_ClassThatDescendsFromInternalClass extends DateTime
{
}

class MockeryTest_ClassThatImplementsSerializable implements Serializable
{
public function serialize()
if (PHP_VERSION_ID < 80100) {
class MockeryTest_ClassThatImplementsSerializable implements Serializable
{
}
public function serialize()
{
}

public function unserialize($serialized)
{
public function unserialize($serialized)
{
}
}
}

0 comments on commit f240683

Please sign in to comment.