Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/vendor
tests/*.jasper
tests/fixture
tests/codeCoverage

# IDE
Expand All @@ -8,4 +9,4 @@ tests/codeCoverage
.project
.settings
## PHPStorm
.idea/
.idea/
65 changes: 61 additions & 4 deletions tests/PHPJasperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testCompile()

$expected = '.*jasperstarter compile ".*hello_world.jrxml" -o "{output_file}"';

$this->assertRegExp('/'.$expected.'/', $result->output());
$this->expectOutputRegex('/'.$expected.'/', $result->output());
}

public function testProcess()
Expand All @@ -54,15 +54,42 @@ public function testProcess()

$expected = '.*jasperstarter process ".*hello_world.jrxml" -o "{output_file}"';

$this->assertRegExp('/'.$expected.'/', $result->output());
$this->expectOutputRegex('/'.$expected.'/', $result->output());
}

public function testProcessWithOptions()
{
$options = [
'locale' => 'en_US',
'params' => [
'param_1' => 'value_1',
'param_2' => 'value_2',
],
'db_connection' => [
'driver' => 'driver',
'username' => 'user',
'password' => '12345678',
'database' => 'db'
],
'resources' => 'foo',
];

$result = $this->instance->process('examples/hello_world.jrxml', '{output_file}', $options);

$expected = '.*jasperstarter --locale en_US process ".*hello_world.jrxml" -o "{output_file}" ';
$expected .= '-f pdf -P param_1="value_1" param_2="value_2" -t driver -u user -p 12345678 -n db -r foo';

$this->expectOutputRegex(
'/'.$expected.'/',
$result->output()
);
}

public function testListParameters()
{
$result = $this->instance->listParameters('examples/hello_world.jrxml');

$this->assertRegExp(
$this->expectOutputRegex(
'/.*jasperstarter list_parameters ".*hello_world.jrxml"/',
$result->output()
);
Expand All @@ -79,7 +106,18 @@ public function testCompileHelloWorld()
{
$result = $this->instance->compile('examples/hello_world.jrxml');

$this->assertRegExp('/.*jasperstarter compile ".*hello_world.jrxml"/', $result->output());
$this->expectOutputRegex('/.*jasperstarter compile ".*hello_world.jrxml"/', $result->output());
}

public function testOutputWithUserOnExecute()
{
$this->expectException(Exception\ErrorCommandExecutable::class);

$this->instance->compile(__DIR__ . '/test.jrxml', __DIR__ . '/test')->execute('phpjasper');

$expected = 'su -u 1000 -c "./jasperstarter compile "/var/www/app/tests/test.jrxml" -o "/var/www/app/tests/test""';

$this->expectOutputRegex('/' . $expected . '/', $this->instance->output());
}

public function testExecuteWithoutCompile()
Expand All @@ -103,6 +141,25 @@ public function testExecute()
$this->assertInternalType('array', $actual);
}

public function testExecuteWithOutput()
{
$actual = $this->instance->compile(__DIR__ . '/test.jrxml', __DIR__ . '/test')->execute();

$this->assertInternalType('array', $actual);
}

public function testExecuteThrowsInvalidResourceDirectory()
{
$reflectionObject = new \ReflectionObject($this->instance);
$reflectionProperty = $reflectionObject->getProperty('pathExecutable');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->instance, '');

$this->expectException(Exception\InvalidResourceDirectory::class);

$this->instance->compile(__DIR__ . '/test.jrxml', __DIR__ . '/test')->execute();
}

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