protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $service = new Twitter(sfConfig::get('twitter_username'), sfConfig::get('twitter_password')); $harvester = new HarvestFollowers($service, $connection); $harvester->execute(); }
public function testDefault() { $followers = array(array('id' => '14139010', 'name' => 'Pascal de Vink', 'screen_name' => 'pascaldevink', 'description' => 'Mock description', 'location' => 'Amsterdam, NL', 'url' => '', 'protected' => false, 'followers_count' => 45, 'profile_image_url' => 'http://a1.twimg.com/profile_images/429161922/twtr_normal.png'), array('id' => '14139011', 'name' => 'Jan de Vries', 'screen_name' => 'jandevries', 'description' => 'Mock description', 'location' => 'Lutjebroek, NL', 'url' => '', 'protected' => false, 'followers_count' => 2, 'profile_image_url' => 'http://a1.twimg.com/profile_images/429161922/twtr_normal.png')); // Setup mocking $mock = Mockery::mock('twitter'); $mock->shouldReceive('getFollowers')->once()->andReturn($followers)->ordered(); $mock->shouldReceive('existsFriendship')->with(Mockery::type('string'), Mockery::type('string'))->twice()->andReturn(true, false); $mock->shouldReceive('createFriendship')->with(Mockery::type('string'))->once(); // Call the task and inject the mock $harvester = new HarvestFollowers($mock); $harvester->execute(); // Verify the mock $mock->mockery_verify(); // Verify if there are indeed 2 followers $t = $this->getTest(); $criteria = new Criteria(FollowerPeer::TABLE_NAME); $this->getTest()->is(2, count(FollowerPeer::doSelect($criteria)), 'Test for created followers'); }