Skip to content

Commit

Permalink
Fix 1.6.8 release (#1396)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Mar 18, 2024
2 parents bbc6d97 + f69ac21 commit c9cf52d
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Expand Up @@ -8,9 +8,10 @@
/docker export-ignore
/fixtures export-ignore
/tests export-ignore
Makefile export-ignore
codecov.yml export-ignore
e2e-test.sh export-ignore
ecs.php export-ignore
Makefile export-ignore
phpunit.xml.dist export-ignore
psalm-baseline.xml export-ignore
psalm.xml.dist export-ignore
79 changes: 79 additions & 0 deletions e2e-test.sh
@@ -0,0 +1,79 @@
#!/bin/bash

set -e
# set -x

#######################################################################################################################
# This script runs semi end-to-end tests for Mockery.
#
# It clones the repositories listed in the `projects` array,
# installs Mockery from the local filesystem,
# and runs PHPUnit for each PHP version listed in the `php_versions` array.
#
# This is useful to test Mockery against different versions of other projects and frameworks.
#
#######################################################################################################################

php_versions=(
"8.2"
"8.3"
)

projects=(
"Brain-WP/BrainMonkey"
"filp/whoops"
"laravel/framework"
)

mockery_path="$(pwd)"

resources_path="$mockery_path/../mockery-resources"

mockery_branch=$(git -C "$mockery_path" rev-parse --abbrev-ref HEAD)
mockery_sha=$(git -C "$mockery_path" rev-parse HEAD | cut -c1-8)
mockery_version="dev-$mockery_branch#$mockery_sha"

echo "===> Running e2e tests"
echo "PHP versions: [ ${php_versions[*]} ]"
echo "Test Projects: [ ${projects[*]} ]"
echo " "
echo "Mockery branch: $mockery_branch"
echo "Mockery SHA: $mockery_sha"
echo "Mockery version: $mockery_version"
echo "Mockery path: $mockery_path"
echo "Resource path: $resources_path"
echo " "


mkdir -p "$resources_path" || { echo "Failed to create directory $resources_path"; exit 1; }
cd "$resources_path" || { echo "Failed to change directory to $resources_path"; exit 1; }

for project in "${projects[@]}"
do
project_path="$resources_path/$project"

if [ ! -d "$project_path" ]; then
echo "Cloning $project to $project_path"

git clone "git@github.com:$project.git" "$project_path" --depth=10 || { echo "Failed to clone $project"; exit 1; }
else
echo "Pulling $project"

git -C "$project_path" fetch --depth=10 || { echo "Failed to fetch $project"; exit 1; }

git -C "$project_path" pull || { echo "Failed to pull $project"; exit 1; }
fi

cd "$project_path" || { echo "Failed to change directory to $project_path"; exit 1; }

echo "Installing Mockery version $mockery_version"

for php_version in "${php_versions[@]}"
do
echo "Running PHPUnit for PHP version $php_version"

docker run -it --rm -v "$mockery_path":/opt/mockery -v "$project_path":/opt/workspace -w /opt/workspace ghcr.io/ghostwriter/php:"$php_version"-pcov sh -c "composer config repositories.local '{\"type\": \"path\", \"url\": \"/opt/mockery\"}' && composer require 'mockery/mockery:$mockery_version' --with-dependencies --ignore-platform-reqs --no-scripts --no-plugins --dev --no-interaction && php vendor/bin/phpunit" || { echo "Failed to run PHPUnit for $project PHP version $php_version"; exit 1; }
done
done

rm -rf "$resources_path" || { echo "Failed to remove directory $resources_path"; exit 1; }
4 changes: 0 additions & 4 deletions library/Mockery/Exception/BadMethodCallException.php
Expand Up @@ -21,10 +21,6 @@ public function dismiss()
$this->dismissed = true;
// we sometimes stack them
$previous = $this->getPrevious();
if (! $previous instanceof Throwable) {
return;
}

if (! $previous instanceof self) {
return;
}
Expand Down
30 changes: 12 additions & 18 deletions library/Mockery/Expectation.php
Expand Up @@ -928,22 +928,6 @@ protected function _matchArg($expected, &$actual)
return true;
}

if (is_string($expected) && is_object($actual)) {
$result = $actual instanceof $expected;

if ($result) {
return true;
}
}

if (is_object($expected)) {
$matcher = Mockery::getConfiguration()->getDefaultMatcher(get_class($expected));

if ($matcher !== null) {
$expected = new $matcher($expected);
}
}

if ($expected instanceof MatcherInterface) {
return $expected->match($actual);
}
Expand All @@ -958,7 +942,17 @@ protected function _matchArg($expected, &$actual)
return $expected->matches($actual);
}

return false;
if (is_object($expected)) {
$matcher = Mockery::getConfiguration()->getDefaultMatcher(get_class($expected));

return $matcher === null ? false : $this->_matchArg(new $matcher($expected), $actual);
}

if (is_object($actual) && is_string($expected) && $actual instanceof $expected) {
return true;
}

return $expected == $actual;
}

/**
Expand All @@ -971,7 +965,7 @@ protected function _matchArg($expected, &$actual)
protected function _matchArgs($args)
{
for ($index = 0, $argCount = count($args); $index < $argCount; ++$index) {
$param =&$args[$index];
$param = &$args[$index];

if (! $this->_matchArg($this->_expectedArgs[$index], $param)) {
return false;
Expand Down
30 changes: 15 additions & 15 deletions library/Mockery/Mock.php
Expand Up @@ -202,7 +202,7 @@ public function mockery_init(Container $container = null, $partialObject = null,

$this->_mockery_instanceMock = $instanceMock;

$this->parentClass = get_parent_class($this);
$this->_mockery_parentClass = get_parent_class($this);
}

/**
Expand Down Expand Up @@ -644,15 +644,15 @@ public function __isset($name)
return false;
}

if (!$this->parentClass) {
if (!$this->_mockery_parentClass) {
return false;
}

if (!method_exists($this->parentClass, '__isset')) {
if (!method_exists($this->_mockery_parentClass, '__isset')) {
return false;
}

return call_user_func($this->parentClass . '::__isset', $name);
return call_user_func($this->_mockery_parentClass . '::__isset', $name);
}

public function mockery_getExpectations()
Expand All @@ -671,11 +671,11 @@ public function mockery_getExpectations()
*/
public function mockery_callSubjectMethod($name, array $args)
{
if (!method_exists($this, $name) && $this->parentClass && method_exists($this->parentClass, '__call')) {
return call_user_func($this->parentClass . '::__call', $name, $args);
if (!method_exists($this, $name) && $this->_mockery_parentClass && method_exists($this->_mockery_parentClass, '__call')) {
return call_user_func($this->_mockery_parentClass . '::__call', $name, $args);
}

return call_user_func_array($this->parentClass . '::' . $name, $args);
return call_user_func_array($this->_mockery_parentClass . '::' . $name, $args);
}

/**
Expand Down Expand Up @@ -910,7 +910,7 @@ protected function _mockery_handleMethodCall($method, array $args)
// noop - there is no hasPrototype method
}

return call_user_func_array($this->parentClass . '::' . $method, $args);
return call_user_func_array($this->_mockery_parentClass . '::' . $method, $args);
}

$handler = $this->_mockery_findExpectedMethodHandler($method);
Expand All @@ -930,13 +930,13 @@ protected function _mockery_handleMethodCall($method, array $args)
return $this->_mockery_partial->{$method}(...$args);
}

if ($this->_mockery_deferMissing && is_callable($this->parentClass . '::' . $method)
&& (!$this->hasMethodOverloadingInParentClass() || ($this->parentClass && method_exists($this->parentClass, $method)))) {
return call_user_func_array($this->parentClass . '::' . $method, $args);
if ($this->_mockery_deferMissing && is_callable($this->_mockery_parentClass . '::' . $method)
&& (!$this->hasMethodOverloadingInParentClass() || ($this->_mockery_parentClass && method_exists($this->_mockery_parentClass, $method)))) {
return call_user_func_array($this->_mockery_parentClass . '::' . $method, $args);
}

if ($this->_mockery_deferMissing && $this->parentClass && method_exists($this->parentClass, '__call')) {
return call_user_func($this->parentClass . '::__call', $method, $args);
if ($this->_mockery_deferMissing && $this->_mockery_parentClass && method_exists($this->_mockery_parentClass, '__call')) {
return call_user_func($this->_mockery_parentClass . '::__call', $method, $args);
}

if ($method === '__toString') {
Expand All @@ -946,7 +946,7 @@ protected function _mockery_handleMethodCall($method, array $args)
return sprintf('%s#%s', self::class, spl_object_hash($this));
}

if ($this->_mockery_ignoreMissing && (\Mockery::getConfiguration()->mockingNonExistentMethodsAllowed() || (!is_null($this->_mockery_partial) && method_exists($this->_mockery_partial, $method)) || is_callable($this->parentClass . '::' . $method))) {
if ($this->_mockery_ignoreMissing && (\Mockery::getConfiguration()->mockingNonExistentMethodsAllowed() || (!is_null($this->_mockery_partial) && method_exists($this->_mockery_partial, $method)) || is_callable($this->_mockery_parentClass . '::' . $method))) {
if ($this->_mockery_defaultReturnValue instanceof Undefined) {
return $this->_mockery_defaultReturnValue->{$method}(...$args);
}
Expand Down Expand Up @@ -995,7 +995,7 @@ protected function mockery_getMethods()
private function hasMethodOverloadingInParentClass()
{
// if there's __call any name would be callable
return is_callable($this->parentClass . '::aFunctionNameThatNoOneWouldEverUseInRealLife12345');
return is_callable($this->_mockery_parentClass . '::aFunctionNameThatNoOneWouldEverUseInRealLife12345');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Expand Up @@ -335,6 +335,7 @@
<code>allowMockingNonExistentMethods</code>
<code>disableReflectionCache</code>
<code>enableReflectionCache</code>
<code>getDefaultMatcher</code>
<code>getInternalClassMethodParamMap</code>
<code>mockingMethodsUnnecessarilyAllowed</code>
<code>reflectionCacheEnabled</code>
Expand Down Expand Up @@ -791,7 +792,6 @@
<code>mockery_allocateOrder</code>
<code>mockery_getGroups</code>
<code>mockery_setGroup</code>
<code>new $matcher($expected)</code>
<code>validate</code>
</MixedMethodCall>
<MixedReturnStatement>
Expand Down
14 changes: 14 additions & 0 deletions tests/Mockery/ExpectationTest.php
Expand Up @@ -2158,6 +2158,20 @@ public function it_uses_a_matchers_to_string_method_in_the_exception_output()

Mockery::close();
}

public function testNonObjectEqualsExpectation()
{
$input = ['club_id' => 1, 'user_id' => 1, 'is_admin' => 1];

$foo = Mockery::mock();

$foo->shouldReceive('foo')->with($input)->andReturn('foobar');

// only sort the input to change the order but not the values.
ksort($input);

self::assertSame('foobar', $foo->foo($input));
}
}

interface IWater
Expand Down

0 comments on commit c9cf52d

Please sign in to comment.