Skip to content

Commit 96f7d14

Browse files
authored
Merge pull request #71 from PHPJasper/master
merge to refactoring
2 parents e0ad9a7 + d951d44 commit 96f7d14

File tree

5 files changed

+479
-31
lines changed

5 files changed

+479
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,4 @@ MIT
350350

351351
## [Contribute](https://github.com/PHPJasper/phpjasper/blob/master/CONTRIBUTING.md)
352352

353-
Contribute to the community PHP, make a fork!!
353+
Contribute to the community PHP, make a fork!

phpunit.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
<filter>
1414
<whitelist>
15-
<directory>src/PHPJasper</directory>
16-
<directory>src/JasperStarter</directory>
15+
<directory suffix=".php">./src</directory>
1716
</whitelist>
1817
</filter>
1918

src/PHPJasper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public function __construct()
5252
* @return $this
5353
* @throws Exception\InvalidInputFile
5454
*/
55-
public function compile(string $input, string $output = '')
55+
public function compile($input, string $output = '')
5656
{
57-
if (!$input) {
57+
if ( !$input ) {
5858
throw new \PHPJasper\Exception\InvalidInputFile();
5959
}
6060

tests/PHPJasper/PHPJasperTest.php

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)