-
Notifications
You must be signed in to change notification settings - Fork 89
Fix problem with string callables failing in PHP 5.6. #206
Changes from 1 commit
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 |
---|---|---|
|
@@ -267,4 +267,20 @@ public function testSetAliasShouldWorkWithRecursiveAlias() | |
$this->assertSame($service, $alias); | ||
$this->assertSame($service, $headAlias); | ||
} | ||
|
||
public static function sampleFactory() | ||
{ | ||
return new stdClass(); | ||
} | ||
|
||
public function testStaticCallable() | ||
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. Please provide a more descriptive name, something like 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. The test is not actually testing anything PHP 5.6-specific. It is simply testing whether a service manager can accept a callable string of the format class::method to use a static method as a factory. As such, I have given the method a more descriptive name but have not made it a version-specific test; this is a behavior of the service manager that some people depend on, so I think it's worth testing for future regressions in case something different causes this behavior to break. Of course, I'll happily change this if you still feel it is necessary -- but I wrote the test with the intention of exercising a generic behavior, not trying to capture the implementation details of my specific fix. 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 also occurs to me that we could, if you think it worthwhile, add a complementary |
||
{ | ||
$config = [ | ||
'factories' => [ | ||
stdClass::class => 'ZendTest\ServiceManager\ServiceManagerTest::sampleFactory', | ||
] | ||
]; | ||
$serviceManager = new SimpleServiceManager($config); | ||
$this->assertEquals(stdClass::class, get_class($serviceManager->get(stdClass::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.
If this is PHP 5.6-specific, let's add a check for being run under PHP 5.6, so that we can remove this once we drop PHP 5 support.
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.
Good idea. I've made the change using the PHP_MAJOR_VERSION constant; please let me know if you have a different preferred way of doing version checking in the code.