Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkakkar committed Mar 8, 2024
1 parent 93ff976 commit 17ad72c
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 132 deletions.
24 changes: 12 additions & 12 deletions test/FeatureFlagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public function testMatchPropertyDateOperators(): void
self::assertFalse(FeatureFlag::matchProperty($prop_a, [
"key" => "2022-05-30",
]));

// is date after
// is date after
// const property_b = { key: 'key', value: '2022-05-01', operator: 'is_date_after' }
Expand Down Expand Up @@ -604,7 +604,7 @@ public function testMatchPropertyDateOperators(): void
public function testMatchPropertyRelativeDateOperators(): void
{
ClockMock::executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () {

$prop_a = [
"key" => "key",
"value" => "-6h",
Expand Down Expand Up @@ -794,7 +794,7 @@ public function testMatchPropertyRelativeDateOperators(): void
self::assertFalse(FeatureFlag::matchProperty($prop_l, [
"key" => "2022-04-16 00:00:00",
]));

$prop_m = [
"key" => "key",
"value" => "1m",
Expand Down Expand Up @@ -848,7 +848,7 @@ public function testMatchPropertyWithNones(): void
self::assertTrue(FeatureFlag::matchProperty($prop_a, [
"key" => "nul",
]));

$prop_b = [
"key" => "key",
"value" => "null",
Expand Down Expand Up @@ -949,7 +949,7 @@ public function testRelativeDateParsingOverflow()

public function testRelativeDateParsingHours()
{

ClockMock::executeAtFrozenDateTime(new \DateTime('2020-01-01T12:01:20Z'), function () {
self::assertEquals(FeatureFlag::relativeDateParseForFeatureFlagMatching('1h'), new \DateTime('2020-01-01T11:01:20Z'));
self::assertEquals(FeatureFlag::relativeDateParseForFeatureFlagMatching('2h'), new \DateTime('2020-01-01T10:01:20Z'));
Expand Down Expand Up @@ -1014,7 +1014,7 @@ public function testRelativeDateParsingMonths()

self::assertEquals(FeatureFlag::relativeDateParseForFeatureFlagMatching('1y'), new \DateTime('2019-04-03T00:00:00Z'));
self::assertEquals(FeatureFlag::relativeDateParseForFeatureFlagMatching('12m'), FeatureFlag::relativeDateParseForFeatureFlagMatching('1y'));

});
}

Expand Down Expand Up @@ -1191,7 +1191,7 @@ public function testGetAllFlagsWithFallback()

public function testGetAllFlagsWithFallbackEmptyLocalFlags()
{
$this->http_client = new MockedHttpClient(host: "app.posthog.com", flagEndpointResponse:[]);
$this->http_client = new MockedHttpClient(host: "app.posthog.com", flagEndpointResponse: []);
$this->client = new Client(
self::FAKE_API_KEY,
[
Expand All @@ -1210,7 +1210,7 @@ public function testGetAllFlagsWithFallbackEmptyLocalFlags()

public function testGetAllFlagsWithNoFallback()
{
$this->http_client = new MockedHttpClient(host: "app.posthog.com", flagEndpointResponse:MockedResponses::MULTIPLE_FLAGS_LOCAL_EVALUATE_REQUEST);
$this->http_client = new MockedHttpClient(host: "app.posthog.com", flagEndpointResponse: MockedResponses::MULTIPLE_FLAGS_LOCAL_EVALUATE_REQUEST);
$this->client = new Client(
self::FAKE_API_KEY,
[
Expand Down Expand Up @@ -1284,13 +1284,13 @@ public function testSimpleFlag()

$this->assertEquals(
$this->http_client->calls,
array(
0 => array(
array (
0 => array (
"path" => "/api/feature_flag/local_evaluation?send_cohorts&token=random_key",
"payload" => null,
),
// no decide because local eval, but capture flag event
1 => array(
1 => array (
"path" => "/batch/",
'payload' => '{"batch":[{"properties":{"$feature\/simple-flag":true,"$active_feature_flags":["simple-flag"],"$feature_flag":"simple-flag","$feature_flag_response":true,"$lib":"posthog-php","$lib_version":"3.0.3","$lib_consumer":"LibCurl","$groups":[]},"distinct_id":"some-distinct-id","event":"$feature_flag_called","$groups":[],"library":"posthog-php","library_version":"3.0.3","library_consumer":"LibCurl","groups":[],"timestamp":"2022-05-01T00:00:00+00:00","type":"capture"}],"api_key":"random_key"}',
),
Expand Down Expand Up @@ -1548,7 +1548,7 @@ public function testFeatureFlagsLocalEvaluationForNegatedCohorts()
array()
);
}

public function testComputingFlagWithoutRolloutLocally()
{
$this->http_client = new MockedHttpClient(host: "app.posthog.com", flagEndpointResponse: MockedResponses::LOCAL_EVALUATION_WITH_NO_ROLLOUT_REQUEST);
Expand Down
36 changes: 18 additions & 18 deletions test/PostHogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testCaptureWithSendFeatureFlagsOption(): void

$this->assertTrue(
PostHog::capture(
array(
array (
"distinctId" => "john",
"event" => "Module PHP Event",
"send_feature_flags" => true
Expand All @@ -108,16 +108,16 @@ public function testCaptureWithSendFeatureFlagsOption(): void

$this->assertEquals(
$this->http_client->calls,
array(
0 => array(
array (
0 => array (
"path" => "/api/feature_flag/local_evaluation?send_cohorts&token=random_key",
"payload" => null,
),
1 => array(
1 => array (
"path" => "/decide/?v=2",
"payload" => sprintf('{"api_key":"%s","distinct_id":"john"}', self::FAKE_API_KEY),
),
2 => array(
2 => array (
"path" => "/batch/",
"payload" => '{"batch":[{"event":"Module PHP Event","send_feature_flags":true,"properties":{"$feature\/simpleFlag":true,"$feature\/having_fun":false,"$feature\/enabled-flag":true,"$feature\/disabled-flag":false,"$feature\/multivariate-simple-test":"variant-simple-value","$feature\/simple-test":true,"$feature\/multivariate-test":"variant-value","$feature\/group-flag":"decide-fallback-value","$feature\/complex-flag":"decide-fallback-value","$feature\/beta-feature":"decide-fallback-value","$feature\/beta-feature2":"alakazam","$feature\/feature-1":"decide-fallback-value","$feature\/feature-2":"decide-fallback-value","$feature\/variant-1":"variant-1","$feature\/variant-3":"variant-3","$active_feature_flags":["simpleFlag","enabled-flag","multivariate-simple-test","simple-test","multivariate-test","group-flag","complex-flag","beta-feature","beta-feature2","feature-1","feature-2","variant-1","variant-3"],"$lib":"posthog-php","$lib_version":"3.0.3","$lib_consumer":"LibCurl"},"library":"posthog-php","library_version":"3.0.3","library_consumer":"LibCurl","distinct_id":"john","groups":[],"timestamp":"2022-05-01T00:00:00+00:00","type":"capture"}],"api_key":"random_key"}',
),
Expand Down Expand Up @@ -152,23 +152,23 @@ public function testCaptureWithLocalSendFlags(): void
ClockMock::executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () {
$this->assertTrue(
PostHog::capture(
array(
array (
"distinctId" => "john",
"event" => "Module PHP Event",
)
)
);

PostHog::flush();

$this->assertEquals(
$this->http_client->calls,
array(
0 => array(
array (
0 => array (
"path" => "/api/feature_flag/local_evaluation?send_cohorts&token=random_key",
"payload" => null,
),
1 => array(
1 => array (
"path" => "/batch/",
"payload" => '{"batch":[{"event":"Module PHP Event","properties":{"$feature\/true-flag":true,"$active_feature_flags":["true-flag"],"$lib":"posthog-php","$lib_version":"3.0.3","$lib_consumer":"LibCurl"},"library":"posthog-php","library_version":"3.0.3","library_consumer":"LibCurl","distinct_id":"john","groups":[],"timestamp":"2022-05-01T00:00:00+00:00","type":"capture"}],"api_key":"random_key"}',
),
Expand All @@ -193,26 +193,26 @@ public function testCaptureWithLocalSendFlagsNoOverrides(): void
ClockMock::executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () {
$this->assertTrue(
PostHog::capture(
array(
array (
"distinctId" => "john",
"event" => "Module PHP Event",
"properties" => array(
"properties" => array (
"\$feature/true-flag" => "random-override"
)
)
)
);

PostHog::flush();

$this->assertEquals(
$this->http_client->calls,
array(
0 => array(
array (
0 => array (
"path" => "/api/feature_flag/local_evaluation?send_cohorts&token=random_key",
"payload" => null,
),
1 => array(
1 => array (
"path" => "/batch/",
"payload" => '{"batch":[{"event":"Module PHP Event","properties":{"$feature\/true-flag":"random-override","$active_feature_flags":["true-flag"],"$lib":"posthog-php","$lib_version":"3.0.3","$lib_consumer":"LibCurl"},"library":"posthog-php","library_version":"3.0.3","library_consumer":"LibCurl","distinct_id":"john","groups":[],"timestamp":"2022-05-01T00:00:00+00:00","type":"capture"}],"api_key":"random_key"}',
),
Expand Down Expand Up @@ -392,7 +392,7 @@ public function testTimestamps(): void
array(
"distinctId" => "user-id",
"event" => "integer-timestamp",
"timestamp" => (int)mktime(0, 0, 0, date('n'), 1, date('Y')),
"timestamp" => (int) mktime(0, 0, 0, date('n'), 1, date('Y')),
)
)
);
Expand All @@ -402,7 +402,7 @@ public function testTimestamps(): void
array(
"distinctId" => "user-id",
"event" => "string-integer-timestamp",
"timestamp" => (string)mktime(0, 0, 0, date('n'), 1, date('Y')),
"timestamp" => (string) mktime(0, 0, 0, date('n'), 1, date('Y')),
)
)
);
Expand Down
Loading

0 comments on commit 17ad72c

Please sign in to comment.