@@ -45,7 +45,7 @@ public function testCompile()
4545
4646 $ expected = '.*jasperstarter compile ".*hello_world.jrxml" -o "{output_file}" ' ;
4747
48- $ this ->assertRegExp ('/ ' .$ expected .'/ ' , $ result ->output ());
48+ $ this ->expectOutputRegex ('/ ' .$ expected .'/ ' , $ result ->output ());
4949 }
5050
5151 public function testProcess ()
@@ -54,15 +54,42 @@ public function testProcess()
5454
5555 $ expected = '.*jasperstarter process ".*hello_world.jrxml" -o "{output_file}" ' ;
5656
57- $ this ->assertRegExp ('/ ' .$ expected .'/ ' , $ result ->output ());
57+ $ this ->expectOutputRegex ('/ ' .$ expected .'/ ' , $ result ->output ());
58+ }
5859
60+ public function testProcessWithOptions ()
61+ {
62+ $ options = [
63+ 'locale ' => 'en_US ' ,
64+ 'params ' => [
65+ 'param_1 ' => 'value_1 ' ,
66+ 'param_2 ' => 'value_2 ' ,
67+ ],
68+ 'db_connection ' => [
69+ 'driver ' => 'driver ' ,
70+ 'username ' => 'user ' ,
71+ 'password ' => '12345678 ' ,
72+ 'database ' => 'db '
73+ ],
74+ 'resources ' => 'foo ' ,
75+ ];
76+
77+ $ result = $ this ->instance ->process ('examples/hello_world.jrxml ' , '{output_file} ' , $ options );
78+
79+ $ expected = '.*jasperstarter --locale en_US process ".*hello_world.jrxml" -o "{output_file}" ' ;
80+ $ expected .= '-f pdf -P param_1="value_1" param_2="value_2" -t driver -u user -p 12345678 -n db -r foo ' ;
81+
82+ $ this ->expectOutputRegex (
83+ '/ ' .$ expected .'/ ' ,
84+ $ result ->output ()
85+ );
5986 }
6087
6188 public function testListParameters ()
6289 {
6390 $ result = $ this ->instance ->listParameters ('examples/hello_world.jrxml ' );
6491
65- $ this ->assertRegExp (
92+ $ this ->expectOutputRegex (
6693 '/.*jasperstarter list_parameters ".*hello_world.jrxml"/ ' ,
6794 $ result ->output ()
6895 );
@@ -79,7 +106,18 @@ public function testCompileHelloWorld()
79106 {
80107 $ result = $ this ->instance ->compile ('examples/hello_world.jrxml ' );
81108
82- $ this ->assertRegExp ('/.*jasperstarter compile ".*hello_world.jrxml"/ ' , $ result ->output ());
109+ $ this ->expectOutputRegex ('/.*jasperstarter compile ".*hello_world.jrxml"/ ' , $ result ->output ());
110+ }
111+
112+ public function testOutputWithUserOnExecute ()
113+ {
114+ $ this ->expectException (Exception \ErrorCommandExecutable::class);
115+
116+ $ this ->instance ->compile (__DIR__ . '/test.jrxml ' , __DIR__ . '/test ' )->execute ('phpjasper ' );
117+
118+ $ expected = 'su -u 1000 -c "./jasperstarter compile "/var/www/app/tests/test.jrxml" -o "/var/www/app/tests/test"" ' ;
119+
120+ $ this ->expectOutputRegex ('/ ' . $ expected . '/ ' , $ this ->instance ->output ());
83121 }
84122
85123 public function testExecuteWithoutCompile ()
@@ -103,6 +141,25 @@ public function testExecute()
103141 $ this ->assertInternalType ('array ' , $ actual );
104142 }
105143
144+ public function testExecuteWithOutput ()
145+ {
146+ $ actual = $ this ->instance ->compile (__DIR__ . '/test.jrxml ' , __DIR__ . '/test ' )->execute ();
147+
148+ $ this ->assertInternalType ('array ' , $ actual );
149+ }
150+
151+ public function testExecuteThrowsInvalidResourceDirectory ()
152+ {
153+ $ reflectionObject = new \ReflectionObject ($ this ->instance );
154+ $ reflectionProperty = $ reflectionObject ->getProperty ('pathExecutable ' );
155+ $ reflectionProperty ->setAccessible (true );
156+ $ reflectionProperty ->setValue ($ this ->instance , '' );
157+
158+ $ this ->expectException (Exception \InvalidResourceDirectory::class);
159+
160+ $ this ->instance ->compile (__DIR__ . '/test.jrxml ' , __DIR__ . '/test ' )->execute ();
161+ }
162+
106163 public function testListParametersWithWrongInput ()
107164 {
108165 $ this ->expectException (Exception \InvalidInputFile::class);
0 commit comments