Skip to content

Commit

Permalink
ServiceTest updated
Browse files Browse the repository at this point in the history
  • Loading branch information
br33f committed Jul 22, 2022
1 parent e57b364 commit c7a9c94
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tests/Ga4/MeasurementProtocol/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public function testUseSsl()
$this->assertFalse($this->service->isUseSsl());
}

public function testUsewww()
{
$this->service->setUseWww(true);
$this->assertTrue($this->service->isUseWww());

$this->service->setUseWww(false);
$this->assertFalse($this->service->isUseWww());
}

public function testCollectEndpoint()
{
$setCollectEndpoint = str_replace('https://', '', $this->faker->url);
Expand Down Expand Up @@ -116,7 +125,6 @@ public function testEndpoint()
$newService->setUseSsl(false);
$this->assertEquals(Service::NOT_SSL_SCHEME . $setCollectEndpoint . $getParams, $newService->getEndpoint());


$setCollectDebugEndpoint = str_replace('https://', '', $this->faker->url);
$setCollectDebugEndpoint = str_replace('http://', '', $setCollectDebugEndpoint);
$newService->setCollectDebugEndpoint($setCollectDebugEndpoint);
Expand Down Expand Up @@ -164,6 +172,33 @@ public function testSend()
$this->assertEquals(200, $baseResponse->getStatusCode());
}

public function testSendWithIpOverride()
{
$mock = new MockHandler([
new Response(200)
]);

$handlerStack = HandlerStack::create($mock);
$mockClient = new Client(['handler' => $handlerStack]);

$setApiSecret = $this->faker->word;
$setMeasurementId = $this->faker->bothify('**-########');
$sendService = new Service($setApiSecret, $setMeasurementId);
$sendService->getHttpClient()->setClient($mockClient);

$sendService->setIpOverride($this->faker->ipv4);

$setClientId = $this->faker->asciify('********************.********************');
$sentRequest = new BaseRequest($setClientId);
$event = new BaseEvent($this->faker->word);
$sentRequest->addEvent($event);

$baseResponse = $sendService->send($sentRequest);
$this->assertTrue($baseResponse instanceof AbstractResponse);
$this->assertEquals(200, $baseResponse->getStatusCode());
}


public function testSendDebugWithError()
{
$mock = new MockHandler([
Expand Down

0 comments on commit c7a9c94

Please sign in to comment.