-
Notifications
You must be signed in to change notification settings - Fork 42
Make StandaloneExtensionManagers configurable #55
Changes from 6 commits
316e9b7
5387abb
b9f3004
1351b73
e09a172
7155b5a
c431c49
7a91f4f
849b55d
8c3860f
223e867
4e68bee
f807526
f71a00c
d4a8efe
a9a5af4
ce6fd8b
3e379f8
789b4b2
4096b6e
1c80524
32982ff
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,88 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
namespace ZendTest\Feed\Writer; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Zend\Feed\Reader\StandaloneExtensionManager; | ||
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. This is supposed to be Writer 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. Ah, my IDE had collapsed the use statements so I didn't see them. Fixed. |
||
use Zend\Feed\Reader\Extension\WellFormedWeb\Entry; | ||
use Zend\Feed\Reader\Extension\Syndication\Feed; | ||
use Zend\Feed\Reader\ExtensionManagerInterface; | ||
|
||
class StandaloneExtensionManagerTest extends TestCase | ||
{ | ||
/** | ||
* @var StandaloneExtensionManager | ||
*/ | ||
private $extensions; | ||
|
||
public function setUp() | ||
{ | ||
$this->extensions = new StandaloneExtensionManager(); | ||
} | ||
|
||
public function testIsAnExtensionManagerImplementation() | ||
{ | ||
$this->assertInstanceOf(ExtensionManagerInterface::class, $this->extensions); | ||
} | ||
|
||
public function defaultPlugins() | ||
{ | ||
return [ | ||
'Atom\Renderer\Feed' => Extension\Atom\Renderer\Feed::class, | ||
'Content\Renderer\Entry' => Extension\Content\Renderer\Entry::class, | ||
'DublinCore\Renderer\Entry' => Extension\DublinCore\Renderer\Entry::class, | ||
'DublinCore\Renderer\Feed' => Extension\DublinCore\Renderer\Feed::class, | ||
'ITunes\Entry' => Extension\ITunes\Entry::class, | ||
'ITunes\Feed' => Extension\ITunes\Feed::class, | ||
'ITunes\Renderer\Entry' => Extension\ITunes\Renderer\Entry::class, | ||
'ITunes\Renderer\Feed' => Extension\ITunes\Renderer\Feed::class, | ||
'Slash\Renderer\Entry' => Extension\Slash\Renderer\Entry::class, | ||
'Threading\Renderer\Entry' => Extension\Threading\Renderer\Entry::class, | ||
'WellFormedWeb\Renderer\Entry' => Extension\WellFormedWeb\Renderer\Entry::class, | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider defaultPlugins | ||
*/ | ||
public function testHasAllDefaultPlugins($pluginName, $pluginClass) | ||
{ | ||
$this->assertTrue($this->extensions->has($pluginName)); | ||
} | ||
|
||
/** | ||
* @dataProvider defaultPlugins | ||
*/ | ||
public function testCanRetrieveDefaultPluginInstances($pluginName, $pluginClass) | ||
{ | ||
$extension = $this->extensions->get($pluginName); | ||
$this->assertInstanceOf($pluginClass, $extension); | ||
} | ||
|
||
/** | ||
* @dataProvider defaultPlugins | ||
*/ | ||
public function testEachPluginRetrievalReturnsNewInstance($pluginName, $pluginClass) | ||
{ | ||
$extension = $this->extensions->get($pluginName); | ||
$this->assertInstanceOf($pluginClass, $extension); | ||
|
||
$test = $this->extensions->get($pluginName); | ||
$this->assertInstanceOf($pluginClass, $test); | ||
$this->assertNotSame($extension, $test); | ||
} | ||
|
||
public function testPluginAddRemove() | ||
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. Same here, additional tests for expected exception in case of invalid extension class or object of valid extension. 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. additional tests to ensure extensions derived from allowed class or with classnames ending with 'Feed' or 'Entry' are accepted |
||
{ | ||
$this->extensions->add('Test/Test', 'mytestextension'); | ||
$this->assertTrue($this->extensions->has('Test/Test')); | ||
$this->extensions->remove('Test/Test'); | ||
$this->assertFalse($this->extensions->has('Test/Test')); | ||
} | ||
} |
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.
No validation what is added to the manager?
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 point.
$class
should be checked to be instance ofZend\Feed\Reader\Extension\AbstractEntry
orZend\Feed\Reader\Extension\AbstractFeed
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 wondered about that - $class can be a string (it was in the components until I changed it), but it might be the name of something that doesn't exist yet, so I don't know that it can be validated at this point.
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.
with check it will be autoloaded when extension is registered. Plugin manager validates on creation.