Help with guzzle async request

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Blitze
Registered User
Posts: 387
Joined: Tue Nov 29, 2005 5:06 pm

Help with guzzle async request

Post by Blitze » Mon Jan 28, 2019 5:05 am

So I am testing this ajax request in a functional test that requires me (i think) to use a callback (closure) to then test the results of the request. It works just fine locally for php 5.5.9 but fails on travis for php 5.4, 5.5 and 5.6. I have tried every which way I can think of but it still fails. My understanding is that as of php 5.4, you can access $this or self in a closure but I get the error PHP Fatal error: Call to a member function request() on a non-object in /home/travis/build/phpBB3/tests/test_framework/phpbb_functional_test_case.php on line 139.

Here's my code: https://github.com/blitze/phpBB-ext-sit ... e_test.php

and here's the travis build: https://travis-ci.org/blitze/phpBB-ext- ... /485189998

Please help.
My Extensions: phpBB SiteMaker

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4918
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Help with guzzle async request

Post by VSE » Thu Jan 31, 2019 2:55 am

Maybe self::request is out of the scope of the closure, so maybe you need something like:

Code: Select all

$request = self::request;
$promise->then(function($response) use($request) {
	$crawler = $request('GET', 'index.php?edit_mode=1');
}
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

Blitze
Registered User
Posts: 387
Joined: Tue Nov 29, 2005 5:06 pm

Re: Help with guzzle async request

Post by Blitze » Fri Feb 01, 2019 5:42 am

Thank for looking into this VSE. I tried that too but got a Fatal error: Undefined class constant 'request' at the $request = self::request line. I did try the following but again, it passed locally for php 5.5.9 but failed on travis for php 5.4, 5.5, and 5.6:

Code: Select all

$self = __class__;
$response->then(function($response) use ($self) {
	$crawler = $self::request('GET', 'index.php?edit_mode=1');
});
Since accessing $this or self in a closure is supposed to work as of PHP 5.4, it almost seems as though the goutte client gets reset in the closure. Not sure what to do. May be try to recreate the travis build locally in a docker container or maybe I should just scrap the test. I've put too much time on it.

Thanks
My Extensions: phpBB SiteMaker

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3907
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Help with guzzle async request

Post by kasimi » Fri Feb 01, 2019 8:38 am

I don't have a clue, and like you already said this shouldn't be necessary since PHP 5.4, but this is how you can reference a static method:

Code: Select all

$request = ['self', 'request'];
$response->then(function($response) use ($request) {
    $crawler = call_user_func($request, 'GET', 'index.php?edit_mode=1');
});

Blitze
Registered User
Posts: 387
Joined: Tue Nov 29, 2005 5:06 pm

Re: Help with guzzle async request

Post by Blitze » Fri Feb 01, 2019 10:41 am

Thanks for your response Kasimi. Unfortunately, the travis build failed with the same error. Not sure what to do next...
My Extensions: phpBB SiteMaker

Blitze
Registered User
Posts: 387
Joined: Tue Nov 29, 2005 5:06 pm

Re: Help with guzzle async request

Post by Blitze » Sat Feb 02, 2019 9:54 pm

I still don't know why the build was failing on travis but I found another way to make an ajax request without using guzzle. I set the proper headers on the goutte client and it works. Whew!!!
My Extensions: phpBB SiteMaker

Post Reply

Return to “Extension Writers Discussion”