-
Notifications
You must be signed in to change notification settings - Fork 89
Hotfix #279 #280
base: master
Are you sure you want to change the base?
Hotfix #279 #280
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
use stdClass; | ||
use Zend\ServiceManager\Factory\FactoryInterface; | ||
use Zend\ServiceManager\Factory\InvokableFactory; | ||
use Zend\ServiceManager\Proxy\LazyServiceFactory; | ||
use Zend\ServiceManager\ServiceManager; | ||
use ZendTest\ServiceManager\TestAsset\InvokableObject; | ||
use ZendTest\ServiceManager\TestAsset\SimpleServiceManager; | ||
|
@@ -283,4 +284,51 @@ public function testFactoryMayBeStaticMethodDescribedByCallableString() | |
$serviceManager = new SimpleServiceManager($config); | ||
$this->assertEquals(stdClass::class, get_class($serviceManager->get(stdClass::class))); | ||
} | ||
|
||
/** | ||
* Hotfix #279 | ||
* @see https://github.com/zendframework/zend-servicemanager/issues/279 | ||
*/ | ||
public function testConfigureMultipleTimes() | ||
{ | ||
$delegatorFactory = function ( | ||
ContainerInterface $container, | ||
$name, | ||
callable $callback | ||
) { | ||
/** @var InvokableObject $instance */ | ||
$instance = $callback(); | ||
$options = $instance->getOptions(); | ||
$inc = ! empty($options['inc']) ? $options['inc'] : 0; | ||
return new InvokableObject(['inc' => ++$inc]); | ||
}; | ||
|
||
$config = [ | ||
'factories' => [ | ||
'Foo' => function () { | ||
return new InvokableObject(); | ||
}, | ||
], | ||
'delegators' => [ | ||
'Foo' => [ | ||
$delegatorFactory, | ||
LazyServiceFactory::class, | ||
], | ||
], | ||
'lazy_services' => [ | ||
'class_map' => [ | ||
'Foo' => InvokableObject::class, | ||
], | ||
], | ||
]; | ||
|
||
$serviceManager = new ServiceManager($config); | ||
$serviceManager->configure($config); | ||
|
||
/** @var InvokableObject $instance */ | ||
$instance = $serviceManager->get('Foo'); | ||
|
||
self::assertInstanceOf(InvokableObject::class, $instance); | ||
self::assertSame(1, $instance->getOptions()['inc']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a single test should have only one assertion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, I think it can be a valid assertion. Instead to throw an error in case of failure I'm asserting that the second assertion depends on the first assertion. If it's enough the phpunit error catch for you, I can remove the first assertion. Different point of view :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine to have multiple assertions as long as they are connected, imho. Kinda "one logic assertion". I was checking what people say about it, and I see some approach to write test with single assertion. I see the advantages of it, but I think this approach would be more messy. You can see that in other tests usually we have more than one assertion, but these are connected - as you are saying, @thomasvargiu. any my favourite comment there is:
🤣 |
||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.