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

[1.4] Fixed bad merge #1089

Merged
merged 4 commits into from Aug 11, 2020
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
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