Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pixel API implementation #321

Merged
merged 13 commits into from
Oct 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding test for function vipgoci_send_stats_to_pixel_api()
  • Loading branch information
gudmdharalds committed Oct 24, 2022
commit 5f3e2e6139cb904e2401f466d53e069c603f45de
130 changes: 130 additions & 0 deletions tests/unit/OtherWebServicesSendStatsToPixelApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
/**
* Test vipgoci_send_stats_to_pixel_api().
*
* @package Automattic/vip-go-ci
*/

declare(strict_types=1);

namespace Vipgoci\Tests\Unit;

use PHPUnit\Framework\TestCase;

/**
* Class that implements the testing.
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
final class OtherWebServicesSendStatsToPixelApiTest extends TestCase {
/**
* Setup function. Require files.
*
* @return void
*/
protected function setUp() :void {
require_once __DIR__ . '/../../other-web-services.php';
require_once __DIR__ . '/../../log.php';
require_once __DIR__ . '/helper/OtherWebServicesSendStatsToPixelApi.php';
}

/**
* Emulate sending statistics to Pixel API.
*
* @covers ::vipgoci_send_stats_to_pixel_api
*
* @return void
*/
public function testSendStatistics(): void {
$counter_report = array(
'stat1' => 50,
'stat2' => 30,
'stat3' => 10,
'stat4' => 2,
'stat5' => 0,
'stat6' => 1,
'stat7' => -100,
);


ob_start();

vipgoci_send_stats_to_pixel_api(
'https://127.0.0.1',
array(
'mygroup1' => array(
'stat1',
'stat2',
'stat3',
),
'mygroup2' => array(
'stat3',
'stat4',
'stat5',
'stat7',
'statinvalid',
),
),
$counter_report
);

$printed_data = ob_get_contents();
ob_end_clean();

$this->assertStringContainsString(
'"Sending statistics to pixel API service"',
$printed_data
);

$this->assertStringContainsString(
'"Finished sending statistics to pixel API service"',
$printed_data
);

$this->assertStringContainsString(
'"https:\/\/127.0.0.1?v=wpcom-no-pv&x_mygroup1\/stat1=50"',
$printed_data
);

$this->assertStringContainsString(
'"https:\/\/127.0.0.1?v=wpcom-no-pv&x_mygroup1\/stat2=30"',
$printed_data
);

$this->assertStringContainsString(
'"https:\/\/127.0.0.1?v=wpcom-no-pv&x_mygroup1\/stat3=10"',
$printed_data
);

$this->assertStringContainsString(
'"https:\/\/127.0.0.1?v=wpcom-no-pv&x_mygroup2\/stat3=10"',
$printed_data
);

$this->assertStringContainsString(
'"https:\/\/127.0.0.1?v=wpcom-no-pv&x_mygroup2\/stat4=2"',
$printed_data
);

$this->assertStringNotContainsString(
'stat5=',
$printed_data
);

$this->assertStringNotContainsString(
'stat6=',
$printed_data
);

$this->assertStringNotContainsString(
'stat7=',
$printed_data
);

$this->assertStringNotContainsString(
'statinvalid=',
$printed_data
);
}
}