Skip to content

Commit

Permalink
Merge pull request #2 from violinist-dev/feat/integration-tests
Browse files Browse the repository at this point in the history
Feat/integration tests
  • Loading branch information
eiriksm committed Feb 2, 2019
2 parents a7929c9 + 01ffdab commit 58c809a
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
composer.lock
!/tests/assets/projects/*/composer.lock
vendor
data
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"Violinist\\SymfonyCloudSecurityChecker\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Violinist\\SymfonyCloudSecurityChecker\\Tests\\": "tests"
}
},
"require": {
"symfony/process": "^2.7 || ^3.0 || ^4.0"
},
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<testsuites>
<testsuite name="Cloud checker Test Suite">
<directory>tests/Unit</directory>
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
<logging>
Expand Down
5 changes: 4 additions & 1 deletion src/SecurityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class SecurityChecker
{

protected $symfonyCommand = 'symfony';

protected $processFactory;

public function checkDirectory($dir)
Expand All @@ -21,7 +24,7 @@ public function checkDirectory($dir)
$process = $this->getProcess($command);
$process->run();
}
$command = sprintf('symfony security:check --dir=%s --format=json', $dir);
$command = sprintf('%s security:check --dir=%s --format=json', $this->symfonyCommand, $dir);
$process = $this->getProcess($command);
$process->run();
$string = $process->getOutput();
Expand Down
23 changes: 23 additions & 0 deletions tests/Integration/IntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Violinist\SymfonyCloudSecurityChecker\Tests\Integration;

use PHPUnit\Framework\TestCase;

class IntegrationTest extends TestCase
{
public function testInsecure()
{
$checker = new TestSecurityChecker();
$result = $checker->checkDirectory(__DIR__ . '/../assets/projects/unsecure');
$this->assertTrue(count($result) > 0);
$this->assertEquals('CVE-2010-4879', $result["dompdf/dompdf"]["advisories"][0]["cve"]);
}

public function testSecure()
{
$checker = new TestSecurityChecker();
$result = $checker->checkDirectory(__DIR__ . '/../assets/projects/secure');
$this->assertTrue(count($result) === 0);
}
}
14 changes: 14 additions & 0 deletions tests/Integration/TestSecurityChecker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Violinist\SymfonyCloudSecurityChecker\Tests\Integration;

use Violinist\SymfonyCloudSecurityChecker\SecurityChecker;

class TestSecurityChecker extends SecurityChecker
{
public function __construct()
{
$os = strtolower(PHP_OS);
$this->symfonyCommand = __DIR__ . '/../assets/bin/symfony-' . $os;
}
}
Binary file added tests/assets/bin/symfony-darwin
Binary file not shown.
Binary file added tests/assets/bin/symfony-linux
Binary file not shown.
65 changes: 65 additions & 0 deletions tests/assets/projects/secure/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions tests/assets/projects/unsecure/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 58c809a

Please sign in to comment.