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
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
}
<?php
= "test";
echo ;
?>
\ No newline at end of file
<?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;
}
}
<?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
}
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