Skip to content

minor corrections, tests improvement #145

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

Merged
merged 1 commit into from
Apr 15, 2019
Merged
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
16 changes: 9 additions & 7 deletions src/PHPJasper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace PHPJasper;

use PHPJasper\Exception;

class PHPJasper
{

Expand Down Expand Up @@ -68,7 +70,7 @@ private function checkServer()
public function compile(string $input, string $output = '')
{
if (!is_file($input)) {
throw new \PHPJasper\Exception\InvalidInputFile();
throw new Exception\InvalidInputFile();
}

$this->command = $this->checkServer();
Expand All @@ -95,7 +97,7 @@ public function process(string $input, string $output, array $options = [])
$options = $this->parseProcessOptions($options);

if (!$input) {
throw new \PHPJasper\Exception\InvalidInputFile();
throw new Exception\InvalidInputFile();
}

$this->validateFormat($options['format']);
Expand Down Expand Up @@ -175,7 +177,7 @@ protected function validateFormat($format)
}
foreach ($format as $value) {
if (!in_array($value, $this->formats)) {
throw new \PHPJasper\Exception\InvalidFormat();
throw new Exception\InvalidFormat();
}
}
}
Expand All @@ -188,7 +190,7 @@ protected function validateFormat($format)
public function listParameters(string $input)
{
if (!is_file($input)) {
throw new \PHPJasper\Exception\InvalidInputFile();
throw new Exception\InvalidInputFile();
}

$this->command = $this->checkServer();
Expand Down Expand Up @@ -216,7 +218,7 @@ public function execute($user = false)
chdir($this->pathExecutable);
exec($this->command, $output, $returnVar);
if ($returnVar !== 0) {
throw new \PHPJasper\Exception\ErrorCommandExecutable();
throw new Exception\ErrorCommandExecutable();
}

return $output;
Expand Down Expand Up @@ -247,10 +249,10 @@ protected function addUserToCommand($user)
protected function validateExecute()
{
if (!$this->command) {
throw new \PHPJasper\Exception\InvalidCommandExecutable();
throw new Exception\InvalidCommandExecutable();
}
if (!is_dir($this->pathExecutable)) {
throw new \PHPJasper\Exception\InvalidResourceDirectory();
throw new Exception\InvalidResourceDirectory();
}
}
}
16 changes: 7 additions & 9 deletions tests/PHPJasperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@

use PHPUnit\Framework\TestCase;
use PHPJasper\PHPJasper;
use PHPJasper\Exception;

/**
* @author Rafael Queiroz <rafaelfqf@gmail.com>
*/
final class PHPJasperTest extends TestCase
{
/**
* @var
*/
private $instance;

public function setUp()
Expand Down Expand Up @@ -72,7 +70,7 @@ public function testListParameters()

public function testCompileWithWrongInput()
{
$this->expectException(\PHPJasper\Exception\InvalidInputFile::class);
$this->expectException(Exception\InvalidInputFile::class);

$this->instance->compile('');
}
Expand All @@ -86,14 +84,14 @@ public function testCompileHelloWorld()

public function testExecuteWithoutCompile()
{
$this->expectException(\PHPJasper\Exception\InvalidCommandExecutable::class);
$this->expectException(Exception\InvalidCommandExecutable::class);

$this->instance->execute();
}

public function testInvalidInputFile()
{
$this->expectException(\PHPJasper\Exception\InvalidInputFile::class);
$this->expectException(Exception\InvalidInputFile::class);

$this->instance->compile('{invalid}')->execute();
}
Expand All @@ -107,14 +105,14 @@ public function testExecute()

public function testListParametersWithWrongInput()
{
$this->expectException(\PHPJasper\Exception\InvalidInputFile::class);
$this->expectException(Exception\InvalidInputFile::class);

$this->instance->listParameters('');
}

public function testProcessWithWrongInput()
{
$this->expectException(\PHPJasper\Exception\InvalidInputFile::class);
$this->expectException(Exception\InvalidInputFile::class);

$this->instance->process('', '', [
'format' => 'mp3'
Expand All @@ -123,7 +121,7 @@ public function testProcessWithWrongInput()

public function testProcessWithWrongFormat()
{
$this->expectException(\PHPJasper\Exception\InvalidFormat::class);
$this->expectException(Exception\InvalidFormat::class);

$this->instance->process('hello_world.jrxml', '', [
'format' => 'mp3'
Expand Down