oerdnj / deb.sury.org

Public bugreports for anything ppa:ondrej/*
835 stars 26 forks source link

Mocking OAuth not working since 2.0.9 #2237

Open langemeijer opened 6 days ago

langemeijer commented 6 days ago

Frequently asked questions

Describe the bug Since the oauth 2.0.9 (2.0.9-1+0~20241126.37+debian12~1.gbp4c2d5a) I cannot mock (using phpunit) the OAuth class anymore. This worked using 2.0.7++-4+0~20241125.36+debian12~1.gbpe3d442.

To Reproduce This test succeeded with 2.0.7++ and breaks with 2.0.9:

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

#[Group('unit')]
final class AuthorizationTest extends TestCase
{
    #[Test]
    public function minimalTestCase(): void {
        $consumerKey = 'ajkshjdng';
        $consumerSecret = 'asdhj3h4h34j';

        $oauth = $this->getMockBuilder(OAuth::class)
            ->setConstructorArgs([$consumerKey, $consumerSecret])
            ->getMock();

        $oauth
            ->method('getRequestToken')
            ->with()
            ->willReturnMap(
                [
                    ['fakeurl.org', null, ['oauth_token' => 'liajsdjwiu34', 'oauth_token_secret' => 'asdfhhherwer3']],
                ]
            );

        $tokenData = $oauth->getRequestToken('fakeurl.org');

        self::assertEquals('liajsdjwiu34', $tokenData['oauth_token']);
        self::assertEquals('asdfhhherwer3', $tokenData['oauth_token_secret']);
    }
}

Additional context I understand that I might have to take this issue upstream, but because I don't know what's in the ++'s in the 2.0.7++ version this might not be a regression at all, from a oauth-dev standpoint.

oerdnj commented 6 days ago

The ++ is just a workaround for packaging, the version is identical to 2.0.7

oerdnj commented 1 day ago

@langemeijer Have you reported this to the upstream?

langemeijer commented 23 hours ago

I have now: https://github.com/php/pecl-web_services-oauth/issues/32

oerdnj commented 22 hours ago

Thank you, please ping me if there's an upstream patch. I can pull it before an official release.