Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for bundle. #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions Tests/features/synchronzie.feature
Original file line number Diff line number Diff line change
Expand Up @@ -205,29 +205,5 @@ Feature: Synchronization of crontab
| json |
| yml |

@not_ready @desc_not_ready
Scenario: Dry run
Given "'crontab' '-l'" command will have 0 as exit code and will return:
"""
*/10 * * * * test

"""
When I run synchronize command with file "./Tests/example_configurations/test.<ext>" and options:
"""
--dry-run
"""
Then The exit code should be 0

@not_ready @desc_not_ready
Scenario: With username
Given "'crontab' '-l'" command will have 0 as exit code and will return:
"""
*/10 * * * * test

"""
When I run synchronize command with file "./Tests/example_configurations/test.<ext>" and options:
"""
--user=kuczek
"""
Then The exit code should be 0

102 changes: 102 additions & 0 deletions Tests/spec/Reader/ReaderFactorySpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* @author Krystian Kuczek <krystian@hexmedia.pl>
* @copyright 2013-2016 Hexmedia.pl
* @license @see LICENSE
*/

namespace spec\Hexmedia\Crontab\Reader;

use Hexmedia\Crontab\Exception\FactoryException;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

/**
* Class ReaderFactorySpec
*
* @package spec\Hexmedia\Crontab
*
* @covers Hexmedia\Crontab\ReaderFactory
*/
class ReaderFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Hexmedia\Crontab\Reader\ReaderFactory');
}

function it_is_not_created_without_type()
{
$this->shouldThrow(
new FactoryException('No type defined, you need to define type to create correct reader.')
)->during('create', array(array()));
}

function it_is_not_created_with_wrong_type()
{
$type = "x";
$this->shouldThrow(new FactoryException(sprintf("Unknown type '%s'", $type)))->during(
'create',
array(array('type' => $type))
);
}

function it_is_able_to_create_standard_reader()
{
$this::create(array('type' => 'yaml', 'file' => 'aa'))->shouldHaveType('Hexmedia\Crontab\Reader\YamlReader');
}

function it_is_not_able_to_create_standard_reader_without_file()
{
$type = "xml";
$this->shouldThrow(new FactoryException(sprintf('File needs to be defined for type %s', $type)))->during(
"create",
array(array("type" => $type))
);
}

function it_is_able_to_create_unix_reader()
{
$this::create(array('type' => 'unix'))->shouldHaveType('Hexmedia\Crontab\Reader\UnixSystemReader');
}

function it_is_allowed_to_add_reader()
{
$this::getReaders()->shouldHaveCount(6);

$this::addReader(
'test',
'dev\Hexmedia\Crontab\Test\TestReader',
function ($configuration, $className) {
return new $className();
}
);

$this::getReaders()->shouldHaveCount(7);
}

function it_is_able_to_create_reader_initialized_with_custom_function()
{
$this::create(array('type' => 'test'))->shouldHaveType('dev\Hexmedia\Crontab\Test\TestReader');
}

function it_is_not_able_to_create_reader_with_non_existing_class()
{
$readerClass = "NonExistingClass";

$this->shouldThrow(
new FactoryException(
sprintf("Class %s was not found and cannot be added as reader.", $readerClass)
)
)->during(
'addReader',
array(
'z',
$readerClass,
function ($configuration, $class) {
return null;
},
)
);
}
}
35 changes: 0 additions & 35 deletions Tests/spec/ReaderFactorySpec.php

This file was deleted.

6 changes: 4 additions & 2 deletions src-dev/Behat/ApplicationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ public function iRunCommand($command, $file = null, PyStringNode $options = null

$arguments['configuration-file'] = __DIR__ . "/../../" . $file;

$options = $this->parseOptions($options);
if (null != $options) {
$options = $this->parseOptions($options);

$arguments += $options;
$arguments += $options;
}

$runOptions = array('interactive' => false, 'decorated' => false);

Expand Down
22 changes: 22 additions & 0 deletions src-dev/Test/TestReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace dev\Hexmedia\Crontab\Test;

use Hexmedia\Crontab\Crontab;
use Hexmedia\Crontab\Reader\ReaderInterface;

/**
* @author Krystian Kuczek <krystian@hexmedia.pl>
* @copyright 2013-2016 Hexmedia.pl
* @license @see LICENSE
*/
class TestReader implements ReaderInterface
{
/**
* @return Crontab
*/
public function read()
{
return null;
}
}
41 changes: 31 additions & 10 deletions src/Console/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Hexmedia\Crontab\Exception\ParsingException;
use Hexmedia\Crontab\Reader\ReaderInterface;
use Hexmedia\Crontab\Reader\SystemReader;
use Hexmedia\Crontab\ReaderFactory;
use Hexmedia\Crontab\Reader\ReaderFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -42,11 +42,9 @@ protected function configure()
{
$this
->addOption('machine', 'm', InputOption::VALUE_OPTIONAL, 'Machine name to synchronize')
->addOption('user', 'u', InputOption::VALUE_OPTIONAL, 'Username for synchronization (crontab -u)')
->addOption('type', 't', InputOption::VALUE_REQUIRED, 'Type of parsed file, if not given system will guess')
->addOption('dry-run', null, InputOption::VALUE_OPTIONAL, 'Do not write crontab file');

$this->configureArguments();
$this->configureOptionsAndArguments();
$this->configureName();
}

Expand All @@ -58,9 +56,10 @@ abstract protected function configureName();
/**
*
*/
protected function configureArguments()
protected function configureOptionsAndArguments()
{
$this
->addOption('type', 't', InputOption::VALUE_REQUIRED, 'Type of parsed file, if not given system will guess')
->addArgument('configuration-file', InputArgument::REQUIRED, 'Configuration file')
->addArgument('name', InputArgument::REQUIRED, 'Name of project');
}
Expand All @@ -75,17 +74,20 @@ protected function configureArguments()
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$user = $input->getOption('user');

$crontab = new Crontab($user, $name);
$crontab = new Crontab(null, $name);

$systemReader = new SystemReader($user, $crontab);
$systemReader = new SystemReader(null, $crontab);

$systemReader->read();

$configuration = $this->prepareConfiguration($input);
$configuration['crontab'] = $crontab;

// $this->readConfigurationCrontab($configuration);

//Trzeba tutaj jakoś zabstractować czytanie.

/** @var ReaderInterface $reader */
$reader = ReaderFactory::create($configuration);

Expand All @@ -103,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

$this->output($output, $crontab, $user);
$this->output($output, $crontab, null);
}

/**
Expand All @@ -115,12 +117,31 @@ protected function prepareConfiguration(InputInterface $input)
{
$configuration = array();

$configuration['user'] = $input->getOption('user');
$configuration['type'] = $input->getOption('type');
$configuration['file'] = $input->getArgument('configuration-file');
$configuration['name'] = $input->getArgument('name');
$configuration['machine'] = $input->getOption('machine');

return $configuration;
}

/**
* @param InputInterface $input
*
* @return mixed
*/
protected function getProjectName(InputInterface $input)
{
return $input->getArgument('name');
}

/**
* @param InputInterface $input
*
* @return mixed
*/
protected function getConfigurationFile(InputInterface $input)
{
return $input->getArgument('configuration-file');
}
}
4 changes: 2 additions & 2 deletions src/Console/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function configureName()
{
$this
->setName('clear')
->setDescription('Clear this project crontabs from this machine');
->setDescription('Clear this project crontab from this machine');
}

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
*
*/
protected function configureArguments()
protected function configureOptionsAndArguments()
{
$this
->addArgument('name', InputArgument::REQUIRED, 'Name of project')
Expand Down
Loading