@@ -17,10 +17,12 @@ final class PHPJasperTest extends TestCase
17
17
private $ PHPJasper ;
18
18
private $ input ;
19
19
private $ output ;
20
+ protected $ windows ;
20
21
21
22
public function setUp ()
22
23
{
23
24
$ this ->PHPJasper = new PHPJasper ();
25
+ $ this ->windows = strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ? true : false ;
24
26
}
25
27
26
28
public function tearDown ()
@@ -38,76 +40,110 @@ public function testCompile()
38
40
$ result = $ this ->PHPJasper ->compile ('{input_file} ' , '{output_file} ' );
39
41
40
42
$ 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 ());
42
48
}
43
49
44
50
public function testListParameters ()
45
51
{
46
52
$ result = $ this ->PHPJasper ->listParameters ('{input_fille} ' );
47
53
48
54
$ this ->assertInstanceOf (PHPJasper::class, $ result );
49
- $ this ->assertEquals ('jasperstarter list_parameters "{input_fille}" ' , $ result ->output ());
50
- }
51
55
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}" ' ;
55
58
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 ()
60
63
{
61
- $this->setExpectedException (\PHPJasper\Exception\InvalidInputFile::class);
64
+ $ this ->expectException (\PHPJasper \Exception \InvalidInputFile::class);
62
65
63
66
$ jasper = new PHPJasper ();
67
+
64
68
$ jasper ->compile (null );
65
69
}
66
70
67
- public function testCompile ()
71
+ public function testCompileHelloWorld ()
68
72
{
69
73
$ jasper = new PHPJasper ();
74
+
70
75
$ result = $ jasper ->compile ('hello_world.jrxml ' );
71
76
72
77
$ this ->assertInstanceOf (PHPJasper::class, $ result );
73
- $this->assertEquals('./jasperstarter compile "hello_world.jrxml"', $result->output());
74
- }
75
78
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
+
76
91
public function testExecuteWithoutCompile ()
77
92
{
78
- $this->setExpectedException (\PHPJasper\Exception\InvalidCommandExecutable::class);
93
+ $ this ->expectException (\PHPJasper \Exception \InvalidCommandExecutable::class);
79
94
80
95
$ jasper = new PHPJasper ();
81
96
$ jasper ->execute ();
82
97
}
83
-
98
+
84
99
public function testExecuteWithCompile ()
85
100
{
86
- $this->setExpectedException (\PHPJasper\Exception\ErrorCommandExecutable::class);
101
+ $ this ->expectException (\PHPJasper \Exception \ErrorCommandExecutable::class);
87
102
88
103
$ jasper = new PHPJasper ();
89
104
$ jasper ->compile ('hello_world.jrxml ' )->execute ();
90
105
}
91
106
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
+
92
128
public function testListParametersWithWrongInput ()
93
129
{
94
- $this->setExpectedException (\PHPJasper\Exception\InvalidInputFile::class);
130
+ $ this ->expectException (\PHPJasper \Exception \InvalidInputFile::class);
95
131
96
132
$ jasper = new PHPJasper ();
97
133
$ jasper ->listParameters ('' );
98
134
}
99
-
135
+
100
136
public function testProcessWithWrongInput ()
101
137
{
102
- $this->setExpectedException (\PHPJasper\Exception\InvalidInputFile::class);
138
+ $ this ->expectException (\PHPJasper \Exception \InvalidInputFile::class);
103
139
104
140
$ jasper = new PHPJasper ();
105
- $jasper->process(0);
141
+ $ jasper ->process (0 , "" );
106
142
}
107
-
143
+
108
144
public function testProcessWithWrongFormat ()
109
145
{
110
- $this->setExpectedException (\PHPJasper\Exception\InvalidFormat::class);
146
+ $ this ->expectException (\PHPJasper \Exception \InvalidFormat::class);
111
147
112
148
$ jasper = new PHPJasper ();
113
149
$ jasper ->process ('hello_world.jrxml ' , false , [
@@ -118,7 +154,6 @@ public function testProcessWithWrongFormat()
118
154
public function testProcess ()
119
155
{
120
156
$ 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
+ }
124
159
}
0 commit comments