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

PhpUnit 7 integration and drop support for php70 #44

Merged
merged 35 commits into from Apr 6, 2018
Merged

Conversation

Giuffre
Copy link
Contributor

@Giuffre Giuffre commented Feb 4, 2018

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 to moka but phpunit/phpunit-mock-objects is and follows phpunit development, we must update.

@Giuffre Giuffre changed the title PhpUnit 7 integration PhpUnit 7 integration and drop support for php70 Feb 4, 2018
@Giuffre Giuffre requested a review from xzhayon February 4, 2018 15:37
@Giuffre Giuffre self-assigned this Feb 4, 2018
@Giuffre Giuffre requested a review from Jean85 February 4, 2018 17:09
@Giuffre
Copy link
Contributor Author

Giuffre commented Feb 4, 2018

@Jean85 or @xzhavilla consider you my workaround properly in this context?

To provide a full integration with PHPUnit\Framework\TestCase we attach automatically the generated mock object with the method registerMockObject and test it through https://github.com/facile-it/moka/blob/feature/phpunit7/tests/MokaTest.php. Until PHPUnit 6.* can be done by calling directly the method verifyMockObjects but from 7.* this method has changed the visibility from protected to private and to call it we need to do some magic with reflection.

Copy link
Member

@Jean85 Jean85 left a 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...

@Giuffre
Copy link
Contributor Author

Giuffre commented Feb 7, 2018

@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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

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) {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

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
Copy link
Member

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());
Copy link
Member

@xzhayon xzhayon Feb 13, 2018

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(
Copy link
Member

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.

*/
function buildProxy(string $fqcn, MockingStrategyInterface $mockingStrategy): ProxyInterface
{
return (new ProxyGenerator($mockingStrategy))->get($fqcn);
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@xzhayon
Copy link
Member

xzhayon commented Feb 13, 2018

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 Giuffre added this to the v2.2.0 milestone Mar 1, 2018
@xzhayon
Copy link
Member

xzhayon commented Apr 3, 2018

@Giuffre: I've reverted the change which removed the ProxyGeneratorFactory, to get generator cache back. Apart from that, I cleaned up some stuff and fixed a couple of tests.

I do not like all these functions, but, if it's fine for you, this changeset can go in!

@xzhayon xzhayon merged commit 5369e8a into master Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants