-
Notifications
You must be signed in to change notification settings - Fork 26
feat(version upgrade)!: Bump to PHP8.5 #98
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
Changes from all commits
aa4ae35
bcd4c7a
0f6e282
24d87ba
7a99297
2708f73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| use PostHog\Consumer\ForkCurl; | ||
| use PostHog\Consumer\LibCurl; | ||
| use PostHog\Consumer\Socket; | ||
| use Symfony\Component\Clock\Clock; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. total PHP noob is it necessary to go from standard library time to Symfony? is there something that could trip us up here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a sneaky one, the https://github.com/slope-it/clock-mock#mocked-functionsmethods library modifies the standard library and replaced the We needed to switch this to the Symfony clock in order to be able to manipulate it during our testing (same with the case in |
||
|
|
||
| const SIZE_LIMIT = 50_000; | ||
|
|
||
|
|
@@ -829,7 +830,7 @@ private function formatTime($ts) | |
| { | ||
| // time() | ||
| if (null == $ts || !$ts) { | ||
| $ts = time(); | ||
| $ts = Clock::get()->now()->getTimestamp(); | ||
| } | ||
| if (false !== filter_var($ts, FILTER_VALIDATE_INT)) { | ||
| return date("c", (int)$ts); | ||
|
|
@@ -841,7 +842,7 @@ private function formatTime($ts) | |
| return date("c", strtotime($ts)); | ||
| } | ||
|
|
||
| return date("c"); | ||
| return date("c", Clock::get()->now()->getTimestamp()); | ||
| } | ||
|
|
||
| // fix for floatval casting in send.php | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,9 +114,6 @@ public function sendRequest(string $path, ?string $payload, array $extraHeaders | |
| $httpResponse = $this->executePost($ch, $includeEtag); | ||
| $responseCode = $httpResponse->getResponseCode(); | ||
|
|
||
| //close connection | ||
| curl_close($ch); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer required as per: https://www.php.net/manual/en/migration85.deprecated.php#curl This is default behaviour since PHP 8.0: https://www.php.net/manual/en/class.curlhandle.php |
||
|
|
||
| // Handle 304 Not Modified - this is a success, not an error | ||
| if ($responseCode === 304) { | ||
| if ($this->debug) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,30 @@ | ||
| <?xml version="1.0"?> | ||
| <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
| xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" | ||
| backupGlobals="true" | ||
| backupStaticAttributes="false" | ||
| backupStaticProperties="false" | ||
| colors="true" | ||
| convertErrorsToExceptions="true" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explanation of the chnages: |
||
| convertNoticesToExceptions="true" | ||
| convertWarningsToExceptions="true" | ||
| forceCoversAnnotation="false" | ||
| processIsolation="false" | ||
| stopOnError="false" | ||
| stopOnFailure="false" | ||
| stopOnIncomplete="false" | ||
| stopOnSkipped="false" | ||
| stopOnRisky="false" | ||
| timeoutForSmallTests="1" | ||
| timeoutForMediumTests="10" | ||
| timeoutForLargeTests="60" | ||
| verbose="false" | ||
| cacheDirectory=".phpunit.cache" | ||
| > | ||
| <coverage processUncoveredFiles="true"> | ||
| <include> | ||
| <directory suffix=".php">./lib</directory> | ||
| </include> | ||
| <coverage includeUncoveredFiles="true"> | ||
| <report> | ||
| <text outputFile="php://stdout" showUncoveredFiles="true"/> | ||
| </report> | ||
| </coverage> | ||
| <source> | ||
| <include> | ||
| <directory suffix=".php">./lib</directory> | ||
| </include> | ||
| </source> | ||
| <testsuites> | ||
| <testsuite name="posthog-php"> | ||
| <directory>test</directory> | ||
| </testsuite> | ||
| </testsuites> | ||
| <logging/> | ||
| </phpunit> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| namespace PostHog\Test; | ||
|
|
||
| use Symfony\Component\Clock\Clock; | ||
| use Symfony\Component\Clock\MockClock; | ||
| use Symfony\Component\Clock\NativeClock; | ||
|
|
||
| /** | ||
| * Trait providing time mocking functionality for tests using Symfony Clock. | ||
| * This replaces the slope-it/clock-mock dependency which required the uopz extension. | ||
| */ | ||
|
Comment on lines
+9
to
+12
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahhhhhh ok, so the switch to symfony is for this mocking? in which case, alongside the "is it correct/safe" question, is this (and i hate this word) idiomatic for PHP
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah traits are quite a common pattern within PHP, and they are frequently used to house "common / reusable methods" that span across a hierarchical / compositional object structure. + The added benefit here is that we cna have it act as a drop in replacement without changing much in the underlying function calls 😄 . Here is a blog post of how Laravel does it (from 2023), which is one of the most popular PHP frameworks: https://laraveldaily.com/post/traits-laravel-eloquent-examples (or rather how |
||
| trait ClockMockTrait | ||
| { | ||
| /** | ||
| * Execute a callback with a frozen date/time. | ||
| * This mimics the behavior of SlopeIt\ClockMock\ClockMock::executeAtFrozenDateTime() | ||
| * | ||
| * @param \DateTimeInterface $dateTime The date/time to freeze to | ||
| * @param callable $callback The callback to execute | ||
| * @return mixed The return value of the callback | ||
| */ | ||
| protected function executeAtFrozenDateTime(\DateTimeInterface $dateTime, callable $callback): mixed | ||
| { | ||
| $mockClock = new MockClock($dateTime instanceof \DateTimeImmutable | ||
| ? $dateTime | ||
| : \DateTimeImmutable::createFromInterface($dateTime)); | ||
|
|
||
| Clock::set($mockClock); | ||
|
|
||
| try { | ||
| return $callback(); | ||
| } finally { | ||
| // Reset to real clock | ||
| Clock::set(new NativeClock()); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we need to bump to version 4 in here or it's automated?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work out of the box once I follow the steps listed here: https://github.com/PostHog/posthog-php/blob/master/RELEASING.md!
There is nothing happening automatically, but I will obviously tag it with v4 😄 !