Skip to content

Commit

Permalink
Merge branch 'release/0.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Bickel committed Aug 17, 2016
2 parents 7c17971 + 2a6d352 commit 58de22e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
11 changes: 8 additions & 3 deletions src/Command/CoreImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ protected function configure()
* @param InputInterface $input User input on console
* @param OutputInterface $output Output of the command
*
* @return void
* @return integer
*/
protected function doImport(Finder $finder, InputInterface $input, OutputInterface $output)
{
$exitCode = 0;
foreach ($finder as $file) {
$this->importResource($file, $input, $output);
}
Expand All @@ -103,7 +104,9 @@ protected function doImport(Finder $finder, InputInterface $input, OutputInterfa
foreach ($this->errorStack as $errorMessage) {
$output->writeln($errorMessage);
}
$exitCode = 1;
}
return $exitCode;
}

/**
Expand All @@ -113,15 +116,17 @@ protected function doImport(Finder $finder, InputInterface $input, OutputInterfa
* @param InputInterface $input User input on console
* @param OutputInterface $output Output of the command
*
* @return void
* @return integer
*/
private function importResource(\SplFileInfo $file, InputInterface $input, OutputInterface $output)
{
$doc = $this->frontMatter->parse($file->getContents());
$origDoc = $this->serializer->unserialize($doc->getContent());

if (is_null($origDoc)) {
$output->writeln("<error>Could not deserialize file <${file}></error>");
$errorMessage = "<error>Could not deserialize file <${file}></error>";
$output->writeln($errorMessage);
array_push($this->errorStack, $errorMessage);
} else {
try {
$collectionName = $doc->getData()['collection'];
Expand Down
7 changes: 3 additions & 4 deletions src/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ protected function configure()
*/
protected function doImport(Finder $finder, InputInterface $input, OutputInterface $output)
{
$exitCode = 0;
$host = $input->getArgument('host');
$rewriteHost = $input->getOption('rewrite-host');
$rewriteTo = $input->getOption('rewrite-to');
Expand All @@ -160,17 +161,15 @@ protected function doImport(Finder $finder, InputInterface $input, OutputInterfa
if (empty($this->errors)) {
// No errors
$output->writeln("\n".'<info>No errors</info>');
$output->writeln('0');
exit(0);
} else {
// Yes, there was errors
$output->writeln("\n".'<info>There was errors: '.count($this->errors).'</info>');
foreach ($this->errors as $file => $error) {
$output->writeln("<error>{$file}: {$error}</error>");
}
$output->writeln('1');
exit(1);
$exitCode = 1;
}
return $exitCode;
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Command/ImportCommandAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
* @param InputInterface $input User input on console
* @param OutputInterface $output Output of the command
*
* @return void
* @return integer
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -68,12 +68,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$finder->ignoreDotFiles(true)->filter($filter);


$exitCode = 1;
try {
$this->doImport($finder, $input, $output);
$exitCode = $this->doImport($finder, $input, $output);
} catch (MissingTargetException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
}
return $exitCode;
}

/**
Expand Down
1 change: 1 addition & 0 deletions test/Command/CoreImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ public function testResultingFiles()
'Could not deserialize file <' . $this->sourceDir . '/Dudess/Invalid.json>',
$this->cmdTester->getDisplay()
);
$this->assertEquals(1, $this->cmdTester->getStatusCode());
}
}
3 changes: 3 additions & 0 deletions test/Command/ImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function ($ok) use ($responseMock) {

$this->assertContains('Loading data from ' . $file, $cmdTester->getDisplay());
$this->assertContains('Wrote <' . $host . $path . '>; rel="self"', $cmdTester->getDisplay());
$this->assertEquals(0, $cmdTester->getStatusCode());
}

/**
Expand Down Expand Up @@ -167,6 +168,7 @@ function ($ok, $nok) use ($exceptionMock) {
$cmdTester->getDisplay()
);
}
$this->assertEquals(1, $cmdTester->getStatusCode());
}

/**
Expand Down Expand Up @@ -254,6 +256,7 @@ function ($ok) use ($responseMock) {
]
);
$this->assertContains('Wrote <http://example.com/core/module/test>; rel="self"', $cmdTester->getDisplay());
$this->assertEquals(0, $cmdTester->getStatusCode());
}

/**
Expand Down

0 comments on commit 58de22e

Please sign in to comment.