Skip to content

Commit b2705db

Browse files
authored
Merge pull request #1 from Cheburon/functional-test
Functional test
2 parents 200c0e3 + 6c9fdae commit b2705db

13 files changed

+172
-0
lines changed

phpunit.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<phpunit bootstrap="tests/phpunit.php" colors="true">
2+
</phpunit>

tests/Base.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
class Base extends \PHPUnit_Framework_TestCase {
6+
7+
}

tests/ObfuscateTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
class ObfuscateTest extends Base {
6+
7+
const AFTER_PATH = "/after";
8+
const BEFORE_PATH = "/before";
9+
const EXPECTED_PATH = "/expected";
10+
11+
protected function tearDown() {
12+
$files = glob(__DIR__ . self::AFTER_PATH . "/*");
13+
foreach ($files as $file) {
14+
unlink($file);
15+
}
16+
rmdir(__DIR__ . self::AFTER_PATH);
17+
}
18+
19+
public function testObfuscate() {
20+
shell_exec("./bin/obfuscate obfuscate " . __DIR__ . self::BEFORE_PATH . " " . __DIR__ . self::AFTER_PATH . " --config=" . __DIR__ . "/config.yml");
21+
$expectedFileNames = scandir(__DIR__ . self::EXPECTED_PATH);
22+
foreach ($expectedFileNames as $expectedFileName) {
23+
if ($expectedFileName === '.' || $expectedFileName === '..') {
24+
continue;
25+
}
26+
if (!file_exists(__DIR__ . self::AFTER_PATH . "/" . $expectedFileName)) {
27+
$this->fail("{$expectedFileName} not found");
28+
}
29+
$this->assertEquals(file_get_contents(__DIR__ . self::EXPECTED_PATH . "/" . $expectedFileName), file_get_contents(__DIR__ . self::AFTER_PATH . "/" . $expectedFileName));
30+
}
31+
}
32+
}

tests/before/Functions.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
4+
function functionA($argumentVar) {
5+
$localVarA = 3;
6+
return $argumentVar + $localVarA;
7+
}
8+
9+
function functionB() {
10+
$localVarB = 5;
11+
return functionB($localVarB);
12+
}
13+
14+
$localVarMainA = "local value";
15+
$localVarMainB = functionB();
16+
$localVarMainA = functionA($localVarMainA);

tests/before/MultipleClasses.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
class FirstClass {
4+
5+
protected $_protectedProperty;
6+
public $publicProperty;
7+
8+
protected function _protectedMethod() {
9+
echo "This is protected method of first class";
10+
}
11+
12+
public function publicMethod() {
13+
echo "This is public method of first class";
14+
}
15+
}
16+
17+
class SecondClass extends FirstClass {
18+
19+
private $_privateProperty;
20+
21+
protected function _protectedMethod() {
22+
parent::_protectedMethod();
23+
echo "This is protected method of second class";
24+
$this->_privateProperty = parent::$_protectedProperty;
25+
}
26+
27+
public function publicMethod() {
28+
parent::publicMethod();
29+
echo "This is public method of second class";
30+
$this->_privateProperty = parent::$publicProperty;
31+
}
32+
}
33+
34+
class ThirdClass {
35+
public function __construct(SecondClass $secondObject) {
36+
$secondObject->publicMethod();
37+
}
38+
}

tests/before/Namespaces.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace namespaceA;
4+
5+
class classA {
6+
7+
}
8+
9+
namespace namespaceB;
10+
11+
use namespaceA;
12+
13+
class classB {
14+
private $_objectA;
15+
16+
public function __construct() {
17+
$this->_objectA = new namespaceA\classA();
18+
}
19+
}

tests/before/SimpleClass.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
class SimpleClass {
4+
5+
private $_privateProperty;
6+
protected $_protectedProperty;
7+
public $publicProperty;
8+
9+
private function _privateMethod() {
10+
$localVar = "test";
11+
$this->_privateProperty = $localVar;
12+
$this->_protectedProperty = $localVar;
13+
$this->publicProperty = $localVar;
14+
}
15+
16+
protected function _protectedMethod() {
17+
$localVar = "test";
18+
$this->_privateProperty = $localVar;
19+
$this->_protectedProperty = $localVar;
20+
$this->publicProperty = $localVar;
21+
}
22+
23+
public function publicMethod() {
24+
$localVar = "test";
25+
$this->_privateProperty = $localVar;
26+
$this->_protectedProperty = $localVar;
27+
$this->publicProperty = $localVar;
28+
$this->_protectedMethod();
29+
$this->_privateMethod();
30+
}
31+
}
32+
33+
$simpleObject = new SimpleClass();
34+
$simpleObject->publicMethod();

tests/config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
3+
# String scrambler
4+
obfuscator.scrambler:
5+
class: Naneau\Obfuscator\StringScrambler
6+
arguments:
7+
- 'salt'

tests/expected/Functions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
function functionA($spc5a579) { $sp0edd21 = 3; return $spc5a579 + $sp0edd21; } function functionB() { $sp6a6761 = 5; return functionB($sp6a6761); } $sp8851f9 = 'local value'; $sp7f60ff = functionB(); $sp8851f9 = functionA($sp8851f9);

tests/expected/MultipleClasses.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
class FirstClass { protected $_protectedProperty; public $publicProperty; protected function _protectedMethod() { echo 'This is protected method of first class'; } public function publicMethod() { echo 'This is public method of first class'; } } class SecondClass extends FirstClass { private $_privateProperty; protected function _protectedMethod() { parent::_protectedMethod(); echo 'This is protected method of second class'; $this->_privateProperty = parent::$_protectedProperty; } public function publicMethod() { parent::publicMethod(); echo 'This is public method of second class'; $this->_privateProperty = parent::$publicProperty; } } class ThirdClass { public function __construct(SecondClass $spb91639) { $spb91639->publicMethod(); } }

0 commit comments

Comments
 (0)