Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Make StandaloneExtensionManagers configurable#55

Closed
Synchro wants to merge22 commits intozendframework:developfromSynchro:master
Closed
Show file tree
Hide file tree
Changes from6 commits
Commits
Show all changes
22 commits
Select commitHold shift + click to select a range
316e9b7
Merge branch 'hotfix/43'
weierophinneyNov 1, 2017
5387abb
Make $extensions property protected
SynchroNov 10, 2017
b9f3004
Switch to making StandaloneExtensionManager configurable
SynchroNov 14, 2017
1351b73
Not final
SynchroNov 14, 2017
e09a172
Add tests for Writer StandaloneExtensionMananger
SynchroNov 14, 2017
7155b5a
No return value from remove, simplify
SynchroNov 14, 2017
c431c49
Implement same changes for Writer
SynchroNov 14, 2017
7a91f4f
Use class pseudoconstants rather than strings for class names
SynchroNov 14, 2017
849b55d
Fix namespaced names
SynchroNov 14, 2017
8c3860f
Fix data provider
SynchroNov 14, 2017
223e867
Fix test provider namespaces
SynchroNov 14, 2017
4e68bee
Writer, not Reader
SynchroNov 14, 2017
f807526
Fix data provider
SynchroNov 14, 2017
f71a00c
Improve docs a little
SynchroNov 14, 2017
d4a8efe
Add checks when adding extensions
SynchroNov 14, 2017
a9a5af4
Use mock extension
SynchroNov 14, 2017
ce6fd8b
Code style
SynchroNov 14, 2017
3e379f8
Fix wrong exceptions
SynchroNov 14, 2017
789b4b2
Fix wrong exception
SynchroNov 14, 2017
4096b6e
More tests
SynchroNov 14, 2017
1c80524
More tests
SynchroNov 14, 2017
32982ff
Break out tests
SynchroNov 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletionssrc/Reader/StandaloneExtensionManager.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
Copy link
Member

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?

Copy link
Member

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

Copy link
ContributorAuthor

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.

Copy link
Member

@XerkusXerkusNov 14, 2017
edited
Loading

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.

}

/**
* Remove an extension.
*
* @param string $name
*/
public function remove($name)
{
unset($this->extensions[$name]);
}
}
14 changes: 14 additions & 0 deletionstest/Reader/StandaloneExtensionManagerTest.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,4 +80,18 @@ public function testEachPluginRetrievalReturnsNewInstance($pluginName, $pluginCl
$this->assertInstanceOf($pluginClass, $test);
$this->assertNotSame($extension, $test);
}

public function testAddingPlugin()
{
$this->extensions->add('Test/Test', 'mytestextension');
$this->assertTrue($this->extensions->has('Test/Test'));
}

public function testRemovingPlugin()
{
$this->extensions->add('Test/Test', 'mytestextension');
$this->assertTrue($this->extensions->remove('Test/Test'));
$this->assertFalse($this->extensions->has('Test/Test'));
$this->assertFalse($this->extensions->remove('Test/Test'));
}
}
88 changes: 88 additions & 0 deletionstest/Writer/StandaloneExtensionManagerTest.php
View file
Open in desktop
Original file line numberDiff line numberDiff 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is supposed to be Writer

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The 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()
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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'));
}
}

[8]ページ先頭

©2009-2025 Movatter.jp