38 Commits

Author SHA1 Message Date
13c4e1baf8 don't use phing 2019-06-05 11:11:18 +02:00
ac8c31e525 added comments 2019-06-05 10:15:11 +02:00
b934c4b5db Added Test for DataCollector 2019-06-05 10:14:50 +02:00
6f86885c4f Set test environment 2019-06-05 10:14:31 +02:00
f1de0abfda typo 2019-06-05 10:14:16 +02:00
5359a608c1 don't use default command 2019-06-05 09:46:32 +02:00
d69799f5de fixed renaming bugs 2019-06-05 09:46:21 +02:00
fcc9a80d50 set dossier:build as default command 2019-06-05 09:43:57 +02:00
582a82f3fc Its not working yet 2019-06-05 09:37:02 +02:00
c4f2bae3c2 changed commands to match new order 2019-06-05 09:36:30 +02:00
0aa71f31b1 Added Project form 2019-06-05 09:35:46 +02:00
9f0b05cbe9 Added PhotoTrait 2019-06-05 09:35:35 +02:00
482beb7010 Reorganized commands, removed theme-commands and edit-commands 2019-06-05 09:35:13 +02:00
3ab5a91d64 Ignore test-config 2019-06-05 08:59:34 +02:00
8d456c8e18 setting directories 2019-06-05 08:59:19 +02:00
e9922e2016 adding some tasks to get started 2019-06-05 00:31:34 +02:00
3271cb65ba Merge branch 'master' into dev
Conflicts:
	composer.json
	composer.lock
2019-06-05 00:13:09 +02:00
7cbbf2cd88 Using Phing as build-tool 2019-06-05 00:10:35 +02:00
d329257704 use dev-master version 2019-06-04 23:32:43 +02:00
1d990608f0 load magdev/console-form via packagist 2019-06-04 23:30:51 +02:00
77158e334e still trying to make installation work 2019-06-04 23:29:29 +02:00
9fee520d5d still trying to make installation work 2019-06-04 23:25:46 +02:00
ca08a12386 set minimu stability to dev 2019-06-04 23:12:26 +02:00
8f5b174ea2 use master branch 2019-06-04 23:10:15 +02:00
e1ade971c7 use github https 2019-06-04 23:07:29 +02:00
58410759b5 override stability for console-form 2019-06-04 23:01:21 +02:00
faceddec16 use http-path for repository 2019-06-04 22:55:20 +02:00
5a0e15d907 use local fork of console-form 2019-06-04 22:49:49 +02:00
a5329afd63 Merge branch 'dev' 2019-06-04 22:32:58 +02:00
668bf757a4 start using PHPUnit and test all this 2019-06-04 22:17:41 +02:00
8f01bf32a2 don't do this string hacking, we have a model 2019-06-04 21:34:09 +02:00
bedfc8c559 typo 2019-06-04 21:31:43 +02:00
4d91bd6bf5 Sort status output by start_date 2019-06-04 21:26:58 +02:00
fa86042253 skip dot-directories 2019-06-04 21:15:32 +02:00
1159d0b62f Introduced SystemService 2019-06-04 21:06:59 +02:00
fa253e60d8 made exec method more flexible 2019-06-04 21:01:19 +02:00
526dd97348 made start-template and output-dir/-filename configurable 2019-06-04 20:47:26 +02:00
fc96ef2f9a made start-template and output-dir/-filename configurable
Also added config-sections for theme and output.
2019-06-04 20:44:56 +02:00
27 changed files with 2211 additions and 501 deletions

2
.gitignore vendored
View File

@@ -12,3 +12,5 @@ Thumbs.db
example/ example/
vendor/ vendor/
.env .env
/.phpunit.result.cache
/build/

1
app/conf/.gitignore vendored
View File

@@ -1,2 +1,3 @@
/dossier_dev.yaml /dossier_dev.yaml
/dossier_prod.yaml /dossier_prod.yaml
/dossier_test.yaml

View File

@@ -1,6 +1,14 @@
### Settings file for magdev/dossier ### Settings file for magdev/dossier
charset: utf-8 charset: utf-8
docname: dossier
# Output settings
output:
path: _output
docname: dossier
# Theme settings
theme:
start_template: document.html.twig
# Date formats # Date formats
date: date:

View File

@@ -6,6 +6,9 @@ services:
config: config:
class: '\Magdev\Dossier\Service\ConfigService' class: '\Magdev\Dossier\Service\ConfigService'
system:
class: '\Magdev\Dossier\Service\SystemService'
monolog: monolog:
class: '\Magdev\Dossier\Service\MonologService' class: '\Magdev\Dossier\Service\MonologService'
@@ -21,7 +24,7 @@ services:
git: git:
class: '\Magdev\Dossier\Service\GitService' class: '\Magdev\Dossier\Service\GitService'
arguments: ['@config', '@monolog'] arguments: ['@config', '@monolog', '@system']
translator: translator:
class: '\Magdev\Dossier\Service\TranslatorService' class: '\Magdev\Dossier\Service\TranslatorService'

2
bin/.gitignore vendored
View File

@@ -3,3 +3,5 @@ lessc
pscss pscss
.directory .directory
/phpca /phpca
/phpunit
/phing

View File

@@ -27,19 +27,10 @@
* @package magdev/dossier * @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License * @license http://opensource.org/licenses/MIT MIT License
*/ */
declare(strict_types=1);
define('DOSSIER_ROOT', dirname(__DIR__)); require(dirname(__DIR__).'/src/bootstrap.php');
define('DOSSIER_CACHE', getenv('HOME').'/.dossier/cache');
define('PROJECT_ROOT', getcwd());
define('DOSSIER_LOGO', 'DQogX19fX19fX18gICAgICAgICAgICAgICAgICAgICAgLl9fICAgICAgICAgICAgICANCiBcX19fX19fIFwgICBfX19fICBfX19fX18gX19fX198X198IF9fX19fX19fX19fIA0KICB8ICAgIHwgIFwgLyAgXyBcLyAgX19fLy8gIF9fXy8gIHwvIF9fIFxfICBfXyBcDQogIHwgICAgYCAgICggIDxfPiApX19fIFwgXF9fXyBcfCAgXCAgX19fL3wgIHwgXC8NCiAvX19fX19fXyAgL1xfX19fL19fX18gID5fX19fICA+X198XF9fXyAgPl9ffCAgIA0KICAgICAgICAgXC8gICAgICAgICAgIFwvICAgICBcLyAgICAgICAgXC8gICAgICAgDQo='); define('DOSSIER_LOGO', 'DQogX19fX19fX18gICAgICAgICAgICAgICAgICAgICAgLl9fICAgICAgICAgICAgICANCiBcX19fX19fIFwgICBfX19fICBfX19fX18gX19fX198X198IF9fX19fX19fX19fIA0KICB8ICAgIHwgIFwgLyAgXyBcLyAgX19fLy8gIF9fXy8gIHwvIF9fIFxfICBfXyBcDQogIHwgICAgYCAgICggIDxfPiApX19fIFwgXF9fXyBcfCAgXCAgX19fL3wgIHwgXC8NCiAvX19fX19fXyAgL1xfX19fL19fX18gID5fX19fICA+X198XF9fXyAgPl9ffCAgIA0KICAgICAgICAgXC8gICAgICAgICAgIFwvICAgICBcLyAgICAgICAgXC8gICAgICAgDQo=');
if (!is_dir(DOSSIER_CACHE)) {
mkdir(DOSSIER_CACHE, 0700, true);
}
require DOSSIER_ROOT.'/vendor/autoload.php';
use Magdev\Dossier\Application; use Magdev\Dossier\Application;
use Magdev\Dossier\Command; use Magdev\Dossier\Command;
@@ -47,21 +38,21 @@ $app = new Application('dossier.phar', '1.0.0');
$app->add(new Command\Dossier\DossierBuildCommand()); $app->add(new Command\Dossier\DossierBuildCommand());
$app->add(new Command\Dossier\DossierInitCommand()); $app->add(new Command\Dossier\DossierInitCommand());
$app->add(new Command\Dossier\DossierStatusCommand()); $app->add(new Command\Dossier\DossierStatusCommand());
$app->add(new Command\Intro\IntroAddCommand());
$app->add(new Command\Intro\IntroEditCommand()); $app->add(new Command\Create\CreateIntroCommand());
$app->add(new Command\Person\PersonAddCommand()); $app->add(new Command\Create\CreatePersonCommand());
$app->add(new Command\Person\PersonEditCommand()); $app->add(new Command\Create\CreateCvCommand());
$app->add(new Command\Cv\CvAddCommand()); $app->add(new Command\Create\CreateProjectCommand());
$app->add(new Command\Cv\CvEditCommand());
$app->add(new Command\Config\ConfigShowCommand()); $app->add(new Command\Config\ConfigShowCommand());
$app->add(new Command\Config\ConfigGetCommand()); $app->add(new Command\Config\ConfigGetCommand());
$app->add(new Command\Config\ConfigSetCommand()); $app->add(new Command\Config\ConfigSetCommand());
$app->add(new Command\Config\ConfigUnsetCommand()); $app->add(new Command\Config\ConfigUnsetCommand());
$app->add(new Command\Theme\ThemeListCommand());
$app->add(new Command\Theme\ThemeDumpCommand());
$app->add(new Command\Cache\CacheClearCommand()); $app->add(new Command\Cache\CacheClearCommand());
$app->add(new Command\Server\ServerStartCommand()); $app->add(new Command\Server\ServerStartCommand());
$app->add(new Command\Dev\PharExtractCommand()); $app->add(new Command\Dev\PharExtractCommand());
$app->run(); $app->run();

View File

@@ -1,7 +1,7 @@
{ {
"name" : "magdev/dossier", "name" : "magdev/dossier",
"type" : "project", "type" : "project",
"description" : "Create your dossier from Markdown files", "description" : "Create a personal dossier from Markdown files",
"license" : "MIT", "license" : "MIT",
"authors" : [{ "authors" : [{
"name" : "Marco Grätsch", "name" : "Marco Grätsch",
@@ -13,6 +13,12 @@
"Magdev\\Dossier\\" : "src" "Magdev\\Dossier\\" : "src"
} }
}, },
"autoload-dev" : {
"psr-4" : {
"Magdev\\DossierTests\\" : "tests"
}
},
"minimum-stability" : "stable",
"require" : { "require" : {
"php" : "~7.2", "php" : "~7.2",
"ext-phar" : "*", "ext-phar" : "*",
@@ -34,11 +40,15 @@
"erusev/parsedown-extra" : "^0.7.1", "erusev/parsedown-extra" : "^0.7.1",
"leafo/scssphp" : "^0.7.6", "leafo/scssphp" : "^0.7.6",
"adbario/php-dot-notation" : "^2.0", "adbario/php-dot-notation" : "^2.0",
"magdev/console-form" : "^0.0.7", "magdev/console-form" : "dev-master",
"monolog/monolog" : "^1.23", "monolog/monolog" : "^1.23",
"pdfshift/pdfshift-php" : "~1.0.2", "pdfshift/pdfshift-php" : "~1.0.2",
"raivisdejus/html-minifier" : "~0.5" "raivisdejus/html-minifier" : "~0.5"
}, },
"require-dev" : {
"wapmorgan/php-code-analyzer" : "^1.0",
"phpunit/phpunit" : "~8.1"
},
"config" : { "config" : {
"bin-dir" : "bin" "bin-dir" : "bin"
}, },
@@ -58,14 +68,5 @@
] ]
} }
} }
},
"repositories" : [{
"type" : "git",
"url" : "git@github.com:magdev/console-form.git",
"name" : "magdev/console-form"
}
],
"require-dev" : {
"wapmorgan/php-code-analyzer" : "^1.0"
} }
} }

1929
composer.lock generated

File diff suppressed because it is too large Load Diff

21
phpunit.xml Normal file
View File

@@ -0,0 +1,21 @@
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="src/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="dossier">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="test"/>
</php>
</phpunit>

View File

@@ -28,7 +28,7 @@
* @license http://opensource.org/licenses/MIT MIT License * @license http://opensource.org/licenses/MIT MIT License
*/ */
namespace Magdev\Dossier\Command\Cv; namespace Magdev\Dossier\Command\Create;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
@@ -43,7 +43,7 @@ use Magdev\Dossier\Command\Base\BaseCommand;
* *
* @author magdev * @author magdev
*/ */
final class CvAddCommand extends BaseCommand final class CreateCvCommand extends BaseCommand
{ {
/** /**
* TheCV Form * TheCV Form
@@ -58,7 +58,7 @@ final class CvAddCommand extends BaseCommand
*/ */
protected function configure() protected function configure()
{ {
$this->setName('cv:add') $this->setName('create:cv')
->setDescription('Write a new CV entry') ->setDescription('Write a new CV entry')
->addArgument('name', InputArgument::REQUIRED, 'Choose the name of the entry') ->addArgument('name', InputArgument::REQUIRED, 'Choose the name of the entry')
->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor'); ->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor');
@@ -72,7 +72,12 @@ final class CvAddCommand extends BaseCommand
* @see \Magdev\Dossier\Command\BaseCommand::initialize() * @see \Magdev\Dossier\Command\BaseCommand::initialize()
*/ */
protected function initialize(InputInterface $input, OutputInterface $output) protected function initialize(InputInterface $input, OutputInterface $output)
{ {
$name = $input->getArgument('name');
if (file_exists(PROJECT_ROOT.'/cv/'.$name.'.md')) {
throw new \RuntimeException('File cv/'.$name.'.md already exists');
}
try { try {
$this->form = $this->getHelper('form')->getFormByName('form.cv', $input, $output); $this->form = $this->getHelper('form')->getFormByName('form.cv', $input, $output);
parent::initialize($input, $output); parent::initialize($input, $output);

View File

@@ -28,7 +28,7 @@
* @license http://opensource.org/licenses/MIT MIT License * @license http://opensource.org/licenses/MIT MIT License
*/ */
namespace Magdev\Dossier\Command\Intro; namespace Magdev\Dossier\Command\Create;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@@ -37,7 +37,7 @@ use Symfony\Component\Console\Exception\RuntimeException;
use Droath\ConsoleForm\Exception\FormException; use Droath\ConsoleForm\Exception\FormException;
use Magdev\Dossier\Command\Base\BaseCommand; use Magdev\Dossier\Command\Base\BaseCommand;
final class IntroAddCommand extends BaseCommand final class CreateIntroCommand extends BaseCommand
{ {
/** /**
* The IntroForm * The IntroForm
@@ -52,7 +52,7 @@ final class IntroAddCommand extends BaseCommand
*/ */
protected function configure() protected function configure()
{ {
$this->setName('intro:add') $this->setName('create:intro')
->setDescription('Write the Intro page') ->setDescription('Write the Intro page')
->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor'); ->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor');
@@ -68,6 +68,10 @@ final class IntroAddCommand extends BaseCommand
{ {
parent::initialize($input, $output); parent::initialize($input, $output);
if (file_exists(PROJECT_ROOT.'/intro.md')) {
throw new \RuntimeException('File intro.md already exists');
}
try { try {
$this->form = $this->getHelper('form') $this->form = $this->getHelper('form')
->getFormByName('form.intro', $input, $output); ->getFormByName('form.intro', $input, $output);

View File

@@ -28,7 +28,7 @@
* @license http://opensource.org/licenses/MIT MIT License * @license http://opensource.org/licenses/MIT MIT License
*/ */
namespace Magdev\Dossier\Command\Person; namespace Magdev\Dossier\Command\Create;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@@ -37,7 +37,7 @@ use Symfony\Component\Console\Exception\RuntimeException;
use Droath\ConsoleForm\Exception\FormException; use Droath\ConsoleForm\Exception\FormException;
use Magdev\Dossier\Command\Base\BaseCommand; use Magdev\Dossier\Command\Base\BaseCommand;
final class PersonAddCommand extends BaseCommand final class CreatePersonCommand extends BaseCommand
{ {
/** /**
* The IntroForm * The IntroForm
@@ -52,7 +52,7 @@ final class PersonAddCommand extends BaseCommand
*/ */
protected function configure() protected function configure()
{ {
$this->setName('person:add') $this->setName('create:person')
->setDescription('Write the Person page') ->setDescription('Write the Person page')
->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor'); ->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor');
@@ -68,6 +68,10 @@ final class PersonAddCommand extends BaseCommand
{ {
parent::initialize($input, $output); parent::initialize($input, $output);
if (file_exists(PROJECT_ROOT.'/person.md')) {
throw new \RuntimeException('File person.md already exists');
}
try { try {
$this->form = $this->getHelper('form') $this->form = $this->getHelper('form')
->getFormByName('form.person', $input, $output); ->getFormByName('form.person', $input, $output);

View File

@@ -0,0 +1,129 @@
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2018 magdev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author magdev
* @copyright 2018 Marco Grätsch
* @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License
*/
namespace Magdev\Dossier\Command\Create;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Exception\RuntimeException;
use Droath\ConsoleForm\Exception\FormException;
use Magdev\Dossier\Command\Base\BaseCommand;
/**
* Write a new project
*
* @author magdev
*/
final class CreateProjectCommand extends BaseCommand
{
/**
* TheCV Form
* @var \Magdev\Dossier\Form\Extension\Form
*/
protected $form = null;
/**
* {@inheritDoc}
* @see \Symfony\Component\Console\Command\Command::configure()
*/
protected function configure()
{
$this->setName('create:project')
->setDescription('Write a new project file')
->addArgument('name', InputArgument::REQUIRED, 'Choose the name of the entry')
->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor');
parent::configure();
}
/**
* {@inheritDoc}
* @see \Magdev\Dossier\Command\BaseCommand::initialize()
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
if (file_exists(PROJECT_ROOT.'/projects/'.$name.'.md')) {
throw new \RuntimeException('File projects/'.$name.'.md already exists');
}
try {
$this->form = $this->getHelper('form')->getFormByName('form.project', $input, $output);
parent::initialize($input, $output);
} catch (FormException $fe) {
throw new RuntimeException(get_class($fe).': '.$fe->getMessage(), $fe->getCode(), $fe);
}
}
/**
* {@inheritDoc}
* @see \Symfony\Component\Console\Command\Command::interact()
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$this->io->title($this->translator->trans('form.project.header.add'));
$this->io->newLine();
$this->form->process();
}
/**
* {@inheritDoc}
* @see \Symfony\Component\Console\Command\Command::execute()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->form->isProcessed()) {
$markdown = $this->getService('markdown');
/* @var $markdown \Magdev\Dossier\Service\MarkdownService */
try {
$text = $this->form->stripData('text', '');
$name = $input->getArgument('name');
$markdown->save(PROJECT_ROOT.'/projects/'.$name.'.md', $this->form->getResults(), $text, false);
$this->io->success($this->translator->trans('message.write.success', array(
'%name%' => 'Project/'.ucfirst($name)
)));
if ($input->getOption('review') != false) {
$this->getService('uri_helper')->openFileInEditor(PROJECT_ROOT.'/projects/'.$name.'.md');
}
} catch (FormException $fe) {
throw new RuntimeException(get_class($fe).': '.$fe->getMessage(), $fe->getCode(), $fe);
}
}
}
}

View File

@@ -1,70 +0,0 @@
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2018 magdev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author magdev
* @copyright 2018 Marco Grätsch
* @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License
*/
namespace Magdev\Dossier\Command\Cv;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Exception\RuntimeException;
use Magdev\Dossier\Command\Base\BaseCommand;
class CvEditCommand extends BaseCommand
{
/**
* {@inheritDoc}
* @see \Symfony\Component\Console\Command\Command::configure()
*/
protected function configure()
{
$this->setName('cv:edit')
->setDescription('Edit a CV entry in your default editor')
->addArgument('file', InputArgument::REQUIRED, 'Filename of the entry w/o extension');
parent::configure();
}
/**
* {@inheritDoc}
* @see \Symfony\Component\Console\Command\Command::configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$file = PROJECT_ROOT.'/cv/'.$input->getArgument('file').'.md';
if (!file_exists($file)) {
throw new RuntimeException('File '.$file.' not found');
}
$this->getService('uri_helper')->openFileInEditor($file);
}
}

View File

@@ -40,6 +40,7 @@ use Magdev\Dossier\Model\Intro;
use Magdev\Dossier\Model\Letter; use Magdev\Dossier\Model\Letter;
use Magdev\Dossier\Command\Base\BaseCommand; use Magdev\Dossier\Command\Base\BaseCommand;
use Magdev\Dossier\Util\DataCollector; use Magdev\Dossier\Util\DataCollector;
use Symfony\Component\Console\Command\Command;
/** /**
* Generate your dossier * Generate your dossier
@@ -62,6 +63,7 @@ final class DossierBuildCommand extends BaseCommand
->addOption('locale', 'l', InputOption::VALUE_OPTIONAL, 'Set the locale', 'de') ->addOption('locale', 'l', InputOption::VALUE_OPTIONAL, 'Set the locale', 'de')
->addOption('sort', 's', InputOption::VALUE_OPTIONAL, 'Set the sort direction for the CV', CurriculumVitae::SORT_DESC) ->addOption('sort', 's', InputOption::VALUE_OPTIONAL, 'Set the sort direction for the CV', CurriculumVitae::SORT_DESC)
->addOption('theme', 't', InputOption::VALUE_OPTIONAL, 'Select the theme', 'print') ->addOption('theme', 't', InputOption::VALUE_OPTIONAL, 'Select the theme', 'print')
->addOption('start-template', 'i', InputOption::VALUE_OPTIONAL, 'The name of the start-template', '')
->addOption('docname', 'd', InputOption::VALUE_OPTIONAL, 'Set the name for the output document (w/o extension)', '') ->addOption('docname', 'd', InputOption::VALUE_OPTIONAL, 'Set the name for the output document (w/o extension)', '')
->addOption('no-cover', null, InputOption::VALUE_NONE, 'Suppress the cover') ->addOption('no-cover', null, InputOption::VALUE_NONE, 'Suppress the cover')
@@ -97,6 +99,7 @@ final class DossierBuildCommand extends BaseCommand
$cssproc = $this->getService('cssproc'); $cssproc = $this->getService('cssproc');
/* @var $cssroc \Magdev\Dossier\Service\StylesheetProcessorService */ /* @var $cssroc \Magdev\Dossier\Service\StylesheetProcessorService */
$startTemplate = $input->getOption('start-template') ?: $this->config->get('theme.start_template');
$name = $input->getOption('docname') ?: $this->getService('git')->getCurrentBranchName(); $name = $input->getOption('docname') ?: $this->getService('git')->getCurrentBranchName();
try { try {
$data = new DataCollector(array( $data = new DataCollector(array(
@@ -113,7 +116,7 @@ final class DossierBuildCommand extends BaseCommand
$models = $this->getService('markdown')->getFileSet($input->getOption('sort')); $models = $this->getService('markdown')->getFileSet($input->getOption('sort'));
$data->merge($models); $data->merge($models);
$outputFile = $tpl->render('document.html.twig', $data, PROJECT_ROOT.'/_output'); $outputFile = $tpl->render($startTemplate, $data, PROJECT_ROOT.'/'.$this->config->get('output.path'));
if ($input->getOption('pdf')) { if ($input->getOption('pdf')) {
$outputFile = $this->getService('pdf')->createPdf($outputFile); $outputFile = $this->getService('pdf')->createPdf($outputFile);
} }

View File

@@ -102,17 +102,17 @@ class DossierStatusCommand extends BaseCommand
); );
$status[] = new TableSeparator(); $status[] = new TableSeparator();
$files = new \FilesystemIterator(PROJECT_ROOT.'/cv'); $files = new \FilesystemIterator(PROJECT_ROOT.'/cv', \FilesystemIterator::SKIP_DOTS);
foreach ($files as $file) { foreach ($files as $file) {
/* @var $file \SplFileInfo */ /* @var $file \SplFileInfo */
$document = $markdown->getDocument($file->getPathname()); $document = $markdown->getDocument($file->getPathname());
$entry = new Entry($document); $entry = new Entry($document);
$status[] = array(get_class($entry), 'cv/'.$file->getFilename(), $status[$entry->getStartDate()->format('Ymd')] = array(get_class($entry), 'cv/'.$file->getFilename(),
$this->io->align($this->io->bool($entry->useInResume()), 9, DossierStyle::ALIGN_CENTER), $this->io->align($this->io->bool($entry->useInResume()), 9, DossierStyle::ALIGN_CENTER),
$this->io->align($this->io->percent($analyzer->analyze($entry), $thresholds), 6, DossierStyle::ALIGN_RIGHT) $this->io->align($this->io->percent($analyzer->analyze($entry), $thresholds), 6, DossierStyle::ALIGN_RIGHT)
); );
} }
ksort($status);
$this->io->table(array('Model', 'File', $this->io->table(array('Model', 'File',
$this->io->align('In Resume', 9), $this->io->align('In Resume', 9),
$this->io->align('Status', 6, DossierStyle::ALIGN_RIGHT) $this->io->align('Status', 6, DossierStyle::ALIGN_RIGHT)

View File

@@ -1,108 +0,0 @@
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2018 magdev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author magdev
* @copyright 2018 Marco Grätsch
* @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License
*/
namespace Magdev\Dossier\Command\Theme;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Magdev\Dossier\Command\Base\BaseCommand;
/**
* Create a local copy of a template
*
* @author magdev
*/
final class ThemeDumpCommand extends BaseCommand
{
/**
* Phar helper service
* @var \Magdev\Dossier\Service\PharHelperService
*/
private $pharHelper = null;
/**
* {@inheritDoc}
* @see \Symfony\Component\Console\Command\Command::configure()
*/
protected function configure()
{
$this->setName('theme:dump')
->setDescription('Create a local copy of a theme')
->addArgument('theme', InputArgument::REQUIRED, 'The name of the theme')
->addOption('locale', 'l', InputOption::VALUE_OPTIONAL, 'Set the locale', 'de')
->addOption('rename', 'r', InputOption::VALUE_OPTIONAL, 'Rename the theme', '')
->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Output folder', getenv('HOME').'/.dossier/tpl');
parent::configure();
}
/**
* {@inheritDoc}
* @see \Symfony\Component\Console\Command\Command::initialize()
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->pharHelper = $this->getService('phar_helper');
parent::initialize($input, $output);
}
/**
* {@inheritDoc}
* @see \Symfony\Component\Console\Command\Command::execute()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$theme = $input->getArgument('theme');
$outDir = $input->getOption('output');
$newName = $input->getOption('rename');
$themeDir = 'app/tpl/'.$theme;
$targetDir = !$newName ? $outDir.'/'.$theme : $outDir.'/'.$newName;
$this->pharHelper->copyDir($themeDir, $targetDir);
$this->io->success($this->translator->trans('message.dump.success', array('%theme%' => $theme)));
/*
if ($outDir != getenv('HOME').'/.dossier/tpl') {
$output->writeln('<fg=cyan> '.$this->translator->trans('message.export.template_dir').'</>');
$output->writeln('<fg=blue> '.$this->translator->trans('message.export.code.template_environment', array('%path%' => $outDir)).'</>');
} else {
$output->writeln('<fg=cyan> '.$this->translator->trans('message.export.template_homedir').'</>');
}*/
$this->io->newLine();
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2018 magdev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author magdev
* @copyright 2018 Marco Grätsch
* @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License
*/
namespace Magdev\Dossier\Form;
use Magdev\Dossier\Form\Extension\Form;
use Magdev\Dossier\Form\Field\SelectField;
use Magdev\Dossier\Form\Field\TextField;
use Magdev\Dossier\Form\Field\BooleanField;
/**
* EntryFormBuilder
*
* @author magdev
*/
class ProjectFormBuilder extends Base\BaseFormBuilder implements Base\FormBuilderInterface
{
/**
* {@inheritDoc}
* @see \Droath\ConsoleForm\FormInterface::getName()
*/
public function getName()
{
return 'form.project';
}
/**
* {@inheritDoc}
* @see \Droath\ConsoleForm\FormInterface::buildForm()
*/
public function buildForm()
{
$form = new Form();
$form->setLabelPrefix($this->config->get('form.label.prefix'))
->setLabelLength($this->config->get('form.label.length'))
->addFormLoadCallback($this->getUnflattenCallback())
->addFormResultsCallback($this->getFlattenCallback());
$form->addField(new TextField('name', $this->translator->trans('form.project.name')));
$form->addField(new TextField('shortDescription', $this->translator->trans('form.project.short_description')));
$form->addField(new TextField('stack', $this->translator->trans('form.project.stack')));
$form->addField(new TextField('status', $this->translator->trans('form.project.status')));
$form->addField(new BooleanField('active', $this->translator->trans('form.project.active')));
$this->addFlatGroupField($form, 'urls', false, 'project');
$form->addField(new TextField('text', $this->translator->trans('form.project.text'), false));
return $form;
}
}

View File

@@ -129,7 +129,7 @@ final class Entry extends BaseModel implements PhotoInterface, AnalyzableInterfa
/** /**
* Constrctor * Constructor
* *
* @param \Mni\FrontYAML\Document $document * @param \Mni\FrontYAML\Document $document
*/ */

View File

@@ -33,6 +33,7 @@ namespace Magdev\Dossier\Model;
use Magdev\Dossier\Model\Base\BaseModel; use Magdev\Dossier\Model\Base\BaseModel;
use Magdev\Dossier\Model\Traits\ToggableTrait; use Magdev\Dossier\Model\Traits\ToggableTrait;
use Mni\FrontYAML\Document; use Mni\FrontYAML\Document;
use Magdev\Dossier\Model\Traits\PhotoTrait;
/** /**
* Model for projects page * Model for projects page
@@ -42,6 +43,7 @@ use Mni\FrontYAML\Document;
class Project extends BaseModel class Project extends BaseModel
{ {
use ToggableTrait; use ToggableTrait;
use PhotoTrait;
/** /**
* Project name * Project name
@@ -67,11 +69,22 @@ class Project extends BaseModel
*/ */
protected $stack = ''; protected $stack = '';
/**
* Project status
* @var string
*/
protected $status = '';
public function getStack(): string public function getStack(): string
{ {
return $this->stack; return $this->stack;
} }
public function getStatus(): string
{
return $this->status;
}
public function getName(): string public function getName(): string

View File

@@ -30,8 +30,6 @@
namespace Magdev\Dossier\Service; namespace Magdev\Dossier\Service;
// git branch | grep \* | cut -d ' ' -f2
class GitService class GitService
{ {
/** /**
@@ -46,17 +44,25 @@ class GitService
*/ */
protected $logger = null; protected $logger = null;
/**
* System service
* @var \Magdev\Dossier\Service\SystemService
*/
protected $system = null;
/** /**
* Constructor * Constructor
* *
* @param \Magdev\Dossier\Service\ConfigService $config * @param \Magdev\Dossier\Service\ConfigService $config
* @param \Magdev\Dossier\Service\MonologService $logger * @param \Magdev\Dossier\Service\MonologService $logger
* @param \Magdev\Dossier\Service\SystemService $system
*/ */
public function __construct(ConfigService $config, MonologService $logger) public function __construct(ConfigService $config, MonologService $logger, SystemService $system)
{ {
$this->config = $config; $this->config = $config;
$this->logger = $logger; $this->logger = $logger;
$this->system = $system;
} }
@@ -68,7 +74,7 @@ class GitService
public function init(): bool public function init(): bool
{ {
if (!$this->isGitRepository()) { if (!$this->isGitRepository()) {
$this->exec('git init'); $this->system->exec('git init');
} }
return $this->isGitRepository(); return $this->isGitRepository();
} }
@@ -82,10 +88,9 @@ class GitService
public function getCurrentBranchName(): string public function getCurrentBranchName(): string
{ {
if (!$this->isGitRepository()) { if (!$this->isGitRepository()) {
return $this->config->get('docname'); return $this->config->get('output.docname');
} }
$output = $this->exec('git branch | grep \\\* | cut -d \' \' -f2'); return $this->system->exec('git branch | grep \\\* | cut -d \' \' -f2', SystemService::MODE_LASTLINE);
return $output[0];
} }
@@ -96,20 +101,6 @@ class GitService
*/ */
public function isGitRepository(): bool public function isGitRepository(): bool
{ {
return is_dir(PROJECT_ROOT.'/.git') && file_exists(PROJECT_ROOT.'/.git/config'); return is_dir(PROJECT_ROOT.'/.git') && file_exists(PROJECT_ROOT.'/.git/HEAD');
}
/**
* Execute a system command
*
* @param string $cmd
* @return array
*/
protected function exec(string $cmd): array
{
$output = array();
exec($cmd, $output);
return $output;
} }
} }

View File

@@ -104,7 +104,7 @@ class MarkdownService
$intro = new Intro($this->getDocument(PROJECT_ROOT.'/intro.md')); $intro = new Intro($this->getDocument(PROJECT_ROOT.'/intro.md'));
$cv = new CurriculumVitae($this->formatter); $cv = new CurriculumVitae($this->formatter);
$files = new \FilesystemIterator(PROJECT_ROOT.'/cv'); $files = new \FilesystemIterator(PROJECT_ROOT.'/cv', \FilesystemIterator::SKIP_DOTS);
foreach ($files as $file) { foreach ($files as $file) {
/* @var $file \SplFileInfo */ /* @var $file \SplFileInfo */
$document = $this->getDocument($file->getPathname()); $document = $this->getDocument($file->getPathname());

View File

@@ -2,7 +2,7 @@
/** /**
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2018 magdev * Copyright (c) 2019 magdev
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -23,50 +23,37 @@
* THE SOFTWARE. * THE SOFTWARE.
* *
* @author magdev * @author magdev
* @copyright 2018 Marco Grätsch * @copyright 2019 Marco Grätsch
* @package magdev/dossier * @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License * @license http://opensource.org/licenses/MIT MIT License
*/ */
namespace Magdev\Dossier\Command\Theme; namespace Magdev\Dossier\Service;
use Symfony\Component\Console\Input\InputInterface; class SystemService
use Symfony\Component\Console\Input\InputOption; {
use Symfony\Component\Console\Output\OutputInterface; const MODE_OUTPUT = 1;
use Magdev\Dossier\Command\Base\BaseCommand; const MODE_RETURN = 2;
const MODE_LASTLINE = 3;
/**
* Create a local copy of a template
*
* @author magdev
*/
final class ThemeListCommand extends BaseCommand
{
/**
* {@inheritDoc}
* @see \Symfony\Component\Console\Command\Command::configure()
*/
protected function configure()
{
$this->setName('theme:list')
->setDescription('List available themes')
->addOption('all', 'a', InputOption::VALUE_NONE, 'List all themes, icluding the overridden ones');
parent::configure();
}
/** /**
* {@inheritDoc} * Execute a system command
* @see \Symfony\Component\Console\Command\Command::execute() *
* @param string $cmd
* @param int $mode
* @param array $output
* @param int $return
* @return string|int|array
*/ */
protected function execute(InputInterface $input, OutputInterface $output) public function exec(string $cmd, int $mode = self::MODE_OUTPUT, &$output = array(), int &$return = 0)
{ {
$all = (bool) $input->getOption('all'); $lastline = exec($cmd, $output, $return);
$helper = $this->getHelper('export'); switch ($mode) {
/* @var $helper \Magdev\Dossier\Helper\ExportHelper */ case self::MODE_LASTLINE: return $lastline;
case self::MODE_RETURN: return $return;
$themes = $this->config->findThemes($all); default:
case self::MODE_OUTPUT: return $output;
}
} }
} }

View File

@@ -97,7 +97,7 @@ class DataCollector implements DataCollectorInterface
*/ */
public function hasData(): bool public function hasData(): bool
{ {
return sizeof($this->data) > o ? true : false; return sizeof($this->data) > 0 ? true : false;
} }

41
src/bootstrap.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2019 magdev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author magdev
* @copyright 2019 Marco Grätsch
* @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License
*/
declare(strict_types=1);
define('DOSSIER_ROOT', dirname(__DIR__));
define('DOSSIER_CACHE', getenv('HOME').'/.dossier/cache');
define('PROJECT_ROOT', getcwd());
if (!is_dir(DOSSIER_CACHE)) {
mkdir(DOSSIER_CACHE, 0700, true);
}
require DOSSIER_ROOT.'/vendor/autoload.php';

View File

@@ -2,7 +2,7 @@
/** /**
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2018 magdev * Copyright (c) 2019 magdev
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -23,47 +23,49 @@
* THE SOFTWARE. * THE SOFTWARE.
* *
* @author magdev * @author magdev
* @copyright 2018 Marco Grätsch * @copyright 2019 Marco Grätsch
* @package magdev/dossier * @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License * @license http://opensource.org/licenses/MIT MIT License
*/ */
namespace Magdev\Dossier\Command\Intro; namespace Magdev\DossierTests;
use Symfony\Component\Console\Input\InputInterface; use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Console\Input\InputArgument; use Magdev\Dossier\Application;
use Symfony\Component\Console\Exception\RuntimeException; use Magdev\Dossier\Service\GitService;
use Magdev\Dossier\Command\Base\BaseCommand;
class IntroEditCommand extends BaseCommand class ApplicationTest extends TestCase
{ {
/** /**
* {@inheritDoc} * @var \Magdev\Dossier\Application
* @see \Symfony\Component\Console\Command\Command::configure()
*/ */
protected function configure() private $app = null;
/**
* Setup TestCase
*/
public function setup(): void
{ {
$this->setName('intro:edit') $this->app = new Application();
->setDescription('Edit the intro in your default editor');
parent::configure();
} }
/** /**
* {@inheritDoc} * @group core
* @see \Symfony\Component\Console\Command\Command::configure()
*/ */
protected function execute(InputInterface $input, OutputInterface $output) public function testGetContainer()
{ {
$file = PROJECT_ROOT.'/intro.md'; $this->assertInstanceOf(ContainerBuilder::class, $this->app->getContainer());
}
if (!file_exists($file)) {
throw new RuntimeException('File '.$file.' not found');
} /**
* @group core
$this->getService('uri_helper')->openFileInEditor($file); */
public function testGetValidService()
{
$this->assertInstanceOf(GitService::class, $this->app->getService('git'));
} }
} }

View File

@@ -2,7 +2,7 @@
/** /**
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2018 magdev * Copyright (c) 2019 magdev
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -23,47 +23,51 @@
* THE SOFTWARE. * THE SOFTWARE.
* *
* @author magdev * @author magdev
* @copyright 2018 Marco Grätsch * @copyright 2019 Marco Grätsch
* @package magdev/dossier * @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License * @license http://opensource.org/licenses/MIT MIT License
*/ */
namespace Magdev\Dossier\Command\Person; namespace Magdev\DossierTests\Util;
use Symfony\Component\Console\Input\InputInterface; use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface; use Magdev\Dossier\Util\DataCollector;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Exception\RuntimeException;
use Magdev\Dossier\Command\Base\BaseCommand;
class PersonEditCommand extends BaseCommand class DataCollectorTest extends TestCase
{ {
/** /**
* {@inheritDoc} * @var array
* @see \Symfony\Component\Console\Command\Command::configure()
*/ */
protected function configure() private $initData = ['foo'];
/**
* @group core
* @covers \Magdev\Dossier\Util\DataCollector::addData()
* @covers \Magdev\Dossier\Util\DataCollector::hasData()
* @covers \Magdev\Dossier\Util\DataCollector::setData()
* @covers \Magdev\Dossier\Util\DataCollector::getData()
*/
public function testSetGetData()
{ {
$this->setName('person:edit') $data = new DataCollector($this->initData);
->setDescription('Edit personal data in your default editor'); $this->assertEquals(true, $data->hasData());
parent::configure(); $data->setData(1, 'bar');
$this->assertEquals(['foo', 'bar'], $data->getData());
} }
/** /**
* {@inheritDoc} * @group core
* @see \Symfony\Component\Console\Command\Command::configure() * @covers \Magdev\Dossier\Util\DataCollector::merge()
*/ */
protected function execute(InputInterface $input, OutputInterface $output) public function testMergeData()
{ {
$file = PROJECT_ROOT.'/person.md'; $data = new DataCollector($this->initData);
$data2 = new DataCollector(['bar']);
if (!file_exists($file)) { $data->merge($data2);
throw new RuntimeException('File '.$file.' not found'); $this->assertEquals(['foo', 'bar'], $data->getData());
}
$this->getService('uri_helper')->openFileInEditor($file);
} }
} }