Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save trikitrok/bc99d68fc4536dd81b24b75df9d7e8eb to your computer and use it in GitHub Desktop.
<?php
namespace Trovit\B2B\AdClick\Tests\unit\Domain;
use PHPUnit\Framework\TestCase;
use Trovit\B2B\AdClick\Domain\ClickParamsValidator;
use Trovit\B2B\AdClick\Domain\NoBotClickValidator;
use Trovit\B2B\AdClick\Domain\ClickValidation;
use Trovit\B2B\AdClick\Tests\helper\ClickRawDataBuilder;
class ClickValidationTest extends TestCase
{
private $noBotClickValidator;
private $clickValidation;
protected function setUp()
{
$this->noBotClickValidator = $this->prophesize(NoBotClickValidator::class);
$this->clickValidation = new ClickValidation(
$this->noBotClickValidator->reveal(),
new ClickParamsValidator()
);
}
/** @test */
public function a_click_lacking_any_mandatory_parameter_is_not_valid()
{
$clickLackingParameters = $this->clickWithAllParameters()
->withoutCountry->build();
$this->botDetector->noBotClickValidator($clickLackingParameters)
->willReturn(true);
$isValid = $this->clickValidation->isValid($clickLackingParameters);
$this->assertFalse($isValid);
}
/** @test */
public function a_click_made_by_a_bot_is_not_valid()
{
$clickWithAllParameters = $this->clickWithAllParameters()->build();
$this->noBotClickValidator->isBot($clickWithAllParameters)
->willReturn(false);
$isValid = $this->clickValidation->isValid($clickWithAllParameters);
$this->assertFalse($isValid);
}
/** @test */
public function a_click_with_all_parameters_and_made_by_a_human_is_valid()
{
$clickWithAllParameters = $this->clickWithAllParameters()->build();
$this->botDetector->noBotClickValidator($clickWithAllParameters)
->willReturn(true);
$isValid = $this->clickValidation->isValid($clickWithAllParameters);
$this->assertTrue($isValid);
}
private function clickWithAllParameters() {
return ClickRawDataBuilder::clickMandatoryRawData();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment