Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Dec 19, 2023
1 parent 4c33be8 commit e265727
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Components/Reporter/ReporterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPUnuhi\Components\Reporter;

use Exception;
use InvalidArgumentException;
use PHPUnuhi\Components\Reporter\JSON\JsonReporter;
use PHPUnuhi\Components\Reporter\JUnit\JUnitReporter;
use PHPUnuhi\Exceptions\ConfigurationException;
Expand Down Expand Up @@ -49,8 +50,8 @@ public function resetStorages(): void
{
$this->reporters = [];

$this->reporters[] = new JUnitReporter();
$this->reporters[] = new JsonReporter();
$this->reporters[] = new JUnitReporter();
$this->reporters[] = new JsonReporter();
}


Expand All @@ -63,7 +64,7 @@ public function getReporter(string $name): ReporterInterface
{
if ($name === '' || $name === '0') {

throw new Exception('No name provided for the Reporter');
throw new InvalidArgumentException('No name provided for the Reporter');
}

foreach ($this->reporters as $reporter) {
Expand Down
53 changes: 53 additions & 0 deletions tests/phpunit/Components/Repoter/ReporterFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace phpunit\Components\Repoter;

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use PHPUnuhi\Components\Reporter\JUnit\JUnitReporter;
use PHPUnuhi\Components\Reporter\ReporterFactory;
use PHPUnuhi\Exceptions\ConfigurationException;

class ReporterFactoryTest extends TestCase
{

/**
* @return void
* @throws ConfigurationException
*/
public function testEmptyReportNameThrowsException(): void
{
$factory = ReporterFactory::getInstance();

$this->expectException(InvalidArgumentException::class);

$factory->getReporter('');
}

/**
* @return void
* @throws ConfigurationException
*/
public function testUnknownReporterThrowsException(): void
{
$factory = ReporterFactory::getInstance();

$this->expectException(ConfigurationException::class);

$factory->getReporter('unknown');
}

/**
* @return void
* @throws ConfigurationException
*/
public function testJUnitReporterIsFound(): void
{
$factory = ReporterFactory::getInstance();

$reporter = $factory->getReporter('junit');

$this->assertInstanceOf(JUnitReporter::class, $reporter);
}

}

0 comments on commit e265727

Please sign in to comment.