Skip to content

Instantly share code, notes, and snippets.

@77web
Last active December 19, 2015 10:09
Show Gist options
  • Save 77web/5938817 to your computer and use it in GitHub Desktop.
Save 77web/5938817 to your computer and use it in GitHub Desktop.
unit test using Phake in OpenPNE3(finally working!!)
<?php
class opActivityTweetPluginConfiguration extends sfPluginConfiguration
{
public function configure()
{
//hack member config
$this->dispatcher->connect('op_action.pre_execute_member_config', array($this, 'listenToPreMemberConfig'));
//manual post
$this->dispatcher->connect('op_action.post_execute_member_updateActivity', array($this, 'listenToManualActivityPost'));
}
public function listenToPreMemberConfig(sfEvent $event)
{
//some code here
}
public function listenToManualActivityPost(sfEvent $event)
{
//some code here
}
}
<?php
include_once dirname(__FILE__).'/../../bootstrap/unit.php';
$t = new lime_test(null, new lime_output_color());
$appConfig = Phake::mock('sfApplicationConfiguration');
$dispatcher = Phake::mock('sfEventDispatcher');
Phake::when($appConfig)->getEventDispatcher()->thenReturn($dispatcher);
$config = new opActivityTweetPluginConfiguration($appConfig);
try
{
Phake::verify($appConfig, Phake::times(1))->getEventDispatcher();
$t->pass('sfApplicationConfiguration->getEventDispatcher() has been called 1 time.');
}
catch (Phake_Exception_VerificationException $e)
{
$t->fail($e->getMessage());
}
try
{
Phake::verify($dispatcher)->connect('op_action.pre_execute_member_config', Phake::capture($preExecuteMemberConfigCallback));
$t->pass('$dispatcher->connect("op_action.pre_execute_member_config", array(...)) has been called 1 time.');
}
catch (Phake_Exception_VerificationException $e)
{
$t->fail($e->getMessage());
}
$t->isa_ok($preExecuteMemberConfigCallback, 'array');
$t->is(count($preExecuteMemberConfigCallback), 2);
$t->isa_ok($preExecuteMemberConfigCallback[0], 'opActivityTweetPluginConfiguration');
$t->is($preExecuteMemberConfigCallback[1], 'listenToPreMemberConfig');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment