-
Notifications
You must be signed in to change notification settings - Fork 46
Bugfixes #71
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
Bugfixes #71
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace spec\Http\Discovery\Helper; | ||
|
||
use Http\Discovery\Strategy\DiscoveryStrategy; | ||
|
||
/** | ||
* This is a discovery helper used in tests. It will always pass an empty array of candidates. | ||
* | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class FailedDiscoveryStrategy implements DiscoveryStrategy | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getCandidates($type) | ||
{ | ||
return []; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace spec\Http\Discovery\Helper; | ||
|
||
use Http\Discovery\Strategy\DiscoveryStrategy; | ||
|
||
/** | ||
* This is a discovery helper used in tests. It will always pass a class named "Sucess" | ||
* | ||
* @author Tobias Nyholm <[email protected]> | ||
*/ | ||
class SuccessfullDiscoveryStrategy implements DiscoveryStrategy | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getCandidates($type) | ||
{ | ||
return [['class'=>'Success']]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
use Http\Discovery\Exception\DiscoveryFailedException; | ||
use Http\Discovery\Exception\StrategyUnavailableException; | ||
use Http\Discovery\Strategy\DiscoveryStrategy; | ||
|
||
/** | ||
* Registry that based find results on class existence. | ||
|
@@ -88,8 +87,10 @@ private static function getFromCache($type) | |
} | ||
|
||
$candidate = self::$cache[$type]; | ||
if (!self::evaluateCondition($candidate['condition'])) { | ||
return; | ||
if (isset($candidate['condition'])) { | ||
if (!self::evaluateCondition($candidate['condition'])) { | ||
return; | ||
} | ||
} | ||
|
||
return $candidate['class']; | ||
|
@@ -109,7 +110,7 @@ private static function storeInCache($type, $class) | |
/** | ||
* Set new strategies and clear the cache. | ||
* | ||
* @param DiscoveryStrategy[] $strategies | ||
* @param array $strategies string array of fully qualified class name to a DiscoveryStrategy | ||
*/ | ||
public static function setStrategies(array $strategies) | ||
{ | ||
|
@@ -120,9 +121,9 @@ public static function setStrategies(array $strategies) | |
/** | ||
* Append a strategy at the end of the strategy queue. | ||
* | ||
* @param DiscoveryStrategy $strategy | ||
* @param string $strategy Fully qualified class name to a DiscoveryStrategy | ||
*/ | ||
public static function appendStrategy(DiscoveryStrategy $strategy) | ||
public static function appendStrategy($strategy) | ||
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. could you add a test? i think we should have a test that shows this was a problem. 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. You are correct. But Im not sure how to write a test for that. 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. Add a resource ONLY in an appended strategy and see if you can resolve that resource. 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. and to test this, first setStrategies to empty or something that never works, then append the one that returns a mock client. 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 correct me if Im wrong. But the problem here is that 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. Something like this is not possible. function it_prepends_strategies(DiscoveryStrategy $successfulStrategy, DiscoveryStrategy $addedStrategy) {
$successfulStrategy->getCandidates('Foobar')->willReturn([['class'=>'Success']]);
$addedStrategy->getCandidates('Foobar')->shouldBeCalled()->willReturn([['class'=>'Added']]);
ClassDiscovery::setStrategies([$successfulStrategy]);
ClassDiscovery::prependStrategy($addedStrategy);
$this->find('Foobar')->shouldReturn('Added');
}
function it_appends_strategies(DiscoveryStrategy $failedStrategy, DiscoveryStrategy $addedStrategy) {
$failedStrategy->getCandidates('Foobar')->shouldBeCalled()->willReturn([]);
$addedStrategy->getCandidates('Foobar')->shouldBeCalled()->willReturn([['class'=>'Added']]);
ClassDiscovery::setStrategies([$failedStrategy]);
ClassDiscovery::appendStrategy($addedStrategy);
$this->find('Foobar')->shouldReturn('Added');
} 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. maybe like this: ClassDiscovery::setStrategies(['Http\Discovery\MockDiscovery']);
...
class MockDiscovery implements Discovery
{
...
}
class MockClient implements Client
{
public function ... () {} // do nothing
} but indeed with passing strings, you would need quite a few mock classes. |
||
{ | ||
self::$strategies[] = $strategy; | ||
self::clearCache(); | ||
|
@@ -131,11 +132,11 @@ public static function appendStrategy(DiscoveryStrategy $strategy) | |
/** | ||
* Prepend a strategy at the beginning of the strategy queue. | ||
* | ||
* @param DiscoveryStrategy $strategy | ||
* @param string $strategy Fully qualified class name to a DiscoveryStrategy | ||
*/ | ||
public static function prependStrategy(DiscoveryStrategy $strategy) | ||
public static function prependStrategy($strategy) | ||
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. maybe a full functional test with a prepend strategy that returns a mock? |
||
{ | ||
self::$strategies = array_unshift(self::$strategies, $strategy); | ||
array_unshift(self::$strategies, $strategy); | ||
self::clearCache(); | ||
} | ||
|
||
|
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.
a similar test could be done here, setting the strategies to only that test strategy that returns a mock client