diff --git a/composer.json b/composer.json index e4d47500..0db05e4b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "pugx/badge-poser", - "description": "add badges on your readme, such as downloads number or latest version.", + "description": "Poser, add badges on your readme, such as downloads number or latest version.", "keywords": ["composer", "packagist", "badge", "pin"], "homepage": "https://github.com/PUGX", "type": "symfony-project", diff --git a/src/PUGX/BadgeBundle/Tests/Controller/BadgeControllerTest.php b/src/PUGX/BadgeBundle/Tests/Controller/BadgeControllerTest.php index 2d53756b..3bab95a2 100644 --- a/src/PUGX/BadgeBundle/Tests/Controller/BadgeControllerTest.php +++ b/src/PUGX/BadgeBundle/Tests/Controller/BadgeControllerTest.php @@ -12,9 +12,9 @@ namespace PUGX\BadgeBundle\Tests\Controller; use Packagist\Api\Client; -use PUGX\StatsBundle\Test\StatsFunctionalTest; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -class BadgeControllerTest extends StatsFunctionalTest +class BadgeControllerTest extends WebTestCase { protected $packagistClient; @@ -44,8 +44,6 @@ public function testDownloadsAction() static::$kernel->getContainer()->set('packagist_client', $this->packagistClient); $crawler = $client->request('GET', '/pugx/badge-poser/d/total.png'); $this->assertTrue($client->getResponse()->isSuccessful()); - - $this->checkStatsCalls($client, 'pugx/badge-poser', 'downloadsAction'); } public function testLatestStableAction() @@ -55,8 +53,6 @@ public function testLatestStableAction() $crawler = $client->request('GET', '/pugx/badge-poser/version.png'); $this->assertTrue($client->getResponse()->isSuccessful()); - - $this->checkStatsCalls($client, 'pugx/badge-poser', 'versionAction'); } public function testLatestUnstableAction() @@ -68,8 +64,6 @@ public function testLatestUnstableAction() $this->assertTrue($client->getResponse()->isSuccessful()); $response = $client->getResponse(); $this->assertRegExp('/s-maxage=3600/', $response->headers->get('Cache-Control')); - - $this->checkStatsCalls($client, 'pugx/badge-poser', 'versionAction'); } public function testIfPackageDoesntExist() diff --git a/src/PUGX/BadgeBundle/Tests/Controller/PageControllerTest.php b/src/PUGX/BadgeBundle/Tests/Controller/PageControllerTest.php index 45dd1555..6842d551 100644 --- a/src/PUGX/BadgeBundle/Tests/Controller/PageControllerTest.php +++ b/src/PUGX/BadgeBundle/Tests/Controller/PageControllerTest.php @@ -11,9 +11,9 @@ namespace PUGX\BadgeBundle\Tests\Controller; -use PUGX\StatsBundle\Test\StatsFunctionalTest; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -class PageControllerTest extends StatsFunctionalTest +class PageControllerTest extends WebTestCase { /** * @dataProvider provider @@ -32,8 +32,6 @@ public function testHomeAction($path) $this->assertEquals(1, $crawler->filter('#container h4:contains("Monthly downloads")')->count()); $this->assertEquals(1, $crawler->filter('#container h4:contains("Latest Stable Version")')->count()); $this->assertEquals(1, $crawler->filter('#container h4:contains("Latest Unstable Version")')->count()); - - $this->checkStatsAreNotIncremented($client); } public function provider() diff --git a/src/PUGX/StatsBundle/Tests/FunctionalControllerTest.php b/src/PUGX/StatsBundle/Tests/FunctionalControllerTest.php new file mode 100644 index 00000000..88e7c652 --- /dev/null +++ b/src/PUGX/StatsBundle/Tests/FunctionalControllerTest.php @@ -0,0 +1,90 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PUGX\BadgeBundle\Tests\Controller; + +use PUGX\StatsBundle\Test\StatsFunctionalTest; +use Packagist\Api\Client; + +class FunctionalControllerTest extends StatsFunctionalTest +{ + protected $packagistClient; + + // this setUp fake the request/response, if you comment this function the test'd run only with internet connection + public function setUp() + { + // see the config_test.yml, there's different parameters and services. + $data = '{"package":{"name":"pugx\/badge-poser","description":"add badges on your readme, such as downloads number or latest version.","time":"2013-05-24T14:45:06+00:00","maintainers":[{"name":"liuggio","email":"liuggio@gmail.com"}],"versions":{"dev-master":{"name":"pugx\/badge-poser","description":"add badges on your readme, such as downloads number or latest version.","keywords":[],"homepage":"","version":"dev-master","version_normalized":"9999999-dev","license":[],"authors":[],"source":{"type":"git","url":"https:\/\/github.com\/PUGX\/badge-poser.git","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e"},"dist":{"type":"zip","url":"https:\/\/api.github.com\/repos\/PUGX\/badge-poser\/zipball\/024df1d420cd715aea3400bfea9b87ed0f3bb47e","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e","shasum":""},"type":"library","time":"2013-05-24T19:19:25+00:00","autoload":{"psr-0":{"":"src\/"}},"extra":{"symfony-app-dir":"app","symfony-web-dir":"web","branch-alias":{"dev-master":"0.1-dev"}},"require":{"php":">=5.3.3","symfony\/symfony":"2.2.*","doctrine\/orm":">=2.2,<3.0,>=2.2.3","doctrine\/doctrine-bundle":"1.2.*","twig\/extensions":"1.0.*","symfony\/assetic-bundle":"2.1.*","symfony\/swiftmailer-bundle":"2.2.*","symfony\/monolog-bundle":"2.2.*","sensio\/distribution-bundle":"2.2.*","sensio\/framework-extra-bundle":"2.2.*","sensio\/generator-bundle":"2.2.*","jms\/security-extra-bundle":"1.4.*","jms\/di-extra-bundle":"1.3.*","knplabs\/packagist-api":"dev-master"},"require-dev":{"guzzle\/plugin-mock":"*"}},"dev-develop":{"name":"pugx\/badge-poser","description":"add badges on your readme, such as downloads number or latest version.","keywords":[],"homepage":"","version":"dev-develop","version_normalized":"dev-develop","license":[],"authors":[],"source":{"type":"git","url":"https:\/\/github.com\/PUGX\/badge-poser.git","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e"},"dist":{"type":"zip","url":"https:\/\/api.github.com\/repos\/PUGX\/badge-poser\/zipball\/024df1d420cd715aea3400bfea9b87ed0f3bb47e","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e","shasum":""},"type":"library","time":"2013-05-24T19:19:25+00:00","autoload":{"psr-0":{"":"src\/"}},"extra":{"symfony-app-dir":"app","symfony-web-dir":"web","branch-alias":{"dev-master":"0.1-dev"}},"require":{"php":">=5.3.3","symfony\/symfony":"2.2.*","doctrine\/orm":">=2.2,<3.0,>=2.2.3","doctrine\/doctrine-bundle":"1.2.*","twig\/extensions":"1.0.*","symfony\/assetic-bundle":"2.1.*","symfony\/swiftmailer-bundle":"2.2.*","symfony\/monolog-bundle":"2.2.*","sensio\/distribution-bundle":"2.2.*","sensio\/framework-extra-bundle":"2.2.*","sensio\/generator-bundle":"2.2.*","jms\/security-extra-bundle":"1.4.*","jms\/di-extra-bundle":"1.3.*","knplabs\/packagist-api":"dev-master"},"require-dev":{"guzzle\/plugin-mock":"*"}}},"type":"library","repository":"https:\/\/github.com\/PUGX\/badge-poser","downloads":{"total":99,"monthly":12,"daily":9},"favers":9}}'; + $this->packagistClient = $this->createPackagistClient($data, 200); + } + + private function createPackagistClient($data, $status = 200) + { + $packagistResponse = new \Guzzle\Http\Message\Response($status); + $packagistResponse->setBody($data); + $plugin = new \Guzzle\Plugin\Mock\MockPlugin(); + $plugin->addResponse($packagistResponse); + $clientHttp = new \Guzzle\Http\Client(); + $clientHttp->addSubscriber($plugin); + + return new Client($clientHttp); + } + + public function testOnDownloadsActionStatisticShouldBeCreated() + { + $client = static::createClient(); + static::$kernel->getContainer()->set('packagist_client', $this->packagistClient); + $client->request('GET', '/pugx/badge-poser/d/total.png'); + + $this->checkStatsCalls($client, 'pugx/badge-poser', 'downloadsAction'); + } + + public function testOnLatestStableActionStatisticShouldBeCreated() + { + $client = static::createClient(); + static::$kernel->getContainer()->set('packagist_client', $this->packagistClient); + $client->request('GET', '/pugx/badge-poser/version.png'); + $this->checkStatsCalls($client, 'pugx/badge-poser', 'versionAction'); + } + + public function testOnLatestUnstableActionStatisticShouldBeCreated() + { + $client = static::createClient(); + static::$kernel->getContainer()->set('packagist_client', $this->packagistClient); + $client->request('GET', '/pugx/badge-poser/v/unstable.png'); + + $this->assertTrue($client->getResponse()->isSuccessful()); + + $this->checkStatsCalls($client, 'pugx/badge-poser', 'versionAction'); + } + + /** + * @dataProvider provider + */ + public function testOnHomeActionStatisticShouldNotBeCreated($path) + { + $client = static::createClient(); + $client->enableProfiler(); + + $client->request('GET', $path); + $this->assertTrue($client->getResponse()->isSuccessful()); + + $this->checkStatsAreNotIncremented($client); + } + + public function provider() + { + return array( + array('/'), + array('/show/pugx/badge-poser') + ); + } +}