From 923abdf4d2c88eb6797350e2b9bb5a4e99abc20f Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandro@alejandrocelaya.com>
Date: Tue, 19 Jul 2016 18:28:21 +0200
Subject: [PATCH] Added first tests for CLI module

---
 .../test/Factory/ApplicationFactoryTest.php   | 60 +++++++++++++++++++
 phpunit.xml.dist                              |  3 +
 2 files changed, 63 insertions(+)
 create mode 100644 module/CLI/test/Factory/ApplicationFactoryTest.php

diff --git a/module/CLI/test/Factory/ApplicationFactoryTest.php b/module/CLI/test/Factory/ApplicationFactoryTest.php
new file mode 100644
index 00000000..1c486e55
--- /dev/null
+++ b/module/CLI/test/Factory/ApplicationFactoryTest.php
@@ -0,0 +1,60 @@
+<?php
+namespace ShlinkioTest\Shlink\CLI\Factory;
+
+use PHPUnit_Framework_TestCase as TestCase;
+use Shlinkio\Shlink\CLI\Factory\ApplicationFactory;
+use Symfony\Component\Console\Application;
+use Symfony\Component\Console\Command\Command;
+use Zend\ServiceManager\ServiceManager;
+
+class ApplicationFactoryTest extends TestCase
+{
+    /**
+     * @var ApplicationFactory
+     */
+    protected $factory;
+
+    public function setUp()
+    {
+        $this->factory = new ApplicationFactory();
+    }
+
+    /**
+     * @test
+     */
+    public function serviceIsCreated()
+    {
+        $instance = $this->factory->__invoke($this->createServiceManager(), '');
+        $this->assertInstanceOf(Application::class, $instance);
+    }
+
+    /**
+     * @test
+     */
+    public function allCommandsWhichAreServicesAreAdded()
+    {
+        $sm = $this->createServiceManager([
+            'commands' => [
+                'foo',
+                'bar',
+                'baz',
+            ],
+        ]);
+        $sm->setService('foo', $this->prophesize(Command::class)->reveal());
+        $sm->setService('baz', $this->prophesize(Command::class)->reveal());
+
+        /** @var Application $instance */
+        $instance = $this->factory->__invoke($sm, '');
+        $this->assertInstanceOf(Application::class, $instance);
+        $this->assertCount(2, $instance->all());
+    }
+
+    protected function createServiceManager($config = [])
+    {
+        return new ServiceManager(['services' => [
+            'config' => [
+                'cli' => $config,
+            ],
+        ]]);
+    }
+}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 2c43e876..65d36865 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -9,6 +9,9 @@
         <testsuite name="Rest">
             <directory>./module/Rest/test</directory>
         </testsuite>
+        <testsuite name="CLI">
+            <directory>./module/CLI/test</directory>
+        </testsuite>
     </testsuites>
 
     <filter>