Skip to content

merge to refactoring #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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