From 51da587cd39f7e858a05fe39536d3e7a243d3770 Mon Sep 17 00:00:00 2001 From: Sviat <178153165+devSviat@users.noreply.github.com> Date: Fri, 4 Dec 2026 18:23:35 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20timestamp=5Fmicros=20=D1=83=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BD=D0=B5=D0=BD=D0=BD=D1=96=20?= =?UTF-8?q?=E2=80=94=20=D1=86=D1=96=D0=BB=D0=B5=20=D1=87=D0=B8=D1=81=D0=BB?= =?UTF-8?q?=D0=BE=20=D0=BC=D1=96=D0=BA=D1=80=D0=BE=D1=81=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D0=BD=D0=B4=20=D1=80=D1=8F=D0=B4=D0=BA=D0=BE=D0=BC=20(1.1.1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (string)microtime(true) * 1000000 множив уже рядок, і в JSON ішло число з плаваючою комою. Тепер (string)(int)(…). Знайшов PHPStan 2.3.7; додано тест. --- Helpers/RefundHelper.php | 2 +- Init/module.json | 2 +- tests/RefundTimestampTest.php | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/RefundTimestampTest.php diff --git a/Helpers/RefundHelper.php b/Helpers/RefundHelper.php index 2c0e1b5..3c16b89 100644 --- a/Helpers/RefundHelper.php +++ b/Helpers/RefundHelper.php @@ -165,7 +165,7 @@ private function buildPayload(object $order, array $built): array $payload = [ 'client_id' => (string)$cid, - 'timestamp_micros' => (string)microtime(true) * 1000000, + 'timestamp_micros' => (string)(int)(microtime(true) * 1000000), 'non_personalized_ads' => false, 'events' => [ [ diff --git a/Init/module.json b/Init/module.json index 947a700..278746e 100644 --- a/Init/module.json +++ b/Init/module.json @@ -1,6 +1,6 @@ { "Okay": "4.5.3", - "version": "1.1.0", + "version": "1.1.1", "moduleName": "Аналітика GA4", "vendor": { "email": "devsviat@proton.me", diff --git a/tests/RefundTimestampTest.php b/tests/RefundTimestampTest.php new file mode 100644 index 0000000..f5802d3 --- /dev/null +++ b/tests/RefundTimestampTest.php @@ -0,0 +1,48 @@ +createStub(CurrenciesEntity::class); + $currencies->method('getMainCurrency')->willReturn((object) ['code' => 'UAH']); + $entityFactory = $this->createStub(EntityFactory::class); + $entityFactory->method('get')->willReturn($currencies); + + $helper = new RefundHelper( + $entityFactory, + new ReflectionClass(AnalyticsHelper::class)->newInstanceWithoutConstructor(), + new ReflectionClass(Settings::class)->newInstanceWithoutConstructor(), + ); + + $before = (int) (microtime(true) * 1000000); + $payload = new ReflectionMethod(RefundHelper::class, 'buildPayload')->invoke( + $helper, + (object) ['id' => 7, 'cid' => '1.2', 'sid' => '', 'user_id' => 0], + ['items' => [], 'shipping' => 0, 'value' => 10], + ); + $after = (int) (microtime(true) * 1000000); + + $micros = $payload['timestamp_micros']; + self::assertIsString($micros); + self::assertMatchesRegularExpression('/^\d{16}$/', $micros); + self::assertGreaterThanOrEqual($before, (int) $micros); + self::assertLessThanOrEqual($after, (int) $micros); + self::assertMatchesRegularExpression('/"timestamp_micros":"\d{16}"/', json_encode($payload)); + } +}