From 90d2b3729b488bb4fb0354da52e64b44e3560378 Mon Sep 17 00:00:00 2001 From: geekcom Date: Thu, 15 Mar 2018 16:41:22 -0300 Subject: [PATCH] fix tests --- tests/PHPJasper/PHPJasperTest.php | 61 ++++++++++++++----------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/tests/PHPJasper/PHPJasperTest.php b/tests/PHPJasper/PHPJasperTest.php index e3d082f..7c53c74 100644 --- a/tests/PHPJasper/PHPJasperTest.php +++ b/tests/PHPJasper/PHPJasperTest.php @@ -21,14 +21,19 @@ */ class PHPJasperTest extends TestCase { + /** + * @var + */ + private $instance; + public function setUp() { - $this->PHPJasper = new PHPJasper(); + $this->instance = new PHPJasper(); } public function tearDown() { - unset($this->PHPJasper); + unset($this->instance); } public function testConstructor() @@ -38,20 +43,26 @@ public function testConstructor() public function testCompile() { - $result = $this->PHPJasper->compile('examples/hello_world.jrxml', '{output_file}'); - - $this->assertInstanceOf(PHPJasper::class, $result); + $result = $this->instance->compile('examples/hello_world.jrxml', '{output_file}'); $expected = '.*jasperstarter compile ".*hello_world.jrxml" -o "{output_file}"'; $this->assertRegExp('/'.$expected.'/', $result->output()); } - public function testListParameters() + public function testProcess() { - $result = $this->PHPJasper->listParameters('examples/hello_world.jrxml'); + $result = $this->instance->process('examples/hello_world.jrxml', '{output_file}'); + + $expected = '.*jasperstarter process ".*hello_world.jrxml" -o "{output_file}"'; + + $this->assertRegExp('/'.$expected.'/', $result->output()); + + } - $this->assertInstanceOf(PHPJasper::class, $result); + public function testListParameters() + { + $result = $this->instance->listParameters('examples/hello_world.jrxml'); $this->assertRegExp( '/.*jasperstarter list_parameters ".*hello_world.jrxml"/', @@ -63,18 +74,12 @@ public function testCompileWithWrongInput() { $this->expectException(\PHPJasper\Exception\InvalidInputFile::class); - $jasper = new PHPJasper(); - - $jasper->compile(''); + $this->instance->compile(''); } public function testCompileHelloWorld() { - $jasper = new PHPJasper(); - - $result = $jasper->compile('examples/hello_world.jrxml'); - - $this->assertInstanceOf(PHPJasper::class, $result); + $result = $this->instance->compile('examples/hello_world.jrxml'); $this->assertRegExp('/.*jasperstarter compile ".*hello_world.jrxml"/', $result->output()); } @@ -83,22 +88,19 @@ public function testExecuteWithoutCompile() { $this->expectException(\PHPJasper\Exception\InvalidCommandExecutable::class); - $jasper = new PHPJasper(); - $jasper->execute(); + $this->instance->execute(); } public function testInvalidInputFile() { $this->expectException(\PHPJasper\Exception\InvalidInputFile::class); - $jasper = new PHPJasper(); - $jasper->compile('{invalid}')->execute(); + $this->instance->compile('{invalid}')->execute(); } public function testExecute() { - $jasper = new PHPJasper(); - $actual = $jasper->compile(__DIR__ . '/test.jrxml')->execute(); + $actual = $this->instance->compile(__DIR__ . '/test.jrxml')->execute(); $this->assertInternalType('array', $actual); } @@ -107,16 +109,14 @@ public function testListParametersWithWrongInput() { $this->expectException(\PHPJasper\Exception\InvalidInputFile::class); - $jasper = new PHPJasper(); - $jasper->listParameters(''); + $this->instance->listParameters(''); } public function testProcessWithWrongInput() { $this->expectException(\PHPJasper\Exception\InvalidInputFile::class); - $jasper = new PHPJasper(); - $jasper->process('', '', [ + $this->instance->process('', '', [ 'format' => 'mp3' ]); } @@ -125,15 +125,8 @@ public function testProcessWithWrongFormat() { $this->expectException(\PHPJasper\Exception\InvalidFormat::class); - $jasper = new PHPJasper(); - $jasper->process('hello_world.jrxml', '', [ + $this->instance->process('hello_world.jrxml', '', [ 'format' => 'mp3' ]); } - - public function testProcess() - { - $jasper = new PHPJasper(); - $this->assertInstanceOf(PHPJasper::class, $jasper->process('hello_world.jrxml', "")); - } }