-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test cli * increase coverage
- Loading branch information
Showing
8 changed files
with
140 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ clover.xml | |
/tmp | ||
sonar-project.properties | ||
.scannerwork | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ class Options | |
/** | ||
* @var array | ||
*/ | ||
private $arguments; | ||
private $arguments = []; | ||
|
||
/** | ||
* @var array | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Tests\Sonar; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Tests\Sonar\Helpers\TestServer; | ||
use Lead\Dir\Dir; | ||
|
||
final class CliTest extends TestCase | ||
{ | ||
public function test_sonar_scanner_command_runs_properly() | ||
{ | ||
$entrypoint = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'sonar-scanner'; | ||
$server = new TestServer(); | ||
|
||
// Start the mockup server | ||
$server->start(); | ||
|
||
// Entrypoint must exist | ||
$this->assertTrue(file_exists($entrypoint)); | ||
|
||
$params = ' -X -Dsonar.verbose=true -Dsonar.host.url=' . $server->getBaseUrl(); | ||
$command = 'php ' . $entrypoint . $params; | ||
|
||
exec($command, $output); | ||
|
||
// SonarQube recieves expected parameters | ||
$this->assertStringContainsString($params, $output[2]); | ||
} | ||
|
||
public function test_expected_scanner_versions() | ||
{ | ||
$expectedScannerVersions = 3; | ||
|
||
$zipfiles = Dir::scan( | ||
__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'scanners', | ||
[ | ||
'type' => 'file', | ||
'skipDots' => true, | ||
'leavesOnly' => true, | ||
'followSymlinks' => true, | ||
'recursive' => true, | ||
] | ||
); | ||
|
||
$this->assertCount($expectedScannerVersions, $zipfiles); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Tests\Sonar\Helpers; | ||
|
||
use Creativestyle\AppHttpServerMock\Server; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class TestServer extends Server | ||
{ | ||
protected function registerRequestHandlers() | ||
{ | ||
$this->registerRequestHandler(['GET','PUT', 'POST'], '/', function (Request $request) { | ||
return new Response('TODO'); | ||
}); | ||
|
||
$this->registerRequestHandler(['GET','PUT', 'POST'], '/batch/index', function (Request $request) { | ||
$xml = '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'; | ||
$xml .= '<mynode><content>TODO</content></mynode>'; | ||
|
||
$response = new Response($xml); | ||
$response->headers->set('Content-Type', 'xml'); | ||
|
||
return $response; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Tests\Sonar; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class OptionsTest extends TestCase | ||
{ | ||
public function test_arguments_are_parsed() | ||
{ | ||
$options = new \Sonar\Options(__DIR__); | ||
|
||
$options->parse(['this one will be deleted', '-Dsonar.prop=something']); | ||
|
||
// make sure other methods can be called | ||
$options->setSourceManagerBranch('foo'); | ||
$options->setEdition(123); | ||
|
||
$this->assertStringContainsString( | ||
$options->cli(), | ||
'-Dsonar.prop=something -Dsonar.sources=' . __DIR__ . ' -Dsonar.exclusions="vendor/**, node_modules/**, .scannerwork/**"' | ||
); | ||
} | ||
|
||
public function test_arguments_come_from_composer_json() | ||
{ | ||
$content = [ | ||
'name' => 'john/doe', | ||
'description' => 'test' | ||
]; | ||
|
||
$options = new \Sonar\Options(__DIR__); | ||
$options->setComposerConfiguration($content); | ||
$options->parse([]); | ||
|
||
$this->assertStringContainsString( | ||
$options->cli(), | ||
'-Dsonar.projectKey=john_doe -Dsonar.projectName=doe -Dsonar.projectDescription="test" -Dsonar.sources=' . __DIR__ . ' -Dsonar.exclusions="vendor/**, node_modules/**, .scannerwork/**"' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Tests\Sonar; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ScannerTest extends TestCase | ||
{ | ||
public function test_sonar_scanner_app_runs_properly() | ||
{ | ||
$app = new \Sonar\Scanner(); | ||
$options = new \Sonar\Options(getcwd()); | ||
|
||
$app->run($options); | ||
|
||
// If we arrive here, no exception has been thrown | ||
$this->assertTrue(true); | ||
} | ||
} |