Skip to content

Commit

Permalink
added test for Handler::addPlugin shortname with constructor arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dotEvan committed Mar 26, 2010
1 parent a3b5214 commit 96753c5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Tests/Phergie/Plugin/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,21 @@ public function testAddPluginThrowsExceptionIfPluginNotInstantiable()
}

/**
* @todo add a tests for using addPlugin with a shortname and args
* addPlugin with shortname and arguments passes args to constructor
*
* @return null
*/
public function testAddPluginShortnamePassesArgsToConstructor() {
$plugin_name = 'TestPluginFromFile';
$this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');

$arguments = array('a', 'b', 'c');

$plugin = $this->handler->addPlugin($plugin_name, $arguments);
for($i = 0; $i < count($arguments); $i++) {
$this->assertEquals($arguments[$i], $plugin->getArg($i));
}
}

/**
* implements __isset
Expand Down
28 changes: 28 additions & 0 deletions Tests/Phergie/Plugin/TestPluginFromFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,32 @@
*/
class Phergie_Plugin_TestPluginFromFile extends Phergie_Plugin_Abstract
{
/**
* holds the arguments that were passed in to the constructor
* @var array
*/
protected $args;

/**
* processes a variable number of arguments into the args property
*
* @return null
*/
public function __construct()
{
$this->args = func_get_args();
}

/**
* returns the argument at the requested index that was stored
* when passed in on class instantiation
*
* @param int $index of the argument
*
* @return mixed
*/
public function getArg($index)
{
return @$this->args[$index];
}
}

0 comments on commit 96753c5

Please sign in to comment.