Skip to content

Commit

Permalink
Merge pull request #1089 from GrahamCampbell/patch-1
Browse files Browse the repository at this point in the history
[1.4] Fixed bad merge
  • Loading branch information
davedevelopment committed Aug 11, 2020
2 parents 81d6dc3 + c1b3906 commit 12172ac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 84 deletions.
13 changes: 11 additions & 2 deletions .travis.yml
Expand Up @@ -24,14 +24,23 @@ matrix:
- COMPOSER_FLAGS="--ignore-platform-reqs"

before_install:
- composer self-update --2
- |
composer self-update --2
if [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
composer require --dev --no-update "phpunit/phpunit:^9.3.2"
fi
install:
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update --no-interaction $COMPOSER_FLAGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable --no-interaction $COMPOSER_FLAGS ; fi

script:
- ./vendor/bin/phpunit --coverage-text --coverage-clover="build/logs/clover.xml" --testsuite="Mockery Test Suite";
- |
if [[ $TRAVIS_PHP_VERSION == 'nightly' ]]; then
./vendor/bin/phpunit --coverage-text --coverage-clover="build/logs/clover.xml" --testsuite="Mockery Test Suite PHP8";
else
./vendor/bin/phpunit --coverage-text --coverage-clover="build/logs/clover.xml" --testsuite="Mockery Test Suite PHP7";
fi
after_success:
- composer require satooshi/php-coveralls
Expand Down
82 changes: 0 additions & 82 deletions library/Mockery/Reflector.php
Expand Up @@ -82,88 +82,6 @@ public static function getReturnType(\ReflectionMethod $method, $withoutNullable
return (!$withoutNullable && $type->allowsNull()) ? self::formatNullableType($typeHint) : $typeHint;
}

/**
* Compute the legacy type hint.
*
* We return:
* - string: the legacy type hint
* - null: if there is no legacy type hint
* - false: if we must check for PHP 7+ typing
*
* @param \ReflectionParameter $param
*
* @return string|null|false
*/
private static function getLegacyTypeHint(\ReflectionParameter $param)
{
// Handle HHVM typing
if (\method_exists($param, 'getTypehintText')) {
if ($param->isArray()) {
return 'array';
}

if ($param->isCallable()) {
return 'callable';
}

$typeHint = $param->getTypehintText();

// throw away HHVM scalar types
if (\in_array($typeHint, array('int', 'integer', 'float', 'string', 'bool', 'boolean'), true)) {
return null;
}

return sprintf('\\%s', $typeHint);
}

// Handle PHP 5 typing
if (\PHP_VERSION_ID < 70000) {
if ($param->isArray()) {
return 'array';
}

if ($param->isCallable()) {
return 'callable';
}

$typeHint = self::getLegacyClassName($param);

return $typeHint === null ? null : sprintf('\\%s', $typeHint);
}

return false;
}

/**
* Compute the class name using legacy APIs, if possible.
*
* This method MUST only be called on PHP 5.
*
* @param \ReflectionParameter $param
*
* @return string|null
*/
private static function getLegacyClassName(\ReflectionParameter $param)
{
try {
$class = $param->getClass();

$typeHint = $class === null ? null : $class->getName();
} catch (\ReflectionException $e) {
$typeHint = null;
}

if ($typeHint === null) {
if (preg_match('/^Parameter #[0-9]+ \[ \<(required|optional)\> (?<typehint>\S+ )?.*\$' . $param->getName() . ' .*\]$/', (string) $param, $typehintMatch)) {
if (!empty($typehintMatch['typehint']) && $typehintMatch['typehint']) {
$typeHint = $typehintMatch['typehint'];
}
}
}

return $typeHint;
}

/**
* Get the string representation of the given type.
*
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -11,6 +11,7 @@

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

Expand Down

0 comments on commit 12172ac

Please sign in to comment.