-
Notifications
You must be signed in to change notification settings - Fork 14
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
fix: support both snake_case and camelCase versions of impression data #227
Conversation
@@ -75,7 +75,7 @@ public function testUnreadableFile() | |||
$file = $this->createTemporaryFile(); | |||
chmod($file, 0222); | |||
$instance = new FileBootstrapProvider($file); | |||
$this->expectException(RuntimeException::class); | |||
$this->expectException(JsonException::class); |
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.
@RikudouSage I couldn't check your comments as I'm struggling with this test that fails locally. I'm building this Dockerfile (docker build . -t php-with-composer
) to reduce noise and make it reproducible:
FROM php:8.3.10-fpm
# Install system dependencies and clean cache
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
libcurl4-openssl-dev libssl-dev \
zip \
unzip
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Copy Composer from the official Composer image
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY . /usr/src/unleash-client-php
WORKDIR /usr/src/unleash-client-php
RUN rm -f composer.lock
RUN composer install
CMD ["sh"]
And running the tests as: docker run -it --rm --name my-running-script php-with-composer composer phpunit
and the test fails with the following error:
$ docker run -it --rm --name my-running-script php-with-composer composer phpunit
> phpunit
PHPUnit 9.6.21 by Sebastian Bergmann and contributors.
Runtime: PHP 8.3.10
Configuration: /usr/src/unleash-client-php/phpunit.xml
.........F..................................................... 63 / 233 ( 27%)
............................................................... 126 / 233 ( 54%)
............................................................... 189 / 233 ( 81%)
............................................ 233 / 233 (100%)
Time: 00:25.133, Memory: 20.00 MB
There was 1 failure:
1) Unleash\Client\Tests\Bootstrap\FileBootstrapProviderTest::testUnreadableFile
Failed asserting that exception of type "JsonException" matches expected exception "RuntimeException". Message was: "Syntax error" at
/usr/src/unleash-client-php/src/Bootstrap/FileBootstrapProvider.php:46
/usr/src/unleash-client-php/tests/Bootstrap/FileBootstrapProviderTest.php:79
.
FAILURES!
Tests: 233, Assertions: 895, Failures: 1.
Script phpunit handling the phpunit event returned with error code 1
Do you know what can it be?
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.
CI does prefer RuntimeException...
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.
I don't :/ But JsonException generally means that there was a syntax error in some JSON, any chance you're providing a non-JSON string somewhere where JSON is expected?
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.
Ah, figured it out, I assume you run the container under its default user, root? The test creates a file and makes it non-readable using chmod, but root has access to everything regardless of read/write permissions, thus the file is readable but because it's empty it fails with a JsonException.
If I run it as the current user, it works:
docker run --rm -it -u $(id -u):$(id -g) php-with-composer vendor/bin/phpunit
src/DTO/DefaultProxyFeature.php
Outdated
* impression_data?: bool, | ||
* impressionData?: bool |
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.
One will be set, the other won't, we don't know which one because it depends on the version of the backend
src/DTO/DefaultProxyFeature.php
Outdated
@@ -88,6 +92,7 @@ public function jsonSerialize(): array | |||
'enabled' => $this->enabled, | |||
'variant' => $this->variant, | |||
'impression_data' => $this->impressionData, | |||
'impressionData' => $this->impressionData, // maybe we don't need this |
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.
I'm unsure what are we using this serialization for... maybe caching?
* impression_data?: bool, | ||
* impressionData?: bool |
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.
One will be set, the other won't, we don't know which one because it depends on the version of the backend
@@ -87,7 +90,8 @@ public function jsonSerialize(): array | |||
'name' => $this->name, | |||
'enabled' => $this->enabled, | |||
'variant' => $this->variant, | |||
'impression_data' => $this->impressionData, | |||
'impression_data' => $this->impressionData, // deprecated |
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.
We output both formats because this is public and might be in use.
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.
LGTM
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.
Looks good!
Description
Impression data should have always been camelCase in unleash-edge. It was not by accident, and the php sdk is using the snake_case version which prevents users from upgrading to newer versions of edge where impression_data was changed to camelCase.
Fixes #226
Type of change
How Has This Been Tested?
Checklist: