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

Avoid BC break in TextResult #56

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

VincentLanglet
Copy link
Contributor

Hi @JanEbbing

The commit 04403a0 introduce a BC break by changing the signature of this class, but was tagged as a minor.

The model type used should have a default value to avoid BC break, especially when null is allowed.

@JanEbbing
Copy link
Member

Hi @VincentLanglet , do you instantiate TextResults in tests or why does this break something for you? I would discourage usage like that, imo it's better to explicitly access the properties (eg text on TextResult) and run assertions against that.

That said, I do agree with this PR.

@VincentLanglet
Copy link
Contributor Author

Hi @VincentLanglet , do you instantiate TextResults in tests or why does this break something for you? I would discourage usage like that, imo it's better to explicitly access the properties (eg text on TextResult) and run assertions against that.

That said, I do agree with this PR.

Yes, I do instantiate one TextResult in tests to simulate a response of an API. With something like

$deeplTranslatorClient->method('translateText')->willReturnCallback(
            static function (array $payload, string $from) use (&$translateCalls): array {
                ++$translateCalls;
                if (1 === $translateCalls % 2) {
                    throw new DeepLException('Odd calls are failing');
                }

                return array_map(
                    static fn (string $text): TextResult => new TextResult(
                        \sprintf('translated(%s)', $text),
                        $from,
                        0
                    ),
                    $payload
                );
            }
        );

Copy link
Member

@daniel-jones-dev daniel-jones-dev left a comment

Choose a reason for hiding this comment

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

Sorry for this oversight @VincentLanglet; I assumed this class was internal and wouldn't be used by users, but testing is a valid use-case.

Thanks for the PR.

@JanEbbing JanEbbing self-requested a review November 29, 2024 10:30
@JanEbbing JanEbbing merged commit c49af6e into DeepLcom:main Nov 29, 2024
@VincentLanglet VincentLanglet deleted the fixTextResult branch November 29, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants