Skip to content

Commit

Permalink
Keep track of ErrorManager errors
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Mar 8, 2019
1 parent a9c596f commit 59deb24
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/ErrorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,30 @@ class ErrorManager
/** @var Configuration */
private $configuration;

/** @var string[] */
private $errors = [];

public function __construct(Configuration $configuration)
{
$this->configuration = $configuration;
}

public function error(string $message) : void
{
$this->errors[] = $message;

if ($this->configuration->isAbortOnError()) {
throw new Exception($message);
}

echo '/!\\ ' . $message . "\n";
}

/**
* @return string[]
*/
public function getErrors() : array
{
return $this->errors;
}
}
25 changes: 25 additions & 0 deletions tests/ErrorManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\RST;

use Doctrine\RST\Configuration;
use Doctrine\RST\ErrorManager;
use PHPUnit\Framework\TestCase;

class ErrorManagerTest extends TestCase
{
public function testGetErrors() : void
{
$configuration = $this->createMock(Configuration::class);
$configuration->expects(self::atLeastOnce())
->method('isAbortOnError')
->willReturn(false);

$errorManager = new ErrorManager($configuration);
$errorManager->error('ERROR FOO');
$errorManager->error('ERROR BAR');
self::assertSame(['ERROR FOO', 'ERROR BAR'], $errorManager->getErrors());
}
}

0 comments on commit 59deb24

Please sign in to comment.