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
PhpUnit 7 integration and drop support for php70 #44
Conversation
f3743da
to
790545f
Compare
…) that is private
@Jean85 or @xzhavilla consider you my workaround properly in this context? To provide a full integration with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workaround was probably the only one possible. I don't know whole Moka's architecture, the only bothering stuff could be performance if that is called many times.
BTW, it's still a workaround, so you could try to find a completely different approach anyway...
@Jean85 I agree. Maybe we can resolve it with another pull request. |
It's not worth using that convenience method now that we have to invoke it via reflection. As a very big plus, only catch the very specific expections thrown on failed expectations, thus making tests much more robust.
@@ -45,7 +46,7 @@ public function __get(%s $name) | |||
'; | |||
|
|||
/** | |||
* @param \ReflectionClass $class | |||
* @param \Reflector $class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? \ReflectionClass implements \Reflector.
%s %s function %s(%s)%s | ||
{ | ||
%s $this->__call("%s", func_get_args()); | ||
} | ||
'; | ||
|
||
/** | ||
* @param \ReflectionMethod $method | ||
* @param \Reflector|\ReflectionMethod $method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we call a specific method of the concrete class implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why the docblock had \ReflectionMethod instead of \Reflector. I mean that there shouldn't be any \Reflector type hint in the docblock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to @Giuffre it's a matter of IDE warnings... Resolving.
|
||
/** | ||
* @param \ReflectionParameter $parameter | ||
* @param \Reflector|\ReflectionParameter $parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
unset(%s%s); | ||
'; | ||
|
||
/** | ||
* @param \ReflectionProperty $property | ||
* @param \Reflector|\ReflectionProperty $property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we call a specific method of the concrete class implementation.
@@ -32,7 +32,7 @@ protected static function doGenerate(\ReflectionParameter $parameter): string | |||
: 'null'; | |||
|
|||
$defaultValue = '=' . $defaultValue; | |||
} catch (\ReflectionException $exception) { | |||
} catch (\Exception $exception) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really safe silencing all the exceptions?
%s %s $%s; | ||
'; | ||
|
||
/** | ||
* @param \ReflectionProperty $property | ||
* @param \Reflector|\ReflectionProperty $property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we call a specific method of the concrete class implementation.
|
||
/** | ||
* @param \ReflectionMethod $method | ||
* @param \Reflector|\ReflectionMethod $method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@@ -195,11 +237,12 @@ public function testBuildWithPHP71Class() | |||
$this->strategy->get($this->mock)->getInt() | |||
); | |||
|
|||
$this->expectException(\Exception::class); | |||
$this->expectExceptionMessage($this->namesWithValues['throwException']->getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this? It's meant to test explicitly which exception is thrown, it is important for it to be that way.
@@ -14,10 +14,13 @@ class IncompleteMockingStrategy extends AbstractMockingStrategy | |||
|
|||
protected function doBuild(string $fqcn) | |||
{ | |||
throw new \Exception(); | |||
throw new \BadMethodCallException(sprintf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a test class, a specific exception is not serving any need.
src/Factory/buildProxy.php
Outdated
*/ | ||
function buildProxy(string $fqcn, MockingStrategyInterface $mockingStrategy): ProxyInterface | ||
{ | ||
return (new ProxyGenerator($mockingStrategy))->get($fqcn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't we caching proxy generators anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I've noticed that we have only n proxy generator where n is the number of strategies and probably the caching is useless for improving performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we're creating multiple mock objects in a test? Without a cache we're also creating multiple generators.
The workaround was fine to me, yet not needed. I replaced the call to the private method with calls to specific mock methods. Furthermore, I made the test catch only specific exceptions, to make it more robust. |
@Giuffre: I've reverted the change which removed the I do not like all these functions, but, if it's fine for you, this changeset can go in! |
To catch up the roadmap of PHPUnit (https://github.com/sebastianbergmann/phpunit/milestones, https://phpunit.de/) we must drop the support to PHP 7.0.
As
phpunit/phpunit
is not a required dependency tomoka
butphpunit/phpunit-mock-objects
is and follows phpunit development, we must update.