- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
92 lines
2.1 KiB
PHP
92 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Framework\Waf\Feedback;
|
|
|
|
use App\Framework\Waf\Analysis\ValueObjects\RequestAnalysisData;
|
|
use App\Framework\Waf\MachineLearning\MachineLearningEngine;
|
|
use App\Framework\Waf\MachineLearning\MachineLearningResult;
|
|
|
|
/**
|
|
* Test implementation of MachineLearningEngine for unit tests
|
|
*/
|
|
class TestMachineLearningEngine extends MachineLearningEngine
|
|
{
|
|
private array $applyFeedbackAdjustmentsResult = [];
|
|
|
|
private array $analyzeRequestResult = [];
|
|
|
|
private array $receivedAdjustments = [];
|
|
|
|
/**
|
|
* Constructor that bypasses parent constructor
|
|
*/
|
|
public function __construct()
|
|
{
|
|
// Intentionally empty to bypass parent constructor
|
|
}
|
|
|
|
/**
|
|
* Set the result to return from applyFeedbackAdjustments
|
|
*
|
|
* @param array $result Result to return
|
|
* @return self
|
|
*/
|
|
public function withApplyFeedbackAdjustmentsResult(array $result): self
|
|
{
|
|
$this->applyFeedbackAdjustmentsResult = $result;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set the result to return from analyzeRequest
|
|
*
|
|
* @param MachineLearningResult $result Result to return
|
|
* @return self
|
|
*/
|
|
public function withAnalyzeRequestResult(MachineLearningResult $result): self
|
|
{
|
|
$this->analyzeRequestResult = $result;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get the adjustments that were passed to applyFeedbackAdjustments
|
|
*
|
|
* @return array Adjustments that were passed
|
|
*/
|
|
public function getReceivedAdjustments(): array
|
|
{
|
|
return $this->receivedAdjustments;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function applyFeedbackAdjustments(array $adjustments): array
|
|
{
|
|
$this->receivedAdjustments = $adjustments;
|
|
|
|
return $this->applyFeedbackAdjustmentsResult;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function analyzeRequest(RequestAnalysisData $requestData, array $context = []): MachineLearningResult
|
|
{
|
|
return $this->analyzeRequestResult;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function isEnabled(): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|