Skip to content

Commit

Permalink
Add test to verify that either files or git options are set.
Browse files Browse the repository at this point in the history
  • Loading branch information
MontealegreLuis committed Aug 16, 2015
1 parent d206afc commit ac52ed0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
20 changes: 20 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php">

<testsuites>
<testsuite name="Integration tests">
<directory>tests/integration</directory>
</testsuite>
</testsuites>

</phpunit>
10 changes: 3 additions & 7 deletions src/Command/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$git = $input->getOption('git');
}

if ($files && $git) {
if (!empty($files) && $git) {
throw new \Exception('Options `files` and `git` can not used in combination.');
}

if ($files) {
if (!empty($files)) {
$files = explode(',', $files[0]);
}

if (!$files[0]) {
$files = [];
}

if (!$files && !$git) {
if (empty($files) && !$git) {
throw new \Exception('You must set `files` or `git` options.');
}

Expand Down
18 changes: 7 additions & 11 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,25 @@ class Application extends BaseApplication
*/
private $config;

/**
* @return \JMOlivas\Phpqa\Config
*/
public function getConfig()
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
{
return $this->config;
parent::__construct($name, $version);
$this->config = new Config();
}

/**
* {@inheritdoc}
* @return \JMOlivas\Phpqa\Config
*/
public function doRun(InputInterface $input, OutputInterface $output)
public function getConfig()
{
$this->config = new Config();

parent::doRun($input, $output);
return $this->config;
}

/**
* @return string
*/
public function getApplicationDirectory()
{
return __DIR__.'/../../';
return __DIR__ . '/../../';
}
}
26 changes: 26 additions & 0 deletions tests/integration/Command/AnalyzeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace JMOlivas\Phpqa\Command;

use JMOlivas\Phpqa\Console\Application;
use PHPUnit_Framework_TestCase as TestCase;
use Symfony\Component\Console\Tester\CommandTester;

class AnalyzeCommandTest extends TestCase
{
/**
* @test
* @expectedException \Exception
* @expectedExceptionMessage You must set `files` or `git` options.
*/
function it_should_throw_exception_if_neither_files_nor_git_options_are_provided()
{
$application = new Application();
$command = new AnalyzeCommand();
$command->setApplication($application);

$tester = new CommandTester($command);

$tester->execute([]);
}
}

0 comments on commit ac52ed0

Please sign in to comment.