Skip to content
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

Closed
wants to merge 13 commits into from

Conversation

gastonfournier
Copy link
Contributor

@gastonfournier gastonfournier commented Sep 24, 2024

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit tests
  • Spec Tests
  • Integration tests / Manual Tests

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

src/DTO/DefaultProxyFeature.php Show resolved Hide resolved
src/DTO/DefaultProxyFeature.php Outdated Show resolved Hide resolved
src/Repository/DefaultUnleashProxyRepository.php Outdated Show resolved Hide resolved
tests/DTO/DefaultProxyFeatureTest.php Show resolved Hide resolved
@@ -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);
Copy link
Contributor Author

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI does prefer RuntimeException...

Copy link
Collaborator

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?

Copy link
Collaborator

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

Comment on lines 31 to 32
* impression_data?: bool,
* impressionData?: bool
Copy link
Contributor Author

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

@@ -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
Copy link
Contributor Author

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?

Comment on lines 156 to 157
* impression_data?: bool,
* impressionData?: bool
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@RikudouSage RikudouSage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@gastonfournier
Copy link
Contributor Author

image

Commit was merged in main, Github had some issue with this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Bug: validateResponse fails on impression_data
3 participants