Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active June 30, 2019 20:35
Show Gist options
  • Save trikitrok/0ead6e5c1d460ae8494b878422267262 to your computer and use it in GitHub Desktop.
Save trikitrok/0ead6e5c1d460ae8494b878422267262 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\ClickValidation;
use Trovit\B2B\AdClick\Domain\ClickParamsValidator;
use Trovit\B2B\AdClick\Domain\NoBotClickValidator;
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(
[new ClickParamsValidator(), $this->noBotClickValidator->reveal()]
);
}
/** @test */
public function a_click_lacking_any_mandatory_parameter_is_not_valid()
{
$clickLackingParameters = $this->clickWithAllParameters()
->withoutCountry()->build();
$this->noBotClickValidator->isValid($clickLackingParameters)
->willReturn(true);
$isValid = $this->clickValidation->isValid($clickLackingParameters);
$this->assertFalse($isValid);
}
/** @test */
public function a_click_by_a_bot_is_not_valid()
{
$clickWithAllParameters = $this->clickWithAllParameters()->build();
$this->noBotClickValidator->isValid($clickWithAllParameters)
->willReturn(false);
$isValid = $this->clickValidation->isValid($clickWithAllParameters);
$this->assertFalse($isValid);
}
/** @test */
public function a_click_by_a_human_with_all_parameters_is_valid()
{
$clickWithAllParameters = $this->clickWithAllParameters()->build();
$this->noBotClickValidator->isValid($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