diff --git a/test/ExceptionCaptureTest.php b/test/ExceptionCaptureTest.php index 2d4dec0..4f64945 100644 --- a/test/ExceptionCaptureTest.php +++ b/test/ExceptionCaptureTest.php @@ -668,7 +668,6 @@ private function getProperty(string $property): mixed { $reflection = new \ReflectionClass(ExceptionCapture::class); $propertyReflection = $reflection->getProperty($property); - $propertyReflection->setAccessible(true); return $propertyReflection->getValue(); } diff --git a/test/ExceptionPayloadBuilderTest.php b/test/ExceptionPayloadBuilderTest.php index 5e5b705..bc4253e 100644 --- a/test/ExceptionPayloadBuilderTest.php +++ b/test/ExceptionPayloadBuilderTest.php @@ -93,7 +93,6 @@ public function testInAppFalseForVendorFrames(): void { $reflector = new \ReflectionClass(ExceptionPayloadBuilder::class); $method = $reflector->getMethod('buildFrame'); - $method->setAccessible(true); $frame = $method->invoke(null, [ 'file' => '/app/vendor/some/package/Foo.php', @@ -108,7 +107,6 @@ public function testInAppTrueForAppFrames(): void { $reflector = new \ReflectionClass(ExceptionPayloadBuilder::class); $method = $reflector->getMethod('buildFrame'); - $method->setAccessible(true); $frame = $method->invoke(null, [ 'file' => '/app/src/Services/MyService.php', @@ -387,7 +385,6 @@ public function testFunctionIncludesClass(): void { $reflector = new \ReflectionClass(ExceptionPayloadBuilder::class); $method = $reflector->getMethod('buildFrame'); - $method->setAccessible(true); $frame = $method->invoke(null, [ 'file' => '/app/src/Foo.php', diff --git a/test/FeatureFlagErrorTest.php b/test/FeatureFlagErrorTest.php index 8cc160c..bd543ee 100644 --- a/test/FeatureFlagErrorTest.php +++ b/test/FeatureFlagErrorTest.php @@ -5,6 +5,7 @@ // comment out below to print all logs instead of failing tests require_once 'test/error_log_mock.php'; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use PostHog\Client; use PostHog\FeatureFlagError; @@ -38,6 +39,7 @@ public function setUp($flagsEndpointResponse = MockedResponses::FLAGS_RESPONSE, $errorMessages = []; } + #[IgnoreDeprecations] public function testFlagMissingError() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -68,6 +70,7 @@ public function testFlagMissingError() }); } + #[IgnoreDeprecations] public function testErrorsWhileComputingFlagsError() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -101,6 +104,7 @@ public function testErrorsWhileComputingFlagsError() }); } + #[IgnoreDeprecations] public function testMultipleErrors() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -135,6 +139,7 @@ public function testMultipleErrors() }); } + #[IgnoreDeprecations] public function testNoErrorWhenFlagEvaluatesSuccessfully() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -162,6 +167,7 @@ public function testNoErrorWhenFlagEvaluatesSuccessfully() }); } + #[IgnoreDeprecations] public function testUnknownErrorWhenExceptionThrown() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -239,6 +245,7 @@ public function testApiErrorMethod() $this->assertEquals('api_error_429', FeatureFlagError::apiError(429)); } + #[IgnoreDeprecations] public function testTimeoutError() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -285,6 +292,7 @@ public function testTimeoutError() }); } + #[IgnoreDeprecations] public function testConnectionError() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -331,6 +339,7 @@ public function testConnectionError() }); } + #[IgnoreDeprecations] public function testApiError500() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -376,6 +385,7 @@ public function testApiError500() }); } + #[IgnoreDeprecations] public function testQuotaLimitedError() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -424,6 +434,7 @@ public function testQuotaLimitedError() }); } + #[IgnoreDeprecations] public function testFailedFlagIsFilteredOutByFailedField() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { diff --git a/test/FeatureFlagEvaluationsTest.php b/test/FeatureFlagEvaluationsTest.php index 62d28f0..67d33a1 100644 --- a/test/FeatureFlagEvaluationsTest.php +++ b/test/FeatureFlagEvaluationsTest.php @@ -7,6 +7,7 @@ require_once 'test/error_log_mock.php'; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use PostHog\Client; use PostHog\EvaluatedFlagRecord; @@ -545,6 +546,7 @@ public function testLocalEvaluationResolvesPayloads(): void } #[DataProvider('falseFlagPayloadProvider')] + #[IgnoreDeprecations] public function testLocalFalseFlagResolvesPayload(mixed $rawPayload, mixed $expectedPayload): void { $this->makeClient( @@ -884,9 +886,9 @@ public static function dedupCallsProvider(): array } /** - * @dataProvider dedupCallsProvider * @param list> $groupsPerCall */ + #[DataProvider('dedupCallsProvider')] public function testFeatureFlagCalledDedupes(array $groupsPerCall, int $expectedCount): void { $this->makeClient(); diff --git a/test/FeatureFlagLocalEvaluationTest.php b/test/FeatureFlagLocalEvaluationTest.php index b9785a7..073875f 100644 --- a/test/FeatureFlagLocalEvaluationTest.php +++ b/test/FeatureFlagLocalEvaluationTest.php @@ -389,9 +389,7 @@ public function jsonSerialize(): mixed self::assertTrue(FeatureFlag::matchProperty($exact, ["key" => $jsonSerializable])); } - /** - * @dataProvider presentPresenceOperatorValuesProvider - */ + #[DataProvider('presentPresenceOperatorValuesProvider')] public function testMatchPropertyPresenceOperatorsTreatPresentValuesAsSet($value): void { foreach (["is_set" => true, "is_not_set" => false] as $operator => $expected) { @@ -1804,9 +1802,7 @@ public function testFlagGroupProperties() $this->assertEquals(PostHog::getFeatureFlag('group-flag', 'some-distinct-id', ["company" => "amazon"], [], ["company" => []]), 'decide-fallback-value'); } - /** - * @dataProvider mixedTargetingProvider - */ + #[DataProvider('mixedTargetingProvider')] public function testMixedTargetingLocalEvaluation(string $flagKey, array $opts, $expected, array $localFlags) { $this->http_client = new MockedHttpClient(host: "app.posthog.com", flagEndpointResponse: $localFlags); @@ -5307,9 +5303,7 @@ private static function earlyExitFlag($earlyExit): array return ["key" => "early-exit-flag", "filters" => $filters]; } - /** - * @dataProvider earlyExitRolloutExclusionProvider - */ + #[DataProvider('earlyExitRolloutExclusionProvider')] public function testEarlyExitRolloutExclusion($earlyExit, bool $expected): void { $flag = self::earlyExitFlag($earlyExit); diff --git a/test/FeatureFlagTest.php b/test/FeatureFlagTest.php index f3312c3..f89e148 100644 --- a/test/FeatureFlagTest.php +++ b/test/FeatureFlagTest.php @@ -6,6 +6,8 @@ require_once 'test/error_log_mock.php'; use Exception; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use PostHog\Client; use PostHog\PostHog; @@ -98,9 +100,7 @@ public static function retryableFlagsCurlErrors(): array ]; } - /** - * @dataProvider retryableFlagsCurlErrors - */ + #[DataProvider('retryableFlagsCurlErrors')] public function testFlagsRequestRetriesTransientCurlErrors(int $curlErrno): void { $this->http_client = new MockedHttpClient("app.posthog.com"); @@ -130,9 +130,7 @@ public function testFlagsRequestRetriesTransientCurlErrors(int $curlErrno): void } } - /** - * @dataProvider retryableFlagsCurlErrors - */ + #[DataProvider('retryableFlagsCurlErrors')] public function testFlagsRequestStopsAfterExhaustingTransientCurlErrorRetries(int $curlErrno): void { $this->http_client = new MockedHttpClient("app.posthog.com"); @@ -212,9 +210,7 @@ public function testFlagsRequestDoesNotRetryConnectionRefused(): void $this->assertCount(1, $this->http_client->calls); } - /** - * @dataProvider nonRetryableFlagsStatusCodes - */ + #[DataProvider('nonRetryableFlagsStatusCodes')] public function testFlagsRequestDoesNotRetryHttpStatusErrors(int $statusCode): void { $this->http_client = new MockedHttpClient("app.posthog.com"); @@ -241,9 +237,7 @@ public function testFlagsRequestDoesNotRetryHttpStatusErrors(int $statusCode): v $this->assertSame('/flags/?v=2', $this->http_client->calls[0]['path']); } - /** - * @dataProvider retryableFlagsStatusCodes - */ + #[DataProvider('retryableFlagsStatusCodes')] public function testFlagsRequestRetriesHttp502And504(int $statusCode): void { $this->http_client = new MockedHttpClient("app.posthog.com"); @@ -271,9 +265,7 @@ public function testFlagsRequestRetriesHttp502And504(int $statusCode): void } } - /** - * @dataProvider retryableFlagsStatusCodes - */ + #[DataProvider('retryableFlagsStatusCodes')] public function testFlagsRequestStopsAfterExhaustingHttp502And504Retries(int $statusCode): void { $this->http_client = new MockedHttpClient("app.posthog.com"); @@ -306,9 +298,7 @@ public function testFlagsRequestStopsAfterExhaustingHttp502And504Retries(int $st } } - /** - * @dataProvider retryableFlagsStatusCodes - */ + #[DataProvider('retryableFlagsStatusCodes')] public function testFlagsRequestDoesNotRetryHttp502And504WhenConfiguredMaxRetriesIsZero(int $statusCode): void { $this->http_client = new MockedHttpClient("app.posthog.com"); @@ -335,9 +325,8 @@ public function testFlagsRequestDoesNotRetryHttp502And504WhenConfiguredMaxRetrie $this->assertCount(1, $this->http_client->calls); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testIsFeatureEnabled($response) { $this->setUp($response); @@ -361,6 +350,7 @@ public function testIsFeatureEnabled($response) ); } + #[IgnoreDeprecations] public function testIsFeatureEnabledCapturesFeatureFlagCalledEventWithAdditionalMetadata() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -388,6 +378,7 @@ public function testIsFeatureEnabledCapturesFeatureFlagCalledEventWithAdditional }); } + #[IgnoreDeprecations] public function testWhitespacePersonalApiKeyFallsBackToFlagsEndpoint() { $this->setUp(MockedResponses::FLAGS_V2_RESPONSE, personalApiKey: " \n\t "); @@ -405,9 +396,8 @@ public function testWhitespacePersonalApiKeyFallsBackToFlagsEndpoint() ); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testIsFeatureEnabledGroups($response) { $this->setUp($response); @@ -435,9 +425,8 @@ public function testIsFeatureEnabledGroups($response) ); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlag($response) { $this->setUp($response); @@ -461,6 +450,7 @@ public function testGetFeatureFlag($response) ); } + #[IgnoreDeprecations] public function testGetFeatureFlagCapturesFeatureFlagCalledEventWithAdditionalMetadata() { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -499,9 +489,8 @@ public static function hasExperimentCases(): array ]; } - /** - * @dataProvider hasExperimentCases - */ + #[DataProvider('hasExperimentCases')] + #[IgnoreDeprecations] public function testFeatureFlagCalledEventIncludesHasExperimentFromRemoteMetadata(?bool $reported) { $response = MockedResponses::FLAGS_V2_RESPONSE; @@ -523,6 +512,7 @@ public function testFeatureFlagCalledEventIncludesHasExperimentFromRemoteMetadat } } + #[IgnoreDeprecations] public function testMinimalFlagCalledEventKeepsOnlyAllowlistedProperties() { $response = MockedResponses::FLAGS_V2_RESPONSE; @@ -553,6 +543,7 @@ public function testMinimalFlagCalledEventKeepsOnlyAllowlistedProperties() $this->assertSame($expected, $properties); } + #[IgnoreDeprecations] public function testMinimalFlagCalledEventKeepsSessionAttributionProperties() { $response = MockedResponses::FLAGS_V2_RESPONSE; @@ -619,9 +610,8 @@ public static function fullFlagCalledEventCases(): array ]; } - /** - * @dataProvider fullFlagCalledEventCases - */ + #[DataProvider('fullFlagCalledEventCases')] + #[IgnoreDeprecations] public function testFlagCalledEventStaysFullWithoutBothMinimalSignals(bool $gated, ?bool $hasExperiment) { $response = MockedResponses::FLAGS_V2_RESPONSE; @@ -642,9 +632,8 @@ public function testFlagCalledEventStaysFullWithoutBothMinimalSignals(bool $gate $this->assertSame('LibCurl', $properties['$lib_consumer']); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagDefault($response) { $this->setUp($response); @@ -653,9 +642,8 @@ public function testGetFeatureFlagDefault($response) $this->checkEmptyErrorLogs(); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagGroups($response) { $this->setUp($response); @@ -686,9 +674,7 @@ public function testGetFeatureFlagGroups($response) ); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] public function testfetchFeatureVariants($response) { $this->setUp($response); @@ -698,9 +684,8 @@ public function testfetchFeatureVariants($response) $this->assertSame('variant-value', $flags['multivariate-test']); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagPayloadHandlesJson($response): void { $this->setUp($response); @@ -708,9 +693,8 @@ public function testGetFeatureFlagPayloadHandlesJson($response): void $this->assertSame(['key' => 'value'], PostHog::getFeatureFlagPayload('json-payload', 'some-distinct')); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagPayloadHandlesIntegers($response): void { $this->setUp($response); @@ -718,9 +702,8 @@ public function testGetFeatureFlagPayloadHandlesIntegers($response): void $this->assertSame(2500, PostHog::getFeatureFlagPayload('integer-payload', 'some-distinct')); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagPayloadHandlesString($response): void { $this->setUp($response); @@ -728,9 +711,8 @@ public function testGetFeatureFlagPayloadHandlesString($response): void $this->assertSame('A String', PostHog::getFeatureFlagPayload('string-payload', 'some-distinct')); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagPayloadHandlesArray($response): void { $this->setUp($response); @@ -738,9 +720,8 @@ public function testGetFeatureFlagPayloadHandlesArray($response): void $this->assertSame([1, 2, 3], PostHog::getFeatureFlagPayload('array-payload', 'some-distinct')); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagPayloadHandlesFlagDisabled($response): void { $this->setUp($response); @@ -748,9 +729,8 @@ public function testGetFeatureFlagPayloadHandlesFlagDisabled($response): void $this->assertNull(PostHog::getFeatureFlagPayload('disabled-flag', 'some-distinct')); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagPayloadHandlesFlagNotInResults($response): void { $this->setUp($response); @@ -758,9 +738,8 @@ public function testGetFeatureFlagPayloadHandlesFlagNotInResults($response): voi $this->assertNull(PostHog::getFeatureFlagPayload('non-existent-flag', 'some-distinct')); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagResult($response): void { $this->setUp($response); @@ -775,9 +754,8 @@ public function testGetFeatureFlagResult($response): void $this->assertTrue($result->getValue()); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagResultWithMultivariateFlag($response): void { $this->setUp($response); @@ -791,9 +769,8 @@ public function testGetFeatureFlagResultWithMultivariateFlag($response): void $this->assertEquals('variant-value', $result->getValue()); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagResultReturnsNullForMissingFlag($response): void { $this->setUp($response); @@ -803,9 +780,8 @@ public function testGetFeatureFlagResultReturnsNullForMissingFlag($response): vo $this->assertNull($result); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagResultForDisabledFlag($response): void { $this->setUp($response); @@ -819,6 +795,7 @@ public function testGetFeatureFlagResultForDisabledFlag($response): void $this->assertFalse($result->getValue()); } + #[IgnoreDeprecations] public function testGetFeatureFlagResultSendsEvent(): void { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -850,9 +827,8 @@ public function testGetFeatureFlagResultSendsEvent(): void }); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagResultWithMultivariateFlagAndPayload($response): void { $this->setUp($response); @@ -867,6 +843,7 @@ public function testGetFeatureFlagResultWithMultivariateFlagAndPayload($response $this->assertEquals('some string payload', $result->getPayload()); } + #[IgnoreDeprecations] public function testGetFeatureFlagPayloadDoesNotSendEvent(): void { $this->setUp(MockedResponses::FLAGS_V2_RESPONSE, personalApiKey: null); @@ -887,9 +864,8 @@ public function testGetFeatureFlagPayloadDoesNotSendEvent(): void $this->assertNull($batchCall, 'Expected no batch call to be made for getFeatureFlagPayload'); } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagResultForDisabledFlagWithPayload($response): void { $this->setUp($response); @@ -904,6 +880,7 @@ public function testGetFeatureFlagResultForDisabledFlagWithPayload($response): v $this->assertEquals(['disabled' => true], $result->getPayload()); } + #[IgnoreDeprecations] public function testGetFeatureFlagResultWithLocalEvaluationOnly(): void { // For local evaluation, we need to set flagEndpointResponse (not flagsEndpointResponse) @@ -939,6 +916,7 @@ public function testGetFeatureFlagResultWithLocalEvaluationOnly(): void } } + #[IgnoreDeprecations] public function testGetFeatureFlagResultReturnsNullForLocalEvaluationWhenFlagCannotBeEvaluatedLocally(): void { // Use a flag config that requires cohorts which can't be evaluated locally @@ -973,9 +951,8 @@ public function testGetFeatureFlagResultReturnsNullForLocalEvaluationWhenFlagCan } } - /** - * @dataProvider decideResponseCases - */ + #[DataProvider('decideResponseCases')] + #[IgnoreDeprecations] public function testGetFeatureFlagResultWithGroups($response): void { $this->setUp($response); diff --git a/test/FlagDefinitionCacheProviderTest.php b/test/FlagDefinitionCacheProviderTest.php index 707d500..2ae8575 100644 --- a/test/FlagDefinitionCacheProviderTest.php +++ b/test/FlagDefinitionCacheProviderTest.php @@ -5,6 +5,7 @@ require_once 'test/error_log_mock.php'; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use PostHog\Client; use PostHog\FlagDefinitionCacheProvider; @@ -505,6 +506,7 @@ public function testCamelCaseGroupTypeMappingIsAcceptedFromCache(): void $this->assertSame([], $httpClient->calls ?? []); } + #[IgnoreDeprecations] public function testMinimalFlagCalledGatePersistsThroughProviderCache(): void { $provider = new MockFlagDefinitionCacheProvider(); diff --git a/test/FlagDependencyIntegrationTest.php b/test/FlagDependencyIntegrationTest.php index cdf3730..67b06f3 100644 --- a/test/FlagDependencyIntegrationTest.php +++ b/test/FlagDependencyIntegrationTest.php @@ -2,11 +2,13 @@ namespace PostHog\Test; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use PostHog\Client; class FlagDependencyIntegrationTest extends TestCase { + #[IgnoreDeprecations] public function testClientIntegrationWithFlagDependencies(): void { // Create a client with mock flags that have dependencies diff --git a/test/FlagDependencyTest.php b/test/FlagDependencyTest.php index e95ad5d..cad9528 100644 --- a/test/FlagDependencyTest.php +++ b/test/FlagDependencyTest.php @@ -2,6 +2,7 @@ namespace PostHog\Test; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use PostHog\Client; use PostHog\FeatureFlag; @@ -426,6 +427,7 @@ public function testMatchesDependencyValue(): void $this->assertFalse(FeatureFlag::matchesDependencyValue("control", 123)); } + #[IgnoreDeprecations] public function testProductionStyleMultivariateDependencyChain(): void { // Test production-style multivariate dependency chain: diff --git a/test/GeoipTest.php b/test/GeoipTest.php index 9543387..dd30dda 100644 --- a/test/GeoipTest.php +++ b/test/GeoipTest.php @@ -3,6 +3,7 @@ namespace PostHog\Test; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use PostHog\Client; use PostHog\PostHog; @@ -107,6 +108,7 @@ public function testBeforeSendCanOverrideClientSettingAndExceptionInheritsIt(): } #[DataProvider('geoipCases')] + #[IgnoreDeprecations] public function testCaptureFlagEnrichmentOptions(array $clientOptions, array $callOptions, bool $disabled): void { $http = new MockedHttpClient('app.posthog.com'); @@ -136,6 +138,7 @@ public function testMinimalExposurePreservesGeoipOption(): void $this->assertArrayNotHasKey('$lib_consumer', $event['properties']); } + #[IgnoreDeprecations] public function testLegacyFlagEvaluationInheritsClientOption(): void { $http = new MockedHttpClient('app.posthog.com'); diff --git a/test/MultivariateIntegrationTest.php b/test/MultivariateIntegrationTest.php index 9207055..7591d57 100644 --- a/test/MultivariateIntegrationTest.php +++ b/test/MultivariateIntegrationTest.php @@ -2,11 +2,13 @@ namespace PostHog\Test; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use PostHog\Client; class MultivariateIntegrationTest extends TestCase { + #[IgnoreDeprecations] public function testMultivariateFlagDependencies(): void { // Create a client with mock multivariate flags that have dependencies @@ -118,6 +120,7 @@ public function testMultivariateFlagDependencies(): void $this->assertTrue($foundOtherVariant, "Should have found at least one user that gets other variants"); } + #[IgnoreDeprecations] public function testBooleanFlagDependencyOnMultivariate(): void { // Test a boolean flag that depends on any variant of a multivariate flag diff --git a/test/PostHogTest.php b/test/PostHogTest.php index 248a2b3..ce60eca 100644 --- a/test/PostHogTest.php +++ b/test/PostHogTest.php @@ -6,6 +6,8 @@ require_once 'test/error_log_mock.php'; use Exception; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use RuntimeException; use PostHog\Client; @@ -262,11 +264,8 @@ public function testClientTrimsWhitespaceSensitiveConfig(): void $ref = new \ReflectionClass($client); $apiKeyProp = $ref->getProperty('apiKey'); - $apiKeyProp->setAccessible(true); $personalApiKeyProp = $ref->getProperty('personalAPIKey'); - $personalApiKeyProp->setAccessible(true); $optionsProp = $ref->getProperty('options'); - $optionsProp->setAccessible(true); $this->assertEquals('random_key', $apiKeyProp->getValue($client)); $this->assertNull($personalApiKeyProp->getValue($client)); @@ -282,9 +281,7 @@ public static function secretKeyCredentialCases(): array ]; } - /** - * @dataProvider secretKeyCredentialCases - */ + #[DataProvider('secretKeyCredentialCases')] public function testSecretKeyResolution(?string $secretKey, ?string $personalApiKey, string $expected): void { $client = new Client(self::FAKE_API_KEY, [], $this->http_client, $personalApiKey, false, secretKey: $secretKey); @@ -296,7 +293,6 @@ public function testSecretKeyResolution(?string $secretKey, ?string $personalApi private function readPrivate(Client $client, string $property): mixed { $prop = (new \ReflectionClass($client))->getProperty($property); - $prop->setAccessible(true); return $prop->getValue($client); } @@ -319,17 +315,14 @@ public function testInitWithHttpHostSetsSslFalse(): void $client = PostHog::getClient(); $ref = new \ReflectionClass($client); $consumerProp = $ref->getProperty('consumer'); - $consumerProp->setAccessible(true); $consumer = $consumerProp->getValue($client); $cRef = new \ReflectionClass($consumer); $httpProp = $cRef->getProperty('httpClient'); - $httpProp->setAccessible(true); $httpClient = $httpProp->getValue($consumer); $hRef = new \ReflectionClass($httpClient); $sslProp = $hRef->getProperty('useSsl'); - $sslProp->setAccessible(true); $this->assertFalse($sslProp->getValue($httpClient), 'HttpClient should use ssl=false for http:// hosts'); } @@ -341,12 +334,10 @@ public function testInitDefaultsBlankHostAfterTrimmingWhitespace(): void $client = PostHog::getClient(); $ref = new \ReflectionClass($client); $consumerProp = $ref->getProperty('consumer'); - $consumerProp->setAccessible(true); $consumer = $consumerProp->getValue($client); $cRef = new \ReflectionClass($consumer); $hostProp = $cRef->getProperty('host'); - $hostProp->setAccessible(true); $this->assertEquals('us.i.posthog.com', $hostProp->getValue($consumer)); } @@ -358,17 +349,14 @@ public function testInitWithWhitespacePaddedHttpHostSetsSslFalse(): void $client = PostHog::getClient(); $ref = new \ReflectionClass($client); $consumerProp = $ref->getProperty('consumer'); - $consumerProp->setAccessible(true); $consumer = $consumerProp->getValue($client); $cRef = new \ReflectionClass($consumer); $httpProp = $cRef->getProperty('httpClient'); - $httpProp->setAccessible(true); $httpClient = $httpProp->getValue($consumer); $hRef = new \ReflectionClass($httpClient); $sslProp = $hRef->getProperty('useSsl'); - $sslProp->setAccessible(true); $this->assertFalse($sslProp->getValue($httpClient), 'HttpClient should use ssl=false for whitespace-padded http:// hosts'); } @@ -380,17 +368,14 @@ public function testInitWithHttpsHostSetsSslTrue(): void $client = PostHog::getClient(); $ref = new \ReflectionClass($client); $consumerProp = $ref->getProperty('consumer'); - $consumerProp->setAccessible(true); $consumer = $consumerProp->getValue($client); $cRef = new \ReflectionClass($consumer); $httpProp = $cRef->getProperty('httpClient'); - $httpProp->setAccessible(true); $httpClient = $httpProp->getValue($consumer); $hRef = new \ReflectionClass($httpClient); $sslProp = $hRef->getProperty('useSsl'); - $sslProp->setAccessible(true); $this->assertTrue($sslProp->getValue($httpClient), 'HttpClient should use ssl=true for https:// hosts'); } @@ -403,17 +388,14 @@ public function testInitWithEnvHttpHostSetsSslFalse(): void $client = PostHog::getClient(); $ref = new \ReflectionClass($client); $consumerProp = $ref->getProperty('consumer'); - $consumerProp->setAccessible(true); $consumer = $consumerProp->getValue($client); $cRef = new \ReflectionClass($consumer); $httpProp = $cRef->getProperty('httpClient'); - $httpProp->setAccessible(true); $httpClient = $httpProp->getValue($consumer); $hRef = new \ReflectionClass($httpClient); $sslProp = $hRef->getProperty('useSsl'); - $sslProp->setAccessible(true); $this->assertFalse($sslProp->getValue($httpClient), 'HttpClient should use ssl=false for http:// env host'); @@ -434,9 +416,7 @@ public function testInitWithoutApiKeyConfiguresNoOpClient(): void }); } - /** - * @dataProvider initNoOpApiKeyCases - */ + #[DataProvider('initNoOpApiKeyCases')] public function testInitWithBlankApiKeyConfiguresNoOpClient(string $apiKey): void { $this->withEnvApiKey(null, function () use ($apiKey) { @@ -459,16 +439,13 @@ public function testInitWithEmptyApiKeyFallsBackToEnvApiKey(): void $ref = new \ReflectionClass($client); $apiKeyProp = $ref->getProperty('apiKey'); - $apiKeyProp->setAccessible(true); $this->assertSame(self::FAKE_API_KEY, $apiKeyProp->getValue($client)); $this->assertNotInstanceOf(NoOp::class, $this->getConsumer($client)); }); } - /** - * @dataProvider disabledClientNoRequestCases - */ + #[DataProvider('disabledClientNoRequestCases')] public function testClientWithBlankApiKeyDoesNotSendRequests(?string $apiKey, string $flagsMethod): void { $httpClient = new MockedHttpClient("app.posthog.com"); @@ -483,9 +460,7 @@ public function testClientWithBlankApiKeyDoesNotSendRequests(?string $apiKey, st $this->assertSame([], $httpClient->calls ?? []); } - /** - * @dataProvider queuedBatchSizeCases - */ + #[DataProvider('queuedBatchSizeCases')] public function testCapturesStayQueuedUntilFlush(array $options): void { $httpClient = new MockedHttpClient("app.posthog.com"); @@ -660,9 +635,7 @@ public function testBeforeSendThrowingCallbackDropsEvent(): void $this->assertSame([], $httpClient->calls ?? []); } - /** - * @dataProvider invalidBeforeSendCases - */ + #[DataProvider('invalidBeforeSendCases')] public function testBeforeSendInvalidCallbackPathsCaptureOriginalEvent(mixed $beforeSend): void { $httpClient = new MockedHttpClient("app.posthog.com"); @@ -691,9 +664,8 @@ public static function invalidBeforeSendCases(): iterable } - /** - * @dataProvider facadeNoOpBeforeInitCases - */ + #[DataProvider('facadeNoOpBeforeInitCases')] + #[IgnoreDeprecations] public function testFacadeMethodsNoOpBeforeInit(callable $call, mixed $expectedValue): void { $this->unsetFacadeClient(); @@ -771,9 +743,7 @@ public function testCapture(): void ); } - /** - * @dataProvider captureGroupsCases - */ + #[DataProvider('captureGroupsCases')] public function testCaptureAddsGroupsProperty(string $groupsKey): void { self::assertTrue( @@ -902,9 +872,7 @@ public static function invalidCaptureFlushIntervalCases(): array ]; } - /** - * @dataProvider invalidCaptureFlushIntervalCases - */ + #[DataProvider('invalidCaptureFlushIntervalCases')] public function testInvalidCaptureFlushIntervalDefaultsToFiveSeconds(mixed $flushInterval): void { $mockClock = new MockClock(new \DateTimeImmutable('2022-05-01 00:00:00')); @@ -942,9 +910,7 @@ public function testInvalidCaptureFlushIntervalDefaultsToFiveSeconds(mixed $flus } } - /** - * @dataProvider validTopLevelUuidCases - */ + #[DataProvider('validTopLevelUuidCases')] public function testCaptureKeepsValidTopLevelUuid(string $uuid): void { self::assertTrue( @@ -963,9 +929,7 @@ public function testCaptureKeepsValidTopLevelUuid(string $uuid): void self::assertSame($uuid, $event['uuid']); } - /** - * @dataProvider invalidTopLevelUuidCases - */ + #[DataProvider('invalidTopLevelUuidCases')] public function testCaptureReplacesInvalidTopLevelUuid(mixed $uuid): void { self::assertTrue( @@ -985,9 +949,7 @@ public function testCaptureReplacesInvalidTopLevelUuid(mixed $uuid): void $this->assertValidUuidV4($event['uuid']); } - /** - * @dataProvider invalidTopLevelUuidCases - */ + #[DataProvider('invalidTopLevelUuidCases')] public function testRawReplacesInvalidTopLevelUuid(mixed $uuid): void { $this->client->raw( @@ -1153,6 +1115,7 @@ public function testCaptureOmitsIsServerPropertyWhenDisabled(): void self::assertArrayNotHasKey('$is_server', $properties); } + #[IgnoreDeprecations] public function testCaptureWithSendFeatureFlagsOption(): void { $this->executeAtFrozenDateTime(new \DateTime('2022-05-01'), function () { @@ -1210,6 +1173,7 @@ public function testCaptureWithSendFeatureFlagsOption(): void }); } + #[IgnoreDeprecations] public function testCaptureWithLocalSendFlags(): void { $this->http_client = new MockedHttpClient(host: "app.posthog.com", flagEndpointResponse: MockedResponses::LOCAL_EVALUATION_MULTIPLE_REQUEST); @@ -1257,6 +1221,7 @@ public function testCaptureWithLocalSendFlags(): void }); } + #[IgnoreDeprecations] public function testCaptureWithLocalSendFlagsNoOverrides(): void { $this->http_client = new MockedHttpClient(host: "app.posthog.com", flagEndpointResponse: MockedResponses::LOCAL_EVALUATION_MULTIPLE_REQUEST); @@ -1617,6 +1582,7 @@ public function testGroupIdentifyValidation(): void PostHog::groupIdentify([]); } + #[IgnoreDeprecations] public function testDefaultPropertiesGetAddedProperly(): void { PostHog::getFeatureFlag('random_key', 'some_id', array("company" => "id:5", "instance" => "app.posthog.com"), array("x1" => "y1"), array("company" => array("x" => "y")));