Skip to content

Commit

Permalink
Merge pull request #71 from PHPJasper/master
Browse files Browse the repository at this point in the history
merge to refactoring
  • Loading branch information
geekcom authored Oct 10, 2017
2 parents e0ad9a7 + d951d44 commit 96f7d14
Show file tree
Hide file tree
Showing 5 changed files with 479 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,4 @@ MIT

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

Contribute to the community PHP, make a fork!!
Contribute to the community PHP, make a fork!
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

<filter>
<whitelist>
<directory>src/PHPJasper</directory>
<directory>src/JasperStarter</directory>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>

Expand Down
4 changes: 2 additions & 2 deletions src/PHPJasper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function __construct()
* @return $this
* @throws Exception\InvalidInputFile
*/
public function compile(string $input, string $output = '')
public function compile($input, string $output = '')
{
if (!$input) {
if ( !$input ) {
throw new \PHPJasper\Exception\InvalidInputFile();
}

Expand Down
87 changes: 61 additions & 26 deletions tests/PHPJasper/PHPJasperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ final class PHPJasperTest extends TestCase
private $PHPJasper;
private $input;
private $output;
protected $windows;

public function setUp()
{
$this->PHPJasper = new PHPJasper();
$this->windows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? true : false;
}

public function tearDown()
Expand All @@ -38,76 +40,110 @@ public function testCompile()
$result = $this->PHPJasper->compile('{input_file}', '{output_file}');

$this->assertInstanceOf(PHPJasper::class, $result);
$this->assertEquals('jasperstarter compile "{input_file}" -o "{output_file}"', $result->output());

$expected = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? '' : './';
$expected .= 'jasperstarter compile "{input_file}" -o "{output_file}"';

$this->assertEquals($expected, $result->output());
}

public function testListParameters()
{
$result = $this->PHPJasper->listParameters('{input_fille}');

$this->assertInstanceOf(PHPJasper::class, $result);
$this->assertEquals('jasperstarter list_parameters "{input_fille}"', $result->output());
}

/*public function testCompileWithWrongInput()
{
$this->setExpectedExceptionFromAnnotation(\PHPJasper\Exception\InvalidInputFile::class);
$expected = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? '' : './';
$expected .= 'jasperstarter list_parameters "{input_fille}"';

$jasper = new PHPJasper();
$jasper->compile(null);
}*/
/*public function testCompileWithWrongInput()
$this->assertEquals($expected, $result->output());
}

public function testCompileWithWrongInput()
{
$this->setExpectedException(\PHPJasper\Exception\InvalidInputFile::class);
$this->expectException(\PHPJasper\Exception\InvalidInputFile::class);

$jasper = new PHPJasper();

$jasper->compile(null);
}

public function testCompile()
public function testCompileHelloWorld()
{
$jasper = new PHPJasper();

$result = $jasper->compile('hello_world.jrxml');

$this->assertInstanceOf(PHPJasper::class, $result);
$this->assertEquals('./jasperstarter compile "hello_world.jrxml"', $result->output());
}

if($this->windows) {

$this->assertEquals('jasperstarter compile "hello_world.jrxml"', $result->output());

}
else {

$this->assertEquals('./jasperstarter compile "hello_world.jrxml"', $result->output());
}

}

public function testExecuteWithoutCompile()
{
$this->setExpectedException(\PHPJasper\Exception\InvalidCommandExecutable::class);
$this->expectException(\PHPJasper\Exception\InvalidCommandExecutable::class);

$jasper = new PHPJasper();
$jasper->execute();
}
public function testExecuteWithCompile()
{
$this->setExpectedException(\PHPJasper\Exception\ErrorCommandExecutable::class);
$this->expectException(\PHPJasper\Exception\ErrorCommandExecutable::class);

$jasper = new PHPJasper();
$jasper->compile('hello_world.jrxml')->execute();
}

public function testExecute()
{
$jasper = new PHPJasper();
$actual = $jasper->compile(__DIR__ . '/test.jrxml')->execute();

$this->assertInternalType('array', $actual);
}

public function testResourceDirectoryException()
{
$this->expectException(\PHPJasper\Exception\InvalidResourceDirectory::class);

$jasper = new PHPJasper();
$jasperReflection = new \ReflectionClass(get_class($jasper));
$property = $jasperReflection->getProperty('pathExecutable');
$property->setAccessible(true);
$property->setValue($jasper,'');

$jasper->compile(__DIR__ . '/test.jrxml')->execute();
}

public function testListParametersWithWrongInput()
{
$this->setExpectedException(\PHPJasper\Exception\InvalidInputFile::class);
$this->expectException(\PHPJasper\Exception\InvalidInputFile::class);

$jasper = new PHPJasper();
$jasper->listParameters('');
}
public function testProcessWithWrongInput()
{
$this->setExpectedException(\PHPJasper\Exception\InvalidInputFile::class);
$this->expectException(\PHPJasper\Exception\InvalidInputFile::class);

$jasper = new PHPJasper();
$jasper->process(0);
$jasper->process(0, "");
}
public function testProcessWithWrongFormat()
{
$this->setExpectedException(\PHPJasper\Exception\InvalidFormat::class);
$this->expectException(\PHPJasper\Exception\InvalidFormat::class);

$jasper = new PHPJasper();
$jasper->process('hello_world.jrxml', false, [
Expand All @@ -118,7 +154,6 @@ public function testProcessWithWrongFormat()
public function testProcess()
{
$jasper = new PHPJasper();
$this->assertInstanceOf(PHPJasper::class, $jasper->process('hello_world.jrxml'));
}*/

$this->assertInstanceOf(PHPJasper::class, $jasper->process('hello_world.jrxml', ""));
}
}
Loading

0 comments on commit 96f7d14

Please sign in to comment.