@@ -17,10 +17,12 @@ final class PHPJasperTest extends TestCase
1717 private $ PHPJasper ;
1818 private $ input ;
1919 private $ output ;
20+ protected $ windows ;
2021
2122 public function setUp ()
2223 {
2324 $ this ->PHPJasper = new PHPJasper ();
25+ $ this ->windows = strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ? true : false ;
2426 }
2527
2628 public function tearDown ()
@@ -38,76 +40,110 @@ public function testCompile()
3840 $ result = $ this ->PHPJasper ->compile ('{input_file} ' , '{output_file} ' );
3941
4042 $ this ->assertInstanceOf (PHPJasper::class, $ result );
41- $ this ->assertEquals ('jasperstarter compile "{input_file}" -o "{output_file}" ' , $ result ->output ());
43+
44+ $ expected = strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ? '' : './ ' ;
45+ $ expected .= 'jasperstarter compile "{input_file}" -o "{output_file}" ' ;
46+
47+ $ this ->assertEquals ($ expected , $ result ->output ());
4248 }
4349
4450 public function testListParameters ()
4551 {
4652 $ result = $ this ->PHPJasper ->listParameters ('{input_fille} ' );
4753
4854 $ this ->assertInstanceOf (PHPJasper::class, $ result );
49- $ this ->assertEquals ('jasperstarter list_parameters "{input_fille}" ' , $ result ->output ());
50- }
5155
52- /*public function testCompileWithWrongInput()
53- {
54- $this->setExpectedExceptionFromAnnotation(\PHPJasper\Exception\InvalidInputFile::class);
56+ $ expected = strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ? '' : './ ' ;
57+ $ expected .= 'jasperstarter list_parameters "{input_fille}" ' ;
5558
56- $jasper = new PHPJasper( );
57- $jasper->compile(null);
58- }*/
59- /* public function testCompileWithWrongInput()
59+ $ this -> assertEquals ( $ expected , $ result -> output () );
60+ }
61+
62+ public function testCompileWithWrongInput ()
6063 {
61- $this->setExpectedException (\PHPJasper\Exception\InvalidInputFile::class);
64+ $ this ->expectException (\PHPJasper \Exception \InvalidInputFile::class);
6265
6366 $ jasper = new PHPJasper ();
67+
6468 $ jasper ->compile (null );
6569 }
6670
67- public function testCompile ()
71+ public function testCompileHelloWorld ()
6872 {
6973 $ jasper = new PHPJasper ();
74+
7075 $ result = $ jasper ->compile ('hello_world.jrxml ' );
7176
7277 $ this ->assertInstanceOf (PHPJasper::class, $ result );
73- $this->assertEquals('./jasperstarter compile "hello_world.jrxml"', $result->output());
74- }
7578
79+ if ($ this ->windows ) {
80+
81+ $ this ->assertEquals ('jasperstarter compile "hello_world.jrxml" ' , $ result ->output ());
82+
83+ }
84+ else {
85+
86+ $ this ->assertEquals ('./jasperstarter compile "hello_world.jrxml" ' , $ result ->output ());
87+ }
88+
89+ }
90+
7691 public function testExecuteWithoutCompile ()
7792 {
78- $this->setExpectedException (\PHPJasper\Exception\InvalidCommandExecutable::class);
93+ $ this ->expectException (\PHPJasper \Exception \InvalidCommandExecutable::class);
7994
8095 $ jasper = new PHPJasper ();
8196 $ jasper ->execute ();
8297 }
83-
98+
8499 public function testExecuteWithCompile ()
85100 {
86- $this->setExpectedException (\PHPJasper\Exception\ErrorCommandExecutable::class);
101+ $ this ->expectException (\PHPJasper \Exception \ErrorCommandExecutable::class);
87102
88103 $ jasper = new PHPJasper ();
89104 $ jasper ->compile ('hello_world.jrxml ' )->execute ();
90105 }
91106
107+ public function testExecute ()
108+ {
109+ $ jasper = new PHPJasper ();
110+ $ actual = $ jasper ->compile (__DIR__ . '/test.jrxml ' )->execute ();
111+
112+ $ this ->assertInternalType ('array ' , $ actual );
113+ }
114+
115+ public function testResourceDirectoryException ()
116+ {
117+ $ this ->expectException (\PHPJasper \Exception \InvalidResourceDirectory::class);
118+
119+ $ jasper = new PHPJasper ();
120+ $ jasperReflection = new \ReflectionClass (get_class ($ jasper ));
121+ $ property = $ jasperReflection ->getProperty ('pathExecutable ' );
122+ $ property ->setAccessible (true );
123+ $ property ->setValue ($ jasper ,'' );
124+
125+ $ jasper ->compile (__DIR__ . '/test.jrxml ' )->execute ();
126+ }
127+
92128 public function testListParametersWithWrongInput ()
93129 {
94- $this->setExpectedException (\PHPJasper\Exception\InvalidInputFile::class);
130+ $ this ->expectException (\PHPJasper \Exception \InvalidInputFile::class);
95131
96132 $ jasper = new PHPJasper ();
97133 $ jasper ->listParameters ('' );
98134 }
99-
135+
100136 public function testProcessWithWrongInput ()
101137 {
102- $this->setExpectedException (\PHPJasper\Exception\InvalidInputFile::class);
138+ $ this ->expectException (\PHPJasper \Exception \InvalidInputFile::class);
103139
104140 $ jasper = new PHPJasper ();
105- $jasper->process(0);
141+ $ jasper ->process (0 , "" );
106142 }
107-
143+
108144 public function testProcessWithWrongFormat ()
109145 {
110- $this->setExpectedException (\PHPJasper\Exception\InvalidFormat::class);
146+ $ this ->expectException (\PHPJasper \Exception \InvalidFormat::class);
111147
112148 $ jasper = new PHPJasper ();
113149 $ jasper ->process ('hello_world.jrxml ' , false , [
@@ -118,7 +154,6 @@ public function testProcessWithWrongFormat()
118154 public function testProcess ()
119155 {
120156 $ jasper = new PHPJasper ();
121- $this->assertInstanceOf(PHPJasper::class, $jasper->process('hello_world.jrxml'));
122- }*/
123-
157+ $ this ->assertInstanceOf (PHPJasper::class, $ jasper ->process ('hello_world.jrxml ' , "" ));
158+ }
124159}
0 commit comments