Skip to content

Commit

Permalink
TrendingBundleTwitterer now depends on HWIOAuthBundle resource ow…
Browse files Browse the repository at this point in the history
…ner, not on additional `InoriTwitterApp` and related. Funtionality of `BundleActivity` was merged into `BundleUtilsExtension`
  • Loading branch information
stloyd committed Sep 6, 2012
1 parent 59443d7 commit 3852a60
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 209 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
* 2012-08-20
* BC: Bundle entity property symfonyVersion string turned into symfonyVersions array
* `Travis` now depends on `Buzz`
* `Goutte` was removed, and finders were refactored to use `Buzz`
* `TrendingBundleTwitterer` now depends on `HWIOAuthBundle` resource owner,
not on additional `InoriTwitterApp` and related
* Funtionality of `BundleActivity` was merged into `BundleUtilsExtension`
* Bundle entity property `$symfonyVersion` string turned into `$symfonyVersions` array

* 2012-08-15
* BundleActivityTwigExtension renamed to BundleUtilsExtension
* `BundleActivityTwigExtension` renamed to `BundleUtilsExtension`
1 change: 0 additions & 1 deletion app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function registerBundles()
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
new Inori\TwitterAppBundle\InoriTwitterAppBundle(),
new Igorw\FileServeBundle\IgorwFileServeBundle(),

// register your bundles here
Expand Down
14 changes: 6 additions & 8 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ doctrine:
entity_managers:
default:
mappings:
KnpBundlesBundle: ~

inori_twitter_app:
file: %kernel.root_dir%/../vendor/twitter/oauth/twitteroauth/twitteroauth.php
consumer_key: %knp_bundles.twitter.consumer_key%
consumer_secret: %knp_bundles.twitter.consumer_secret%
oauth_token: %knp_bundles.twitter.oauth_token%
oauth_token_secret: %knp_bundles.twitter.oauth_token_secret%
KnpBundlesBundle: ~

knp_zend_cache:
templates:
Expand Down Expand Up @@ -127,4 +120,9 @@ hwi_oauth:
scope: "SCOPE_EMAIL SCOPE_PUBLIC"
user_response_class: Knp\Bundle\KnpBundlesBundle\Security\OAuth\Response\SensioConnectUserResponse

twitter:
type: twitter
client_id: %knp_bundles.twitter.consumer_key%
client_secret: %knp_bundles.twitter.consumer_secret%

firewall_name: secured_area
18 changes: 0 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"nelmio/solarium-bundle": "dev-master",
"igorw/file-serve-bundle": "dev-master",

"inori/twitter-app-bundle": "dev-master",

"videlalvaro/php-amqplib": "dev-master",
"oldsound/rabbitmq-bundle": "dev-master",

Expand All @@ -47,22 +45,6 @@
"behat/common-contexts": "dev-master"
},
"repositories": [
{
"type": "package",
"package": {
"name": "abraham/twitteroauth",
"version": "dev-master",
"dist": {
"url": "https://github.com/abraham/twitteroauth/zipball/master",
"type": "zip"
},
"source": {
"url": "git://github.com/abraham/twitteroauth.git",
"type": "git",
"reference": "master"
}
}
},
{
"type": "package",
"package": {
Expand Down
43 changes: 0 additions & 43 deletions src/Knp/Bundle/KnpBundlesBundle/Activity/BundleActivity.php

This file was deleted.

11 changes: 5 additions & 6 deletions src/Knp/Bundle/KnpBundlesBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ services:

knp_bundles.trending_bundle_twitterer:
class: %knp_bundles.trending_bundle_twitterer.class%
arguments:
- @knp_bundles.entity_manager
- %knp_bundles.trending_bundle_twitterer.template%
- @twitter_app
- %knp_bundles.trending_bundle_twitterer.idle_period%
calls:
- [ setEntityManager, [@knp_bundles.entity_manager] ]
- [ setTwitterParams, [%knp_bundles.trending_bundle_twitterer.template%, %knp_bundles.trending_bundle_twitterer.idle_period%, %knp_bundles.twitter.oauth_token%, %knp_bundles.twitter.oauth_token_secret%] ]

knp_bundles.output:
public: false
Expand All @@ -61,7 +59,8 @@ services:
class: %knp_bundles.travis.class%
arguments:
- @knp_bundles.output
- @buzz
calls:
- [ setBrowser, [@buzz]]

knp_bundles.github_client:
public: false
Expand Down
29 changes: 29 additions & 0 deletions src/Knp/Bundle/KnpBundlesBundle/Tests/Finder/FinderTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Knp\Bundle\KnpBundlesBundle\Tests\Finder;

abstract class FinderTestCase
{
protected function getBrowserMock($node, $url)
{
$revert = libxml_use_internal_errors(true);

$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->loadHTML($node);

libxml_use_internal_errors($revert);

$response = $this->getMock('Buzz\Message\Response');
$response->expects($this->any())
->method('toDomDocument')
->will($this->returnValue($dom));

$browser = $this->getMock('Buzz\Browser');
$browser->expects($this->any())
->method('get')
->with($url)
->will($this->returnValue($response));

return $browser;
}
}
17 changes: 2 additions & 15 deletions src/Knp/Bundle/KnpBundlesBundle/Tests/Finder/GithubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,17 @@

namespace Knp\Bundle\KnpBundlesBundle\Tests\Finder;

use Symfony\Component\DomCrawler\Crawler;
use Knp\Bundle\KnpBundlesBundle\Finder\Github;

class GithubTest extends \PHPUnit_Framework_TestCase
class GithubTest extends FinderTestCase
{
/**
* @dataProvider getExtractPageUrlsData
* @test
*/
public function shouldExtractPageUrlsFromGithubHtml($node, $expected)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->add($node);

$response = $this->getMock('Buzz\Message\Response');
$response->expects($this->any())
->method('toDomDocument')
->will($this->returnValue($dom));

$browser = $this->getMock('Buzz\Browser');
$browser->expects($this->any())
->method('get')
->with('https://github.com/search?q=Symfony2&type=Repositories&language=PHP&start_value=3')
->will($this->returnValue($response));
$browser = $this->getBrowserMock($node, 'https://github.com/search?q=Symfony2&type=Repositories&language=PHP&start_value=3');

$finder = new Github('Symfony2', 3);
$finder->setBrowser($browser);
Expand Down
17 changes: 2 additions & 15 deletions src/Knp/Bundle/KnpBundlesBundle/Tests/Finder/GoogleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,17 @@

namespace Knp\Bundle\KnpBundlesBundle\Tests\Finder;

use Symfony\Component\DomCrawler\Crawler;
use Knp\Bundle\KnpBundlesBundle\Finder\Google;

class GoogleTest extends \PHPUnit_Framework_TestCase
class GoogleTest extends FinderTestCase
{
/**
* @dataProvider getExtractPageUrlsData
* @test
*/
public function shouldExtractPageUrlsFromGoogleHtml($node, $expected)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->add($node);

$response = $this->getMock('Buzz\Message\Response');
$response->expects($this->any())
->method('toDomDocument')
->will($this->returnValue($dom));

$browser = $this->getMock('Buzz\Browser');
$browser->expects($this->any())
->method('get')
->with('http://www.google.com/search?q=Symfony2&start=20')
->will($this->returnValue($response));
$browser = $this->getBrowserMock($node, 'http://www.google.com/search?q=Symfony2&start=20');

$finder = new Google('Symfony2', 3);
$finder->setBrowser($browser);
Expand Down
72 changes: 47 additions & 25 deletions src/Knp/Bundle/KnpBundlesBundle/Tests/Travis/TravisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ class RepoTest extends \PHPUnit_Framework_TestCase
*/
public function shouldUpdateBundleForSuccessfulBuildStatus()
{
$travis = $this->getTravis();
$travis->expects($this->once())
->method('getTravisData')
->with($this->equalTo('KnpLabs/KnpBundles'))
->will($this->returnValue(array('last_build_status' => 0)));
$travis = $this->getTravis(array('last_build_status' => 0), 'KnpLabs/KnpBundles');

$bundle = $this->getMock('Knp\Bundle\KnpBundlesBundle\Entity\Bundle', array('setTravisCiBuildStatus'));
$bundle->expects($this->once())
Expand All @@ -39,11 +35,7 @@ public function shouldUpdateBundleForSuccessfulBuildStatus()
*/
public function shouldUpdateBundleForFailureBuildStatus()
{
$travis = $this->getTravis();
$travis->expects($this->once())
->method('getTravisData')
->with($this->equalTo('KnpLabs/KnpBundles'))
->will($this->returnValue(array('last_build_status' => 1)));
$travis = $this->getTravis(array('last_build_status' => 1), 'KnpLabs/KnpBundles');

$bundle = $this->getMock('Knp\Bundle\KnpBundlesBundle\Entity\Bundle', array('setTravisCiBuildStatus'));
$bundle->expects($this->once())
Expand All @@ -61,10 +53,7 @@ public function shouldUpdateBundleForFailureBuildStatus()
*/
public function shouldUpdateBundleForUndefinedBuildStatus()
{
$travis = $this->getTravis();
$travis->expects($this->once())
->method('getTravisData')
->will($this->returnValue(array('last_build_status' => 777)));
$travis = $this->getTravis(array('last_build_status' => 777));

$bundle = $this->getMock('Knp\Bundle\KnpBundlesBundle\Entity\Bundle', array('setTravisCiBuildStatus'));
$bundle->expects($this->once())
Expand All @@ -82,10 +71,7 @@ public function shouldUpdateBundleForUndefinedBuildStatus()
*/
public function shouldUpdateBundleWhenCannotFetchStatus()
{
$travis = $this->getTravis();
$travis->expects($this->once())
->method('getTravisData')
->will($this->returnValue(array()));
$travis = $this->getTravis(array(), false);

$bundle = $this->getMock('Knp\Bundle\KnpBundlesBundle\Entity\Bundle', array('setTravisCiBuildStatus'));
$bundle->expects($this->once())
Expand All @@ -98,14 +84,50 @@ public function shouldUpdateBundleWhenCannotFetchStatus()
$travis->update($bundle);
}

private function getTravis()
private function getTravis($return = array(), $with = null)
{
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$browser = $this->getMock('Buzz\Browser');
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');

$travis = new Travis($output);
$travis->setBrowser($this->getBrowserMock($return, $with));

return $travis;
}

return $this->getMock('Knp\Bundle\KnpBundlesBundle\Travis\Travis',
array('getTravisData'),
array($output, $browser)
);
private function getBrowserMock($return = array(), $with = null)
{
$client = $this->getMockForAbstractClass('Buzz\Client\Curl');
$client->expects($this->any())
->method('setVerifyPeer')
->with($this->equalTo(false));
$client->expects($this->any())
->method('setTimeout')
->with($this->equalTo(30));

$response = $this->getMock('Buzz\Message\Response');
$response->expects($this->any())
->method('getContent')
->will($this->returnValue(false !== $with ? json_encode($return) : null));

$browser = $this->getMock('Buzz\Browser');
$browser->expects($this->any())
->method('getClient')
->will($this->returnValue($client));
$browser->expects($this->any())
->method('setClient')
->with($client);

if (empty($with)) {
$browser->expects($this->any())
->method('get')
->will($this->returnValue($response));
} else {
$browser->expects($this->any())
->method('get')
->with($this->equalTo('http://travis-ci.org/'.$with.'.json'))
->will($this->returnValue($response));
}

return $browser;
}
}
Loading

0 comments on commit 3852a60

Please sign in to comment.