Skip to content
Snippets Groups Projects
Commit b602dba9 authored by BorelEnzo's avatar BorelEnzo
Browse files

Create basic test: file size

parent 4fee284d
No related branches found
No related tags found
No related merge requests found
<?php <?php
namespace Analyzer;
class Analyzer{ class Analyzer
{
private $fileName;
private $fileContent; private $fileName;
private $fileContent;
function __construct(){}
public function analyze($pFileName)
function __destruct(){} {
if (!$pFileName || !is_string($pFileName)) {
public function analyze($pFileName){ $this->kill("No file");
if(!$pFileName || !is_string($pFileName)){ } else {
$this->kill("No file"); $this->fileName= $pFileName;
} $this->fileContent = file_get_contents($this->fileName);
else{
$this->fileName= $pFileName;
$this->fileContent = file_get_contents($this->fileName);
}
} }
}
/**
* //FIXME kill properly /**
* @param string $message * //FIXME kill properly
*/ * @param string $message
private function kill($message){ */
die($message); private function kill($message)
} {
die($message);
/** }
* Searches for non-ASCII characters, often used in obfuscated files
* @return number /**
*/ * Searches for non-ASCII characters, often used in obfuscated files
private function searchNonASCIIChars(){ * @return number
$count = 0; */
for($i = 0; $i < strlen($this->fileContent); $i++){ private function searchNonASCIIChars()
if (ord($this->fileContent[$i]) > 0x7f){ {
$count++; $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
<?php <?php
= "test"; = "test";
echo ; echo ;
?>
\ No newline at end of file
<?php <?php
/** /**
* Apply the strpos function with an array of parameters * Apply the strpos function with an array of parameters
* @param string $haystack * @param string $haystack
* @param array $arrayOfWords words to search in the haystack * @param array $arrayOfWords words to search in the haystack
* @return int|boolean * @return int|boolean
*/ */
function strposOnArray($haystack, $arrayOfWords){ function strposOnArray($haystack, $arrayOfWords)
if (is_array($arrayOfWords)) { {
foreach ($arrayOfWords as $word) { if (is_array($arrayOfWords)) {
$pos = strpos($haystack, $word); foreach ($arrayOfWords as $word) {
if ($pos !== false) { $pos = strpos($haystack, $word);
return $pos; if ($pos !== false) {
} return $pos;
} }
return false;
} }
} return false;
\ No newline at end of file }
}
<?php <?php
namespace Tests; namespace Tests;
use PHPUnit\Framework\TestCase;
require_once '../src/Analyzer.php'; use PHPUnit\Framework\TestCase;
use Analyzer\Analyzer;
require_once '../src/Analyzer.php';
class AnalyzerTest extends TestCase
{
class AnalyzerTest extends TestCase{ public function testTestMe()
{
public function testTestMe(){ $analyzer = new Analyzer();
$analyzer = new \Analyzer(); $analyzer->analyze("../src/test.php");
$analyzer->analyze("../src/test.php"); $this->assertTrue($analyzer->testMe("searchNonASCIIChars") >0);
$this->assertTrue($analyzer->testMe("searchNonASCIIChars") >0);
}
} }
?> }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment