]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add tests on TagAllCommand
authorJeremy Benoist <jeremy.benoist@gmail.com>
Thu, 21 Jan 2016 15:36:17 +0000 (16:36 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Thu, 21 Jan 2016 15:36:17 +0000 (16:36 +0100)
Some simple tests

src/Wallabag/CoreBundle/Command/TagAllCommand.php
src/Wallabag/CoreBundle/Tests/Command/TagAllCommandTest.php [new file with mode: 0644]

index 2cf3f80842e5fc1bc27b14fcd336eaecc5cf5c69..db1a9ab79d3b28d361e7498b156a57dcc4f4e6b7 100644 (file)
@@ -28,7 +28,7 @@ class TagAllCommand extends ContainerAwareCommand
         try {
             $user = $this->getUser($input->getArgument('username'));
         } catch (NoResultException $e) {
-            $output->writeln(sprintf('<error>User %s not found.</error>', $input->getArgument('username')));
+            $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username')));
 
             return 1;
         }
diff --git a/src/Wallabag/CoreBundle/Tests/Command/TagAllCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/TagAllCommandTest.php
new file mode 100644 (file)
index 0000000..653c1a9
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+namespace Wallabag\CoreBundle\Tests\Command;
+
+use Symfony\Bundle\FrameworkBundle\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+use Wallabag\CoreBundle\Command\TagAllCommand;
+use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
+
+class TagAllCommandTest extends WallabagCoreTestCase
+{
+    /**
+     * @expectedException Symfony\Component\Console\Exception\RuntimeException
+     * @expectedExceptionMessage Not enough arguments (missing: "username")
+     */
+    public function testRunTagAllCommandWithoutUsername()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new TagAllCommand());
+
+        $command = $application->find('wallabag:tag:all');
+
+        $tester = new CommandTester($command);
+        $tester->execute(array(
+            'command' => $command->getName(),
+        ));
+    }
+
+    public function testRunTagAllCommandWithBadUsername()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new TagAllCommand());
+
+        $command = $application->find('wallabag:tag:all');
+
+        $tester = new CommandTester($command);
+        $tester->execute(array(
+            'command' => $command->getName(),
+            'username' => 'unknown',
+        ));
+
+        $this->assertContains('User "unknown" not found', $tester->getDisplay());
+    }
+
+    public function testRunTagAllCommand()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new TagAllCommand());
+
+        $command = $application->find('wallabag:tag:all');
+
+        $tester = new CommandTester($command);
+        $tester->execute(array(
+            'command' => $command->getName(),
+            'username' => 'admin',
+        ));
+
+        $this->assertContains('Tagging entries for user « admin »... Done', $tester->getDisplay());
+    }
+}