-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
michalbundyra
commented
Mar 22, 2018
- more generic tests in delegators to use all types of factories
- removed duplicated test as these are covered by more generic tests using all factory types
- refactor expected exception assertion
- added one more missing delegator test
The same functionality is tested in testDelegatorFactoriesTriggerForFactoryBackedServicesUsingAnyFactoryType with data "invokable-class-name"
Use dataProvider delegatorService for all valid services which can be delegated
4a703db
to
8e64831
Compare
With all these changes Aura.Di and Pimple integration PRs works: |
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 looks mostly good.. with the major exception of the DelegatorTestTrait
. That class appears to be almost entirely rewritten, without any commentary on why.
I'm not sure if this was based on an earlier version of #1, or if there are reasons for the changes, but I can't merge this as-is currently because I don't understand why the changes were made.
@@ -13,7 +13,7 @@ | |||
|
|||
trait AliasTestTrait | |||
{ | |||
public function alias() : Generator | |||
final public function alias() : Generator |
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.
Just noting for the record, in case anybody wonders about the final
visibility: this is because we do not want implementors overriding these tests and testing different behavior.
@@ -63,31 +63,7 @@ public function testDelegatorsDoNotOperateOnServices() : void | |||
self::assertSame($myService, $instance); | |||
} | |||
|
|||
public function testDelegatorsOperateOnFactoryBackedServices() : void |
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 is this test case removed?
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.
Covered by testDelegatorFactoriesTriggerForFactoryBackedServicesUsingAnyFactoryType
with data provider factoriesForDelegators
(so more generic, for all types of factories).
@@ -143,67 +119,64 @@ public function testDelegatorsNamedForAliasDoNotApplyToInvokableServiceResolvedV | |||
self::assertSame($instance, $container->get(TestAsset\Service::class)); | |||
} | |||
|
|||
public function testDelegatorsDoNotApplyToAliasResolvingToServiceEntry() : void | |||
final public function testDelegatorsNamedForAliasDoNotApplyToInvokableServiceWithAlias() : void |
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 are these two tests swapped? It makes understanding the diff far harder (I had to look back and forth around a half-dozen times to realize that was what happened...)
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.
Diff is messed up. Test testDelegatorsNamedForAliasDoNotApplyToInvokableServiceWithAlias
was added here, as it is similar to the previous so it was logic place to add it.
Test testDelegatorsDoNotApplyToAliasResolvingToServiceEntry
has not been modified at all, just added final
.
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.
testDelegatorsDoNotApplyToAliasResolvingToServiceEntry
was moved; it now appears after the new test 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.
It was not moved, another one was added before it, if you check "split view" maybe it will be clearer.
@@ -231,39 +204,7 @@ public function testDelegatorsDoNotTriggerForAliasTargetingInvokableService() : | |||
self::assertSame($instance, $container->get(TestAsset\Service::class)); | |||
} | |||
|
|||
public function testDelegatorsTriggerForFactoryServiceResolvedByAlias() : void |
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.
I found where this was moved, and discovered you added a data provider, which is excellent... but why was it moved? (Moving things around makes code review sooooo hard!)
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.
It was moved to keep logical order, I've used dataProvders to provide more generic tests for all factory types.
I agree that moving things around makes code review harder. I think it was needed here to keep it clear in code later on.
@@ -342,7 +280,32 @@ public function testDelegatorsReceiveCallbackResolvingToReturnValueOfPrevious( | |||
self::assertSame($instance, $container->get($serviceNameToTest)); | |||
} | |||
|
|||
public function testMultipleAliasesForADelegatedInvokableServiceReceiveSameInstance() |
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.
Again: why was this test moved?
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.
It was not moved, just diff is showing it wrong. New test was added before that one, and here only final
keyword was added.
} | ||
|
||
// @codingStandardsIgnoreStart | ||
public function testWhenInvokableWithDelegatorsResolvesToInvalidFactoryClassAnExceptionIsRaisedWhenCallbackIsInvoked() |
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 was this test removed?
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.
Covered by more generic test testWithDelegatorsResolvesToInvalidClassAnExceptionIsRaisedWhenCallbackIsInvoked
with data provider invalidService
.
} | ||
|
||
// @codingStandardsIgnoreStart | ||
public function testWhenServiceWithDelegatorsResolvesToNonExistentFactoryClassNoExceptionIsRaisedIfCallbackNeverInvoked() |
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 was this test removed?
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.
Covered by testWithDelegatorsResolvesToInvalidClassNoExceptionIsRaisedIfCallbackNeverInvoked
with data provider invalidService
.
} | ||
|
||
// @codingStandardsIgnoreStart | ||
public function testWhenServiceWithDelegatorsResolvesToInvalidFactoryClassAnExceptionIsRaisedIfCallbackNeverInvoked() |
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 was this test removed?
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 test name was wrong, it was testing that "no exception is raised ...".
Covered by testWithDelegatorsResolvesToInvalidClassNoExceptionIsRaisedIfCallbackNeverInvoked
with data provider invalidService
self::assertInstanceOf(TestAsset\Delegator::class, $instance); | ||
} | ||
|
||
// @codingStandardsIgnoreStart | ||
public function testWhenServiceWithDelegatorsResolvesToNonExistentFactoryClassAnExceptionIsRaisedWhenCallbackIsInvoked() |
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 was this test removed?
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.
Covered by testWithDelegatorsResolvesToInvalidClassAnExceptionIsRaisedWhenCallbackIsInvoked
with data provider invalidService
.
$container->get('service'); | ||
} | ||
|
||
public function testWhenServiceWithDelegatorsResolvesToInvalidFactoryClassAnExceptionIsRaisedWhenCallbackIsInvoked() |
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 was this test removed?
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.
Covered by testWithDelegatorsResolvesToInvalidClassAnExceptionIsRaisedWhenCallbackIsInvoked
with data provider invalidService
@weierophinney I think the diff is messed up somehow, it's better to have a look on separate commits. Basically I've added data providers to have more cases and removed duplicated tests (as data providers covers all cases). I can write more explanations tomorrow, but I think when you have a look commit by commit it should be clearer. |
} | ||
|
||
public function testDelegatorsDoNotTriggerForAliasTargetingFactoryBasedService() : void |
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 one is removed, because it's covered by testDelegatorsDoNotTriggerForAliasTargetingFactoryBasedServiceUsingAnyFactoryType
.
@@ -281,14 +222,6 @@ public function delegatorService() : Generator | |||
TestAsset\Service::class, | |||
]; | |||
|
|||
yield 'factory-service' => [ |
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.
Check foreach
loop below - we are generating there entities for all factory types, the same about alias-of-factory-service
.
try { | ||
$container->get(TestAsset\NonExistent::class); | ||
} catch (Throwable $e) { | ||
if (! $e instanceof Error && ! $e instanceof TypeError && ! $e instanceof ContainerExceptionInterface) { |
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.
Here we allow Error
, TypeError
and ContainerExceptionInterface
.
Please note that TypeError extends Error
so it's no point to use both here - Error
is enough. And this is why in testWithDelegatorsResolvesToInvalidClassAnExceptionIsRaisedWhenCallbackIsInvoked
we use only Error
and ContainerExceptionInterface
.