- Notifications
You must be signed in to change notification settings - Fork40
Make StandaloneExtensionManagers configurable#55
Uh oh!
There was an error while loading.Please reload this page.
Changes from6 commits
316e9b75387abbb9f30041351b73e09a1727155b5ac431c497a91f4f849b55d8c3860f223e8674e68beef807526f71a00cd4a8efea9a5af4ce6fd8b3e379f8789b4b24096b6e1c8052432982ffFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -49,4 +49,25 @@ public function get($extension) | ||
| $class = $this->extensions[$extension]; | ||
| return new $class(); | ||
| } | ||
| /** | ||
| * Add an extension. | ||
| * | ||
| * @param string $name | ||
| * @param string $class | ||
| */ | ||
| public function add($name, $class) | ||
| { | ||
| $this->extensions[$name] = $class; | ||
| ||
| } | ||
| /** | ||
| * Remove an extension. | ||
| * | ||
| * @param string $name | ||
| */ | ||
| public function remove($name) | ||
| { | ||
| unset($this->extensions[$name]); | ||
| } | ||
| } | ||
| 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; | ||
| ||
| 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() | ||
| ||
| { | ||
| $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')); | ||
| } | ||
| } | ||