From b602dba9af6dbf7b1c29a20576dfcac09382ee77 Mon Sep 17 00:00:00 2001 From: BorelEnzo <borelenzo@gmail.com> Date: Fri, 27 Oct 2017 19:13:00 +0200 Subject: [PATCH] Create basic test: file size --- src/Analyzer.php | 96 +++++++++++++++++++++--------------------- src/test.php | 1 - src/util.php | 31 +++++++------- tests/AnalyzerTest.php | 26 +++++++----- 4 files changed, 79 insertions(+), 75 deletions(-) diff --git a/src/Analyzer.php b/src/Analyzer.php index d519bf8..361a303 100644 --- a/src/Analyzer.php +++ b/src/Analyzer.php @@ -1,54 +1,54 @@ <?php +namespace Analyzer; - class Analyzer{ - - private $fileName; - private $fileContent; - - function __construct(){} - - function __destruct(){} - - public function analyze($pFileName){ - if(!$pFileName || !is_string($pFileName)){ - $this->kill("No file"); - } - else{ - $this->fileName= $pFileName; - $this->fileContent = file_get_contents($this->fileName); - } +class Analyzer +{ + + private $fileName; + private $fileContent; + + public function analyze($pFileName) + { + if (!$pFileName || !is_string($pFileName)) { + $this->kill("No file"); + } else { + $this->fileName= $pFileName; + $this->fileContent = file_get_contents($this->fileName); } - - - /** - * //FIXME kill properly - * @param string $message - */ - private function kill($message){ - die($message); - } - - /** - * Searches for non-ASCII characters, often used in obfuscated files - * @return number - */ - private function searchNonASCIIChars(){ - $count = 0; - for($i = 0; $i < strlen($this->fileContent); $i++){ - if (ord($this->fileContent[$i]) > 0x7f){ - $count++; - } + } + + + /** + * //FIXME kill properly + * @param string $message + */ + private function kill($message) + { + die($message); + } + + /** + * Searches for non-ASCII characters, often used in obfuscated files + * @return number + */ + private function searchNonASCIIChars() + { + $count = 0; + for ($i = 0; $i < strlen($this->fileContent); $i++) { + if (ord($this->fileContent[$i]) > 0x7f) { + $count++; } - return $count/strlen($this->fileContent); - } - - /** - * Wrapper for tests - * @param $func - * @return ? value of the called function - */ - public function testMe($func){ - return $this->$func(); } + return $count/strlen($this->fileContent); + } + + /** + * Wrapper for tests + * @param $func + * @return ? value of the called function + */ + public function testMe($func) + { + return $this->$func(); } - \ No newline at end of file +} diff --git a/src/test.php b/src/test.php index 32a89f2..5343236 100644 --- a/src/test.php +++ b/src/test.php @@ -1,4 +1,3 @@ <?php $Æ = "test"; echo $Æ; -?> \ No newline at end of file diff --git a/src/util.php b/src/util.php index d0d4b5e..3d19c74 100644 --- a/src/util.php +++ b/src/util.php @@ -1,18 +1,19 @@ <?php - /** - * Apply the strpos function with an array of parameters - * @param string $haystack - * @param array $arrayOfWords words to search in the haystack - * @return int|boolean - */ - function strposOnArray($haystack, $arrayOfWords){ - if (is_array($arrayOfWords)) { - foreach ($arrayOfWords as $word) { - $pos = strpos($haystack, $word); - if ($pos !== false) { - return $pos; - } +/** + * Apply the strpos function with an array of parameters + * @param string $haystack + * @param array $arrayOfWords words to search in the haystack + * @return int|boolean + */ +function strposOnArray($haystack, $arrayOfWords) +{ + if (is_array($arrayOfWords)) { + foreach ($arrayOfWords as $word) { + $pos = strpos($haystack, $word); + if ($pos !== false) { + return $pos; } - return false; } - } \ No newline at end of file + return false; + } +} diff --git a/tests/AnalyzerTest.php b/tests/AnalyzerTest.php index 639d405..c0ecdcd 100644 --- a/tests/AnalyzerTest.php +++ b/tests/AnalyzerTest.php @@ -1,14 +1,18 @@ <?php - namespace Tests; - use PHPUnit\Framework\TestCase; - require_once '../src/Analyzer.php'; +namespace Tests; + +use PHPUnit\Framework\TestCase; +use Analyzer\Analyzer; + +require_once '../src/Analyzer.php'; + +class AnalyzerTest extends TestCase +{ - class AnalyzerTest extends TestCase{ - - public function testTestMe(){ - $analyzer = new \Analyzer(); - $analyzer->analyze("../src/test.php"); - $this->assertTrue($analyzer->testMe("searchNonASCIIChars") >0); - } + public function testTestMe() + { + $analyzer = new Analyzer(); + $analyzer->analyze("../src/test.php"); + $this->assertTrue($analyzer->testMe("searchNonASCIIChars") >0); } -?> \ No newline at end of file +} -- GitLab