Skip to content

Functional test #1

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 9 commits into from
Mar 9, 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: 2 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<phpunit bootstrap="tests/phpunit.php" colors="true">
</phpunit>
7 changes: 7 additions & 0 deletions tests/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Tests;

class Base extends \PHPUnit_Framework_TestCase {

}
32 changes: 32 additions & 0 deletions tests/ObfuscateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Tests;

class ObfuscateTest extends Base {

const AFTER_PATH = "/after";
const BEFORE_PATH = "/before";
const EXPECTED_PATH = "/expected";

protected function tearDown() {
$files = glob(__DIR__ . self::AFTER_PATH . "/*");
foreach ($files as $file) {
unlink($file);
}
rmdir(__DIR__ . self::AFTER_PATH);
}

public function testObfuscate() {
shell_exec("./bin/obfuscate obfuscate " . __DIR__ . self::BEFORE_PATH . " " . __DIR__ . self::AFTER_PATH . " --config=" . __DIR__ . "/config.yml");
$expectedFileNames = scandir(__DIR__ . self::EXPECTED_PATH);
foreach ($expectedFileNames as $expectedFileName) {
if ($expectedFileName === '.' || $expectedFileName === '..') {
continue;
}
if (!file_exists(__DIR__ . self::AFTER_PATH . "/" . $expectedFileName)) {
$this->fail("{$expectedFileName} not found");
}
$this->assertEquals(file_get_contents(__DIR__ . self::EXPECTED_PATH . "/" . $expectedFileName), file_get_contents(__DIR__ . self::AFTER_PATH . "/" . $expectedFileName));
}
}
}
16 changes: 16 additions & 0 deletions tests/before/Functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php


function functionA($argumentVar) {
$localVarA = 3;
return $argumentVar + $localVarA;
}

function functionB() {
$localVarB = 5;
return functionB($localVarB);
}

$localVarMainA = "local value";
$localVarMainB = functionB();
$localVarMainA = functionA($localVarMainA);
38 changes: 38 additions & 0 deletions tests/before/MultipleClasses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

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 $secondObject) {
$secondObject->publicMethod();
}
}
19 changes: 19 additions & 0 deletions tests/before/Namespaces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace namespaceA;

class classA {

}

namespace namespaceB;

use namespaceA;

class classB {
private $_objectA;

public function __construct() {
$this->_objectA = new namespaceA\classA();
}
}
34 changes: 34 additions & 0 deletions tests/before/SimpleClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

class SimpleClass {

private $_privateProperty;
protected $_protectedProperty;
public $publicProperty;

private function _privateMethod() {
$localVar = "test";
$this->_privateProperty = $localVar;
$this->_protectedProperty = $localVar;
$this->publicProperty = $localVar;
}

protected function _protectedMethod() {
$localVar = "test";
$this->_privateProperty = $localVar;
$this->_protectedProperty = $localVar;
$this->publicProperty = $localVar;
}

public function publicMethod() {
$localVar = "test";
$this->_privateProperty = $localVar;
$this->_protectedProperty = $localVar;
$this->publicProperty = $localVar;
$this->_protectedMethod();
$this->_privateMethod();
}
}

$simpleObject = new SimpleClass();
$simpleObject->publicMethod();
7 changes: 7 additions & 0 deletions tests/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:

# String scrambler
obfuscator.scrambler:
class: Naneau\Obfuscator\StringScrambler
arguments:
- 'salt'
2 changes: 2 additions & 0 deletions tests/expected/Functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
function functionA($spc5a579) { $sp0edd21 = 3; return $spc5a579 + $sp0edd21; } function functionB() { $sp6a6761 = 5; return functionB($sp6a6761); } $sp8851f9 = 'local value'; $sp7f60ff = functionB(); $sp8851f9 = functionA($sp8851f9);
2 changes: 2 additions & 0 deletions tests/expected/MultipleClasses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
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(); } }
2 changes: 2 additions & 0 deletions tests/expected/Namespaces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
namespace namespaceA; class classA { } namespace namespaceB; use namespaceA; class classB { private $_objectA; public function __construct() { $this->_objectA = new namespaceA\classA(); } }
2 changes: 2 additions & 0 deletions tests/expected/SimpleClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
class SimpleClass { private $_privateProperty; protected $_protectedProperty; public $publicProperty; private function sp51fa3f() { $spd8dce8 = 'test'; $this->_privateProperty = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } protected function _protectedMethod() { $spd8dce8 = 'test'; $this->_privateProperty = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = 'test'; $this->_privateProperty = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod();
9 changes: 9 additions & 0 deletions tests/phpunit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

include __DIR__ . '/../vendor/autoload.php';

function autoLoader($className) {
include __DIR__ . "\\..\\" . strtolower($className) . '.php';
}

spl_autoload_register('autoLoader');