From 015c7a8359c950f9621b38b11c3973860a981da8 Mon Sep 17 00:00:00 2001
From: Jeremy Benoist <jeremy.benoist@gmail.com>
Date: Sun, 11 Sep 2016 20:24:04 +0200
Subject: Add more tests

And ability to define how many messages can be hanle by the redis worker before stopping (usefull for tests)
---
 .../Command/RedisWorkerCommandTest.php             | 74 ++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php

(limited to 'tests/Wallabag/ImportBundle/Command')

diff --git a/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php
new file mode 100644
index 00000000..74952847
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace Tests\Wallabag\ImportBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+use Wallabag\ImportBundle\Command\RedisWorkerCommand;
+use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
+use M6Web\Component\RedisMock\RedisMockFactory;
+
+class RedisWorkerCommandTest extends WallabagCoreTestCase
+{
+    /**
+     * @expectedException Symfony\Component\Console\Exception\RuntimeException
+     * @expectedExceptionMessage Not enough arguments (missing: "serviceName")
+     */
+    public function testRunRedisWorkerCommandWithoutArguments()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new RedisWorkerCommand());
+
+        $command = $application->find('wallabag:import:redis-worker');
+
+        $tester = new CommandTester($command);
+        $tester->execute([
+            'command' => $command->getName(),
+        ]);
+    }
+
+    /**
+     * @expectedException Symfony\Component\Config\Definition\Exception\Exception
+     * @expectedExceptionMessage No queue or consumer found for service name
+     */
+    public function testRunRedisWorkerCommandWithBadService()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new RedisWorkerCommand());
+
+        $command = $application->find('wallabag:import:redis-worker');
+
+        $tester = new CommandTester($command);
+        $tester->execute([
+            'command' => $command->getName(),
+            'serviceName' => 'YOMONSERVICE',
+        ]);
+    }
+
+    public function testRunRedisWorkerCommand()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new RedisWorkerCommand());
+
+        $factory = new RedisMockFactory();
+        $redisMock = $factory->getAdapter('Predis\Client', true);
+
+        $application->getKernel()->getContainer()->set('wallabag_core.redis.client', $redisMock);
+
+        // put a fake message in the queue so the worker will stop after reading that message
+        // instead of waiting for others
+        $redisMock->lpush('wallabag.import.readability', '{}');
+
+        $command = $application->find('wallabag:import:redis-worker');
+
+        $tester = new CommandTester($command);
+        $tester->execute([
+            'command' => $command->getName(),
+            'serviceName' => 'readability',
+            '--maxIterations' => 1,
+        ]);
+
+        $this->assertContains('Worker started at', $tester->getDisplay());
+        $this->assertContains('Waiting for message', $tester->getDisplay());
+    }
+}
-- 
cgit v1.2.3


From ebf5e5087d2f79ece42a660ee7bddaa3ff3ebe1e Mon Sep 17 00:00:00 2001
From: Jeremy Benoist <jeremy.benoist@gmail.com>
Date: Sun, 11 Sep 2016 21:40:08 +0200
Subject: Add tests on ImportCommand

---
 .../ImportBundle/Command/ImportCommandTest.php     | 86 ++++++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 tests/Wallabag/ImportBundle/Command/ImportCommandTest.php

(limited to 'tests/Wallabag/ImportBundle/Command')

diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
new file mode 100644
index 00000000..eb7fce79
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace Tests\Wallabag\ImportBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Console\Application;
+use Symfony\Component\Console\Tester\CommandTester;
+use Wallabag\ImportBundle\Command\ImportCommand;
+use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
+use M6Web\Component\RedisMock\RedisMockFactory;
+
+class ImportCommandTest extends WallabagCoreTestCase
+{
+    /**
+     * @expectedException Symfony\Component\Console\Exception\RuntimeException
+     * @expectedExceptionMessage Not enough arguments
+     */
+    public function testRunImportCommandWithoutArguments()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new ImportCommand());
+
+        $command = $application->find('wallabag:import');
+
+        $tester = new CommandTester($command);
+        $tester->execute([
+            'command' => $command->getName(),
+        ]);
+    }
+
+    /**
+     * @expectedException Symfony\Component\Config\Definition\Exception\Exception
+     * @expectedExceptionMessage not found
+     */
+    public function testRunImportCommandWithoutFilepath()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new ImportCommand());
+
+        $command = $application->find('wallabag:import');
+
+        $tester = new CommandTester($command);
+        $tester->execute([
+            'command' => $command->getName(),
+            'userId' => 1,
+            'filepath' => 1,
+        ]);
+    }
+
+    /**
+     * @expectedException Symfony\Component\Config\Definition\Exception\Exception
+     * @expectedExceptionMessage User with id
+     */
+    public function testRunImportCommandWithoutUserId()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new ImportCommand());
+
+        $command = $application->find('wallabag:import');
+
+        $tester = new CommandTester($command);
+        $tester->execute([
+            'command' => $command->getName(),
+            'userId' => 0,
+            'filepath' => './',
+        ]);
+    }
+
+    public function testRunImportCommand()
+    {
+        $application = new Application($this->getClient()->getKernel());
+        $application->add(new ImportCommand());
+
+        $command = $application->find('wallabag:import');
+
+        $tester = new CommandTester($command);
+        $tester->execute([
+            'command' => $command->getName(),
+            'userId' => 1,
+            'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
+            '--importer' => 'v2',
+        ]);
+
+        $this->assertContains('imported', $tester->getDisplay());
+        $this->assertContains('already saved', $tester->getDisplay());
+    }
+}
-- 
cgit v1.2.3