From 759db2c70199ac7c9cdc3e0e870d50612de17561 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 6 Apr 2012 13:05:19 +1000 Subject: [PATCH 01/14] Skip tests when the ORM isn't installed --- Tests/Entity/CommentManagerTest.php | 4 ++++ Tests/Entity/ThreadManagerTest.php | 4 ++++ Tests/Entity/VoteManagerTest.php | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/Tests/Entity/CommentManagerTest.php b/Tests/Entity/CommentManagerTest.php index 5616f120e..b7ae247be 100644 --- a/Tests/Entity/CommentManagerTest.php +++ b/Tests/Entity/CommentManagerTest.php @@ -29,6 +29,10 @@ class CommentManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { + if (!class_exists('Doctrine\\ORM\\EntityManager')) { + $this->markTestSkipped('Doctrine ORM not installed'); + } + $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() diff --git a/Tests/Entity/ThreadManagerTest.php b/Tests/Entity/ThreadManagerTest.php index 59edb06a3..032ba8405 100644 --- a/Tests/Entity/ThreadManagerTest.php +++ b/Tests/Entity/ThreadManagerTest.php @@ -28,6 +28,10 @@ class ThreadManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { + if (!class_exists('Doctrine\\ORM\\EntityManager')) { + $this->markTestSkipped('Doctrine ORM not installed'); + } + $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() diff --git a/Tests/Entity/VoteManagerTest.php b/Tests/Entity/VoteManagerTest.php index cd36b6c41..4cbc60c0d 100644 --- a/Tests/Entity/VoteManagerTest.php +++ b/Tests/Entity/VoteManagerTest.php @@ -28,6 +28,10 @@ class VoteManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { + if (!class_exists('Doctrine\\ORM\\EntityManager')) { + $this->markTestSkipped('Doctrine ORM not installed'); + } + $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() From 30d1b6eee05df0bfe849f835eb9f9a8417178c5f Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 6 Apr 2012 13:06:24 +1000 Subject: [PATCH 02/14] Added aksimet-bundle suggestion for the test suite --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f1532985c..a4aa0ef81 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ }, "suggest": { "doctrine/orm": "2.2.*", - "friendsofsymfony/user-bundle": "*" + "friendsofsymfony/user-bundle": "*", + "ornicar/akismet-bundle": "*" }, "autoload": { "psr-0": { "FOS\\CommentBundle": "" } From 4b8867d5ddf81658cb571d725d2c8e4e3cd5bd4c Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 6 Apr 2012 13:07:38 +1000 Subject: [PATCH 03/14] Added composer.phar to ignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6730d3983..c2f20c621 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ phpunit.xml Tests/autoload.php - +composer.phar vendor/* From b3bc1e31f75b4e07eb663ee3513c68b3de466014 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 6 Apr 2012 16:52:32 +1000 Subject: [PATCH 04/14] Added Behat and Mink --- Features/Context/FeatureContext.php | 65 ++++++++++++++++++++++ Tests/Functional/SymfonyDriver.php | 19 +++++++ Tests/Functional/app/Basic/bundles.php | 28 ++++++---- Tests/Functional/app/Behat/bundles.php | 32 +++++++++++ Tests/Functional/app/Behat/config.yml | 20 +++++++ Tests/Functional/app/Behat/nginx.conf.dist | 50 +++++++++++++++++ Tests/Functional/app/Behat/routing.yml | 7 +++ Tests/Functional/app/console | 14 +++++ Tests/Functional/web/app.php | 21 +++++++ composer.json | 4 +- 10 files changed, 247 insertions(+), 13 deletions(-) create mode 100644 Features/Context/FeatureContext.php create mode 100644 Tests/Functional/SymfonyDriver.php create mode 100644 Tests/Functional/app/Behat/bundles.php create mode 100644 Tests/Functional/app/Behat/config.yml create mode 100644 Tests/Functional/app/Behat/nginx.conf.dist create mode 100644 Tests/Functional/app/Behat/routing.yml create mode 100644 Tests/Functional/app/console create mode 100644 Tests/Functional/web/app.php diff --git a/Features/Context/FeatureContext.php b/Features/Context/FeatureContext.php new file mode 100644 index 000000000..9fbc40cfc --- /dev/null +++ b/Features/Context/FeatureContext.php @@ -0,0 +1,65 @@ +getThreadManager()->createThread($id); + $thread->setPermalink($link); + + $this->getThreadManager()->saveThread($thread); + } + + + /** + * @When /^I go to "([^"]*)"$/ + */ + public function iGoTo($url) + { + $this->visit($url); + } + + /** + * @When /^I go to "([^"]*)" as "([^"]*)" identified by "([^"]*)"$/ + */ + public function iGoToAsIdentifiedBy($url) + { + throw new PendingException; + } + + /** + * @Then /^I should see a thread with the identifier of "([^"]*)"$/ + */ + public function iShouldSeeAThreadWithTheIdentifierOf($argument1) + { + throw new PendingException(); + } + + /** + * @Then /^I should see a thread with the identifier to "([^"]*)"$/ + */ + public function iShouldSeeAThreadWithTheIdentifierTo($argument1) + { + throw new PendingException(); + } + + /** + * @return \FOS\CommentBundle\Model\ThreadManagerInterface + */ + private function getThreadManager() + { + return $this->getContainer()->get('fos_comment.manager.thread'); + } +} \ No newline at end of file diff --git a/Tests/Functional/SymfonyDriver.php b/Tests/Functional/SymfonyDriver.php new file mode 100644 index 000000000..588b402df --- /dev/null +++ b/Tests/Functional/SymfonyDriver.php @@ -0,0 +1,19 @@ +getKernel()); + $kernel = new $class('Behat', 'config.yml', $client->getKernel()->getEnvironment(), $client->getKernel()->isDebug()); + $kernel->boot(); + + $this->client = $kernel->getContainer()->get('test.client'); + $this->client->followRedirects(true); + } +} \ No newline at end of file diff --git a/Tests/Functional/app/Basic/bundles.php b/Tests/Functional/app/Basic/bundles.php index af465f775..0a7d02eab 100644 --- a/Tests/Functional/app/Basic/bundles.php +++ b/Tests/Functional/app/Basic/bundles.php @@ -10,16 +10,20 @@ */ return array( - new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), - new \Symfony\Bundle\TwigBundle\TwigBundle(), - new \Symfony\Bundle\SecurityBundle\SecurityBundle(), - new \Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), - new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), - new \Symfony\Bundle\AsseticBundle\AsseticBundle(), - - new \FOS\RestBundle\FOSRestBundle(), - new \FOS\CommentBundle\FOSCommentBundle(), - new \JMS\SerializerBundle\JMSSerializerBundle($this), - - new \FOS\CommentBundle\Tests\Functional\Bundle\CommentBundle\CommentBundle(), + new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + + new Symfony\Bundle\AsseticBundle\AsseticBundle(), + new Symfony\Bundle\SecurityBundle\SecurityBundle(), + new Symfony\Bundle\TwigBundle\TwigBundle(), + + new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + + new FOS\RestBundle\FOSRestBundle(), + new FOS\CommentBundle\FOSCommentBundle(), + + new JMS\SerializerBundle\JMSSerializerBundle($this), + + new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + + new FOS\CommentBundle\Tests\Functional\Bundle\CommentBundle\CommentBundle(), ); diff --git a/Tests/Functional/app/Behat/bundles.php b/Tests/Functional/app/Behat/bundles.php new file mode 100644 index 000000000..f1e3f40f1 --- /dev/null +++ b/Tests/Functional/app/Behat/bundles.php @@ -0,0 +1,32 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +return array( + new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + + new Symfony\Bundle\AsseticBundle\AsseticBundle(), + new Symfony\Bundle\SecurityBundle\SecurityBundle(), + new Symfony\Bundle\TwigBundle\TwigBundle(), + + new Behat\BehatBundle\BehatBundle(), + new Behat\MinkBundle\MinkBundle(), + + new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + + new FOS\RestBundle\FOSRestBundle(), + new FOS\CommentBundle\FOSCommentBundle(), + + new JMS\SerializerBundle\JMSSerializerBundle($this), + + new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + + new FOS\CommentBundle\Tests\Functional\Bundle\CommentBundle\CommentBundle(), +); diff --git a/Tests/Functional/app/Behat/config.yml b/Tests/Functional/app/Behat/config.yml new file mode 100644 index 000000000..b09268bac --- /dev/null +++ b/Tests/Functional/app/Behat/config.yml @@ -0,0 +1,20 @@ +imports: + - { resource: ./../config/default.yml } + +fos_comment: + db_driver: orm + class: + model: + comment: FOS\CommentBundle\Tests\Functional\Bundle\CommentBundle\Entity\Comment + thread: FOS\CommentBundle\Tests\Functional\Bundle\CommentBundle\Entity\Thread + vote: FOS\CommentBundle\Tests\Functional\Bundle\CommentBundle\Entity\Vote + +mink: + base_url: http://127.0.0.1:8080/ + default_session: zombie + javascript_session: zombie + zombie: ~ + show_cmd: open %s + +parameters: + behat.mink.driver.symfony.class: FOS\CommentBundle\Tests\Functional\SymfonyDriver \ No newline at end of file diff --git a/Tests/Functional/app/Behat/nginx.conf.dist b/Tests/Functional/app/Behat/nginx.conf.dist new file mode 100644 index 000000000..74ae556f9 --- /dev/null +++ b/Tests/Functional/app/Behat/nginx.conf.dist @@ -0,0 +1,50 @@ +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + + keepalive_timeout 65; + + fastcgi_connect_timeout 60; + fastcgi_send_timeout 180; + fastcgi_read_timeout 180; + fastcgi_buffer_size 32k; + fastcgi_buffers 16 16k; + fastcgi_intercept_errors on; + + upstream php { + server 127.0.0.1:9000; + } + + access_log logs/access.log; + error_log logs/error.log debug; + + server { + listen 8080 default_server; + server_name .localhost; + + charset utf-8; + + root Functional/web; + + location / { + index app.php; + try_files $uri @rewriteapp; + } + + location @rewriteapp { + rewrite ^(.*)$ /app.php/$1 last; + } + + location ~^/app\.php(/|$) { + fastcgi_split_path_info ^(.+\.php)(.*)$; + fastcgi_pass php; + include /usr/local/etc/nginx/fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param HTTPS off; + fastcgi_param ENVIRONMENT 'test'; + } + } +} diff --git a/Tests/Functional/app/Behat/routing.yml b/Tests/Functional/app/Behat/routing.yml new file mode 100644 index 000000000..1b999730c --- /dev/null +++ b/Tests/Functional/app/Behat/routing.yml @@ -0,0 +1,7 @@ +_commenttest: + resource: "@CommentBundle/Resources/config/routing.yml" + +FOSComentBundle: + resource: "@FOSCommentBundle/Resources/config/routing.yml" + type: rest + prefix: /comment_api \ No newline at end of file diff --git a/Tests/Functional/app/console b/Tests/Functional/app/console new file mode 100644 index 000000000..801e148c5 --- /dev/null +++ b/Tests/Functional/app/console @@ -0,0 +1,14 @@ +#!/usr/bin/env php +run(); diff --git a/Tests/Functional/web/app.php b/Tests/Functional/web/app.php new file mode 100644 index 000000000..de0e87299 --- /dev/null +++ b/Tests/Functional/web/app.php @@ -0,0 +1,21 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +require_once __DIR__ . '/../app/AppKernel.php'; + +use Symfony\Component\HttpFoundation\Request; +use FOS\CommentBundle\Tests\Functional\AppKernel; + +$kernel = new AppKernel('Behat', 'config.yml', 'test', true); +$request = Request::createFromGlobals(); +$response = $kernel->handle($request); +$response->send(); +$kernel->terminate($request, $response); diff --git a/composer.json b/composer.json index a4aa0ef81..0fcd671cb 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,9 @@ "suggest": { "doctrine/orm": "2.2.*", "friendsofsymfony/user-bundle": "*", - "ornicar/akismet-bundle": "*" + "ornicar/akismet-bundle": "*", + "behat/behat-bundle": "*", + "behat/mink-bundle": "*" }, "autoload": { "psr-0": { "FOS\\CommentBundle": "" } From 51e2ad524fa49001902880bb016f05f35c461c87 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 6 Apr 2012 16:52:46 +1000 Subject: [PATCH 05/14] Moved configuration of the Sensio view listener to default.yml --- Tests/Functional/app/Basic/config.yml | 3 --- Tests/Functional/app/config/default.yml | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Functional/app/Basic/config.yml b/Tests/Functional/app/Basic/config.yml index 93db49cd5..5ba497c49 100644 --- a/Tests/Functional/app/Basic/config.yml +++ b/Tests/Functional/app/Basic/config.yml @@ -8,6 +8,3 @@ fos_comment: comment: FOS\CommentBundle\Tests\Functional\Bundle\CommentBundle\Entity\Comment thread: FOS\CommentBundle\Tests\Functional\Bundle\CommentBundle\Entity\Thread vote: FOS\CommentBundle\Tests\Functional\Bundle\CommentBundle\Entity\Vote - -sensio_framework_extra: - view: { annotations: false } diff --git a/Tests/Functional/app/config/default.yml b/Tests/Functional/app/config/default.yml index 3d3597ef7..76adb8ffc 100644 --- a/Tests/Functional/app/config/default.yml +++ b/Tests/Functional/app/config/default.yml @@ -48,6 +48,9 @@ security: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] +sensio_framework_extra: + view: { annotations: false } + twig: debug: %kernel.debug% strict_variables: %kernel.debug% From cba0abce9798127aed0c37c7b19d845edbcd257f Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 6 Apr 2012 17:00:06 +1000 Subject: [PATCH 06/14] Allow the ThreadPermalinkListener to skip if the Request scope is not available (CLI) --- EventListener/ThreadPermalinkListener.php | 18 +++++++++++------- Resources/config/events.xml | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/EventListener/ThreadPermalinkListener.php b/EventListener/ThreadPermalinkListener.php index 3d93b9928..0b71d2fd2 100644 --- a/EventListener/ThreadPermalinkListener.php +++ b/EventListener/ThreadPermalinkListener.php @@ -15,8 +15,8 @@ use FOS\CommentBundle\Event\ThreadEvent; use FOS\CommentBundle\Model\ThreadInterface; use FOS\CommentBundle\Model\ThreadManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpFoundation\Request; /** * Responsible for setting a permalink for each new Thread object. @@ -26,18 +26,18 @@ class ThreadPermalinkListener implements EventSubscriberInterface { /** - * @var Request + * @var ContainerInterface */ - protected $request; + protected $container; /** * Constructor. * - * @param Request $request + * @param ContainerInterface $container */ - public function __construct(Request $request) + public function __construct(ContainerInterface $container) { - $this->request = $request; + $this->container = $container; } /** @@ -47,8 +47,12 @@ public function __construct(Request $request) */ public function onThreadCreate(ThreadEvent $event) { + if (!$this->container->isScopeActive('request')) { + return; + } + $thread = $event->getThread(); - $thread->setPermalink($this->request->getUri()); + $thread->setPermalink($this->container->get('request')->getUri()); } static public function getSubscribedEvents() diff --git a/Resources/config/events.xml b/Resources/config/events.xml index 69a543703..c97c9f721 100644 --- a/Resources/config/events.xml +++ b/Resources/config/events.xml @@ -24,8 +24,8 @@ - - + + From 28a11850712bde94f91f2d9aa4d3909a3ab31a91 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 6 Apr 2012 17:47:08 +1000 Subject: [PATCH 07/14] Added initial Behat feature --- Features/Context/FeatureContext.php | 39 ++++------------------------- Features/EmbedThread.feature | 12 +++++++++ Tests/run_behat.sh | 6 +++++ 3 files changed, 23 insertions(+), 34 deletions(-) create mode 100644 Features/EmbedThread.feature create mode 100644 Tests/run_behat.sh diff --git a/Features/Context/FeatureContext.php b/Features/Context/FeatureContext.php index 9fbc40cfc..774328bbd 100644 --- a/Features/Context/FeatureContext.php +++ b/Features/Context/FeatureContext.php @@ -16,45 +16,16 @@ class FeatureContext extends MinkContext */ public function iHaveAThreadIdentifiedBy($id, $link) { - $thread = $this->getThreadManager()->createThread($id); + $thread = $this->getThreadManager()->findThreadById($id); + if (!$thread) { + $thread = $this->getThreadManager()->createThread($id); + } + $thread->setPermalink($link); $this->getThreadManager()->saveThread($thread); } - - /** - * @When /^I go to "([^"]*)"$/ - */ - public function iGoTo($url) - { - $this->visit($url); - } - - /** - * @When /^I go to "([^"]*)" as "([^"]*)" identified by "([^"]*)"$/ - */ - public function iGoToAsIdentifiedBy($url) - { - throw new PendingException; - } - - /** - * @Then /^I should see a thread with the identifier of "([^"]*)"$/ - */ - public function iShouldSeeAThreadWithTheIdentifierOf($argument1) - { - throw new PendingException(); - } - - /** - * @Then /^I should see a thread with the identifier to "([^"]*)"$/ - */ - public function iShouldSeeAThreadWithTheIdentifierTo($argument1) - { - throw new PendingException(); - } - /** * @return \FOS\CommentBundle\Model\ThreadManagerInterface */ diff --git a/Features/EmbedThread.feature b/Features/EmbedThread.feature new file mode 100644 index 000000000..440597f2e --- /dev/null +++ b/Features/EmbedThread.feature @@ -0,0 +1,12 @@ +Feature: Embed a thread on a page + +Background: + Given I have a thread identified by "test" with a link of "test" + +Scenario: Embed a thread inline + When I go to "inline/test" + Then I should see a "#fos_comment_thread[data-thread=test]" element + +Scenario: Embed a thread async + When I go to "async/test" + Then I should see a "#fos_comment_thread[data-thread=test]" element diff --git a/Tests/run_behat.sh b/Tests/run_behat.sh new file mode 100644 index 000000000..8c5cd7d7e --- /dev/null +++ b/Tests/run_behat.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +Functional/app/console assets:install --symlink Functional/web +Functional/app/console doctrine:database:create +Functional/app/console doctrine:schema:create +Functional/app/console behat \ No newline at end of file From 3c9625484cafcf7e533204b3e88c593bdaed28e3 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 6 Apr 2012 17:47:26 +1000 Subject: [PATCH 08/14] Fixed inline test --- .../CommentBundle/Resources/views/Comment/inline.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig index 3b8ba8bc7..77ed7f1ff 100644 --- a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig +++ b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig @@ -1,7 +1,7 @@ {% extends "::base.html.twig" %} {% block body %} -
+
{% include 'FOSCommentBundle:Thread:comments.html.twig' with { 'comments': comments, From 43ea03ff3fac76935aaad6c0f02135ad8d16b49e Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 6 Apr 2012 17:48:31 +1000 Subject: [PATCH 09/14] Added jQuery to tests --- .../Bundle/CommentBundle/Resources/views/Comment/async.html.twig | 1 + .../CommentBundle/Resources/views/Comment/inline.html.twig | 1 + 2 files changed, 2 insertions(+) diff --git a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/async.html.twig b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/async.html.twig index f90de584e..01a9420dc 100644 --- a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/async.html.twig +++ b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/async.html.twig @@ -1,5 +1,6 @@ {% extends "::base.html.twig"%} {% block body %} + {% include 'FOSCommentBundle:Thread:async.html.twig' with { 'id': id } %} {% endblock body %} diff --git a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig index 77ed7f1ff..364d758b3 100644 --- a/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig +++ b/Tests/Functional/Bundle/CommentBundle/Resources/views/Comment/inline.html.twig @@ -14,6 +14,7 @@ {% block javascript %} {% javascripts '@FOSCommentBundle/Resources/assets/js/comments.js' %} +