Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Improvements #4

Merged
merged 11 commits into from
Apr 5, 2018
Merged

Improvements #4

merged 11 commits into from
Apr 5, 2018

Conversation

michalbundyra
Copy link
Member

  • 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"
@michalbundyra
Copy link
Member Author

With all these changes Aura.Di and Pimple integration PRs works:

@weierophinney weierophinney changed the base branch from feature/review-tests to master April 4, 2018 21:32
@weierophinney weierophinney reopened this Apr 4, 2018
Copy link
Member

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

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

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?

Copy link
Member Author

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

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...)

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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

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!)

Copy link
Member Author

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

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?

Copy link
Member Author

@michalbundyra michalbundyra Apr 5, 2018

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

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?

Copy link
Member Author

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

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?

Copy link
Member Author

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

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?

Copy link
Member Author

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

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?

Copy link
Member Author

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

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?

Copy link
Member Author

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

@michalbundyra
Copy link
Member Author

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

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' => [
Copy link
Member Author

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

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.

@weierophinney weierophinney merged commit aea2454 into master Apr 5, 2018
weierophinney added a commit that referenced this pull request Apr 5, 2018
@weierophinney weierophinney deleted the improvements branch April 5, 2018 13:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants