Skip to content

Commit

Permalink
Tests: fix unit and regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
masicek committed Jun 26, 2012
1 parent 16a8fa6 commit 15ee942
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 90 deletions.
5 changes: 3 additions & 2 deletions Tools/Tests/Regression/TestsGenerator/TestsGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ public function test()
unlink($this->setDirSep($tmp . '/' . $file));
}
}
unlink($this->setDirSep($tmp . '/manyElements.xml'));
unlink($this->setDirSep($tmp . '/manyNewElements.xml'));
unlink($this->setDirSep($tmp . '/modify-element/manyElements.xml'));
unlink($this->setDirSep($tmp . '/modify-element/manyNewElements.xml'));
rmdir($this->setDirSep($tmp . '/modify-element'));
rmdir($tmp);
}

Expand Down
4 changes: 3 additions & 1 deletion Tools/Tests/Regression/TestsRunner/TestsRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public function test()

$report = preg_replace('/Time="[^"]+"/', 'Time="..."', $report);
$report = preg_replace('/Memory="[^"]+"/', 'Memory="..."', $report);
$report = preg_replace('/-[0-9]{10}-[0-9]{6}.xml"/', '-..........-.......xml"', $report);
$report = preg_replace('/-[0-9]{10}-[0-9]{6}.xml/', '-..........-.......xml', $report);
$report = str_replace(__DIR__, '__PATH__', $report);
$report = str_replace(str_replace('\\', '/', __DIR__), '__PATH__', $report);
$this->assertXmlStringEqualsXmlFile($reportsExpected, $report);

// remove generated report
Expand Down
66 changes: 33 additions & 33 deletions Tools/Tests/Regression/TestsRunner/reportsExpectedLinux.xml

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions Tools/Tests/Regression/TestsRunner/reportsExpectedWindows.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<reports>
<global>
<processors>
<processor name="processor1" fullName="Processor 1" firstInformation="First information 1" secondInformation="Second information 1" thirdInformation="Third information 1" />
<processor name="processor2" fullName="Processor 2" firstInformation="First information 2" />
<processor name="processor3" fullName="Processor 3" firstInformation="First information 3" secondInformation="Second information 3" />
<processor name="processor1" fullName="Processor 1" firstInformation="First information 1" kernel="kern1" secondInformation="Second information 1" thirdInformation="Third information 1" />
<processor name="processor2" fullName="Processor 2" firstInformation="First information 2" kernel="kern2" />
<processor name="processor3" fullName="Processor 3" firstInformation="First information 3" kernel="kern1" secondInformation="Second information 3" />
</processors>
</global>
<tests>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public function testGetTestFilesPaths()
$generator = \Mockery::mock('\XSLTBenchmarking\TestsGenerator\XmlGenerator()');
$generator->shouldReceive('setDriver')->twice()->with('easy');
$generator->shouldReceive('generate')->once()->with(
$this->setDirSep(__DIR__ . '/manyElements.xml'),
$this->setDirSep(__DIR__ . '/modify-element/manyElements.xml'),
__DIR__,
array('testName' => 20, 'testName2' => 3)
);
$generator->shouldReceive('generate')->once()->with(
$this->setDirSep(__DIR__ . '/manyNewElements.xml'),
$this->setDirSep(__DIR__ . '/modify-element/manyNewElements.xml'),
__DIR__,
array('testNewName' => 20, 'testName2' => 3)
);
Expand All @@ -90,7 +90,7 @@ public function testGetTestFilesPaths()
array(
$this->setDirSep(__DIR__ . '/oneElement.xml') => $this->setDirSep(__DIR__ . '/oneNewElement.xml'),
$this->setDirSep(__DIR__ . '/twoElements.xml') => $this->setDirSep(__DIR__ . '/twoNewElements.xml'),
$this->setDirSep(__DIR__ . '/manyElements.xml') => $this->setDirSep(__DIR__ . '/manyNewElements.xml'),
$this->setDirSep(__DIR__ . '/modify-element/manyElements.xml') => $this->setDirSep(__DIR__ . '/modify-element/manyNewElements.xml'),
),
$this->driver->getTestFilesPaths('Rename')
);
Expand All @@ -99,10 +99,12 @@ public function testGetTestFilesPaths()
array(
$this->setDirSep(__DIR__ . '/oneElement.xml') => $this->setDirSep(__DIR__ . '/zeroElement.xml'),
$this->setDirSep(__DIR__ . '/twoElements.xml') => $this->setDirSep(__DIR__ . '/zeroElement.xml'),
$this->setDirSep(__DIR__ . '/manyElements.xml') => $this->setDirSep(__DIR__ . '/zeroElement.xml'),
$this->setDirSep(__DIR__ . '/modify-element/manyElements.xml') => $this->setDirSep(__DIR__ . '/zeroElement.xml'),
),
$this->driver->getTestFilesPaths('Remove')
);

rmdir($this->setDirSep(__DIR__ . '/modify-element'));
}


Expand Down
2 changes: 1 addition & 1 deletion Tools/Tests/Unit/TestsRunner/Controlor/IsSameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testPlainTextIsNotSame()
public function testXmlIsSame()
{
$file1 = $this->setDirSep(__DIR__ . '/file1.xml');
$file2 = $this->setDirSep(__DIR__ . '/file2.txt');
$file2 = $this->setDirSep(__DIR__ . '/file2.xml');

$xml1 = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL .
' <root rootAttribute1 = "xxx zzz" rootAttribute2="yyy">' . PHP_EOL .
Expand Down
73 changes: 60 additions & 13 deletions Tools/Tests/Unit/TestsRunner/Processors/Processor/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,20 @@ public function testError()
$filesAfter = scandir(__DIR__);

$this->assertEquals($filesBefore, $filesAfter);
$this->assertEquals('Test error', $return);
$this->assertEquals('Output file was not be generated (output); Test error', $return);
}


public function testXmlAndXsltSeparately()
{
$this->markTestSkippedCondition();

$outputPath = $this->setDirSep(__DIR__ . '/output.xml');
$outputPath_1 = $this->setDirSep(__DIR__ . '/output-1.xml');
$outputPath_2 = $this->setDirSep(__DIR__ . '/output-2.xml');

$processorOK = $this->getMock('\XSLTBenchmarking\TestsRunner\AProcessorDriver', array('getCommandTemplate', 'getFullName', 'getKernel', 'isTemplateSetInInput', 'getBeforeCommandTemplate', 'getAfterCommandTemplate', 'isAvailable'), array(), '', FALSE);
$processorOK->expects($this->once())->method('getCommandTemplate')->will($this->returnValue('php -r "sleep(1);"'));
$processorOK->expects($this->once())->method('getCommandTemplate')->will($this->returnValue('php -r "file_put_contents(\'' . $outputPath . '\', \'generated data\'); sleep(1);"'));
$processorOK->expects($this->never())->method('getFullName')->will($this->returnValue(''));
$processorOK->expects($this->never())->method('getKernel')->will($this->returnValue(''));
$processorOK->expects($this->once())->method('isTemplateSetInInput')->will($this->returnValue(FALSE));
Expand All @@ -218,7 +222,7 @@ public function testXmlAndXsltSeparately()
$processorOK->expects($this->never())->method('isAvailable')->will($this->returnValue(TRUE));

$processorError = $this->getMock('\XSLTBenchmarking\TestsRunner\AProcessorDriver', array('getCommandTemplate', 'getFullName', 'getKernel', 'isTemplateSetInInput', 'getBeforeCommandTemplate', 'getAfterCommandTemplate', 'isAvailable'), array(), '', FALSE);
$processorError->expects($this->never())->method('getCommandTemplate')->will($this->returnValue('php -r "echo \'Test error\';" > [ERROR]'));
$processorError->expects($this->never())->method('getCommandTemplate')->will($this->returnValue('php -r "file_put_contents(\'' . $outputPath . '\', \'generated data\'); echo \'Test error\';" > [ERROR]'));
$processorError->expects($this->never())->method('getFullName')->will($this->returnValue(''));
$processorError->expects($this->never())->method('getKernel')->will($this->returnValue(''));
$processorError->expects($this->never())->method('isTemplateSetInInput')->will($this->returnValue(FALSE));
Expand All @@ -234,12 +238,22 @@ public function testXmlAndXsltSeparately()
$this->setPropertyValue($this->processor, 'available', $available);

$memoryUsage = $this->getMock('\XSLTBenchmarking\TestsRunner\MemoryUsage', array('run', 'get'), array(), '', FALSE);
$memoryUsage->expects($this->exactly(3))->method('run')->with('php -r "sleep(1);"')->will($this->returnValue('php -r "sleep(1);"'));
$memoryUsage->expects($this->exactly(3))->method('run')
->with(
$this->logicalOr(
$this->equalTo('php -r "file_put_contents(\'' . $outputPath . '\', \'generated data\'); sleep(1);"'),
$this->equalTo('php -r "file_put_contents(\'' . $outputPath_1 . '\', \'generated data\'); sleep(1);"'),
$this->equalTo('php -r "file_put_contents(\'' . $outputPath_2 . '\', \'generated data\'); sleep(1);"')
)
)
->will($this->returnCallback(function ($command) {return $command;}));
$memoryUsage->expects($this->exactly(3))->method('get')->will($this->returnValue('123456789'));
$this->setPropertyValue($this->processor, 'memoryUsage', $memoryUsage);

$filesBefore = scandir(__DIR__);
$return = $this->processor->run('processorOK', __FILE__, $this->setDirSep(__DIR__ . '/FixtureRun/input.xml'), 'output', 3);
$return = $this->processor->run('processorOK', __FILE__, $this->setDirSep(__DIR__ . '/FixtureRun/input.xml'), $outputPath, 3);
// remove generated file
unlink($outputPath);
$filesAfter = scandir(__DIR__);

$this->assertEquals($filesBefore, $filesAfter);
Expand Down Expand Up @@ -270,8 +284,12 @@ public function testXsltInXml()
{
$this->markTestSkippedCondition();

$outputPath = $this->setDirSep(__DIR__ . '/output.xml');
$outputPath_1 = $this->setDirSep(__DIR__ . '/output-1.xml');
$outputPath_2 = $this->setDirSep(__DIR__ . '/output-2.xml');

$processorOK = $this->getMock('\XSLTBenchmarking\TestsRunner\AProcessorDriver', array('getCommandTemplate', 'getFullName', 'getKernel', 'isTemplateSetInInput', 'getBeforeCommandTemplate', 'getAfterCommandTemplate', 'isAvailable'), array(), '', FALSE);
$processorOK->expects($this->once())->method('getCommandTemplate')->will($this->returnValue('php -r "sleep(1);"'));
$processorOK->expects($this->once())->method('getCommandTemplate')->will($this->returnValue('php -r "file_put_contents(\'' . $outputPath . '\', \'generated data\'); sleep(1);"'));
$processorOK->expects($this->never())->method('getFullName')->will($this->returnValue(''));
$processorOK->expects($this->never())->method('getKernel')->will($this->returnValue(''));
$processorOK->expects($this->once())->method('isTemplateSetInInput')->will($this->returnValue(TRUE));
Expand All @@ -280,7 +298,7 @@ public function testXsltInXml()
$processorOK->expects($this->never())->method('isAvailable')->will($this->returnValue(TRUE));

$processorError = $this->getMock('\XSLTBenchmarking\TestsRunner\AProcessorDriver', array('getCommandTemplate', 'getFullName', 'getKernel', 'isTemplateSetInInput', 'getBeforeCommandTemplate', 'getAfterCommandTemplate', 'isAvailable'), array(), '', FALSE);
$processorError->expects($this->never())->method('getCommandTemplate')->will($this->returnValue('php -r "echo \'Test error\';" > [ERROR]'));
$processorError->expects($this->never())->method('getCommandTemplate')->will($this->returnValue('php -r "file_put_contents(\'' . $outputPath . '\', \'generated data\'); echo \'Test error\';" > [ERROR]'));
$processorError->expects($this->never())->method('getFullName')->will($this->returnValue(''));
$processorError->expects($this->never())->method('getKernel')->will($this->returnValue(''));
$processorError->expects($this->never())->method('isTemplateSetInInput')->will($this->returnValue(TRUE));
Expand All @@ -296,12 +314,22 @@ public function testXsltInXml()
$this->setPropertyValue($this->processor, 'available', $available);

$memoryUsage = $this->getMock('\XSLTBenchmarking\TestsRunner\MemoryUsage', array('run', 'get'), array(), '', FALSE);
$memoryUsage->expects($this->exactly(3))->method('run')->with('php -r "sleep(1);"')->will($this->returnValue('php -r "sleep(1);"'));
$memoryUsage->expects($this->exactly(3))->method('run')
->with(
$this->logicalOr(
$this->equalTo('php -r "file_put_contents(\'' . $outputPath . '\', \'generated data\'); sleep(1);"'),
$this->equalTo('php -r "file_put_contents(\'' . $outputPath_1 . '\', \'generated data\'); sleep(1);"'),
$this->equalTo('php -r "file_put_contents(\'' . $outputPath_2 . '\', \'generated data\'); sleep(1);"')
)
)
->will($this->returnCallback(function ($command) {return $command;}));
$memoryUsage->expects($this->exactly(3))->method('get')->will($this->returnValue('123456789'));
$this->setPropertyValue($this->processor, 'memoryUsage', $memoryUsage);

$filesBefore = scandir(__DIR__);
$return = $this->processor->run('processorOK', __FILE__, $this->setDirSep(__DIR__ . '/FixtureRun/input.xml'), 'output', 3);
$return = $this->processor->run('processorOK', __FILE__, $this->setDirSep(__DIR__ . '/FixtureRun/input.xml'), $outputPath, 3);
// detele generated file
unlink($outputPath);
$filesAfter = scandir(__DIR__);

$this->assertNotEquals($filesBefore, $filesAfter);
Expand Down Expand Up @@ -333,6 +361,7 @@ public function testXsltInXml()
$this->assertTrue(is_array($returnMemory));
$this->assertEquals(3, count($returnMemory));


// all times are greated then one second
$this->assertGreaterOneSecondInMicrotime($returnTimes[0]);
$this->assertGreaterOneSecondInMicrotime($returnTimes[1]);
Expand All @@ -352,9 +381,13 @@ public function testBeforeAndAfterCommand()
$controleOutputPath = $this->setDirSep(__DIR__ . '/controleOutput');
file_put_contents($controleOutputPath, '');

$outputPath = $this->setDirSep(__DIR__ . '/output.xml');
$outputPath_1 = $this->setDirSep(__DIR__ . '/output-1.xml');
$outputPath_2 = $this->setDirSep(__DIR__ . '/output-2.xml');

$processorOK = $this->getMock('\XSLTBenchmarking\TestsRunner\AProcessorDriver', array('getCommandTemplate', 'getFullName', 'getKernel', 'isTemplateSetInInput', 'getBeforeCommandTemplate', 'getAfterCommandTemplate', 'isAvailable'), array(), '', FALSE);
$processorOK->expects($this->once())->method('getCommandTemplate')->will($this->returnValue(
'php -r "file_put_contents(\'' . $controleOutputPath . '\', file_get_contents(\'' . $controleOutputPath . '\') . \'Test command;\');"'
'php -r "file_put_contents(\'' . $controleOutputPath . '\', file_get_contents(\'' . $controleOutputPath . '\') . \'Test command;\'); file_put_contents(\'[OUTPUT]\', \'generated output\');"'
));
$processorOK->expects($this->never())->method('getFullName')->will($this->returnValue(''));
$processorOK->expects($this->never())->method('getKernel')->will($this->returnValue(''));
Expand Down Expand Up @@ -384,13 +417,26 @@ public function testBeforeAndAfterCommand()
$this->setPropertyValue($this->processor, 'available', $available);

$memoryUsage = $this->getMock('\XSLTBenchmarking\TestsRunner\MemoryUsage', array('run', 'get'), array(), '', FALSE);

$memoryUsage->expects($this->exactly(3))->method('run')
->with('php -r "file_put_contents(\'' . $controleOutputPath . '\', file_get_contents(\'' . $controleOutputPath . '\') . \'Test command;\');"')
->will($this->returnValue('php -r "file_put_contents(\'' . $controleOutputPath . '\', file_get_contents(\'' . $controleOutputPath . '\') . \'Test command;\');"'));
->with(
$this->logicalOr(
$this->equalTo('php -r "file_put_contents(\'' . $controleOutputPath . '\', file_get_contents(\'' . $controleOutputPath . '\') . \'Test command;\'); file_put_contents(\'' . $outputPath . '\', \'generated output\');"'),
$this->equalTo('php -r "file_put_contents(\'' . $controleOutputPath . '\', file_get_contents(\'' . $controleOutputPath . '\') . \'Test command;\'); file_put_contents(\'' . $outputPath_1 . '\', \'generated output\');"'),
$this->equalTo('php -r "file_put_contents(\'' . $controleOutputPath . '\', file_get_contents(\'' . $controleOutputPath . '\') . \'Test command;\'); file_put_contents(\'' . $outputPath_2 . '\', \'generated output\');"')
)
)
->will($this->returnCallback(function ($command) {return $command;}));
$memoryUsage->expects($this->exactly(3))->method('get')->will($this->returnValue('123456789'));
$this->setPropertyValue($this->processor, 'memoryUsage', $memoryUsage);

$return = $this->processor->run('processorOK', __FILE__, $this->setDirSep(__DIR__ . '/FixtureRun/input.xml'), 'output', 3);
$return = $this->processor->run(
'processorOK',
__FILE__,
$this->setDirSep(__DIR__ . '/FixtureRun/input.xml'),
$this->setDirSep(__DIR__ . '/output.xml'),
3
);

$this->assertStringEqualsFile($controleOutputPath,
'Test of before command;Test command;Test of after command;' .
Expand All @@ -399,6 +445,7 @@ public function testBeforeAndAfterCommand()
);

unlink($controleOutputPath);
unlink($outputPath);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function generate($templatePath, $outputPath, array $settings)
try {
$this->display($templatePath);
} catch (\Exception $e) {
throw new \XSLTBenchmarking\GenerateTemplateException('Cannot generate template by Smarty Driver', 0, $e);
throw new \XSLTBenchmarking\GenerateTemplateException('Cannot generate template by Smarty Driver (' . $e->getMessage() . ')', 0, $e);
}
$content = ob_get_clean();

Expand Down

0 comments on commit 15ee942

Please sign in to comment.