Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active June 30, 2019 20:38
Show Gist options
  • Select an option

  • Save trikitrok/328f80a0c5c8cdc1cbe67e5ac4c51171 to your computer and use it in GitHub Desktop.

Select an option

Save trikitrok/328f80a0c5c8cdc1cbe67e5ac4c51171 to your computer and use it in GitHub Desktop.
<?php
namespace Trovit\B2B\AdClick\Tests\unit\Domain;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Trovit\B2B\AdClick\Domain\BotClickDetector;
use Trovit\B2B\AdClick\Domain\ClickParamsValidator;
use Trovit\B2B\AdClick\Domain\ClickValidation;
use Trovit\B2B\AdClick\Domain\DomainLogger;
use Trovit\B2B\AdClick\Tests\helper\ClickRawDataBuilder;
class ClickValidationTest extends TestCase
{
private $click;
private $botDetector;
private $domainLogger;
private $clickValidation;
private $paramsValidator;
protected function setUp()
{
$this->click = ClickRawDataBuilder::clickMandatoryRawData()->build();
$this->domainLogger = $this->prophesize(DomainLogger::class);
$this->botDetector = $this->prophesize(BotClickDetector::class);
$this->paramsValidator = $this->prophesize(ClickParamsValidator::class);
$this->clickValidation = new ClickValidation(
$this->botDetector->reveal(),
$this->domainLogger->reveal(),
$this->paramsValidator->reveal()
);
}
/** @test */
public function a_click_by_a_bot_is_not_valid_and_is_logged()
{
$this->paramsValidator->isValid(Argument::any())->willReturn(true);
$this->botDetector->isBot($this->click['userIp'])->willReturn(true);
$isValid = $this->clickValidation->isValid($this->click);
$this->assertFalse($isValid);
$this->domainLogger->logBotClick($this->click)->shouldHaveBeenCalledOnce();
}
/** @test */
public function a_click_by_human_is_valid()
{
$this->paramsValidator->isValid(Argument::any())->willReturn(true);
$this->botDetector->isBot($this->click['userIp'])->willReturn(false);
$isValid = $this->clickValidation->isValid($this->click);
$this->assertTrue($isValid);
$this->domainLogger->logBotClick($this->click)->shouldNotHaveBeenCalled();
}
/** @test */
public function a_click_missing_a_mandatory_param_is_not_valid_but_is_not_logged()
{
$this->paramsValidator->isValid(Argument::any())->willReturn(false);
$isValid = $this->clickValidation->isValid($this->click);
$this->assertFalse($isValid);
$this->domainLogger->logBotClick($this->click)->shouldNotHaveBeenCalled();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment