-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #520 from thephpleague/fix/query-string-separator
Ensure generated query strings are consistent
- Loading branch information
Showing
4 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* This file is part of the league/oauth2-client library | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Alex Bilbie <[email protected]> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
* @link http://thephpleague.com/oauth2-client/ Documentation | ||
* @link https://packagist.org/packages/league/oauth2-client Packagist | ||
* @link https://github.com/thephpleague/oauth2-client GitHub | ||
*/ | ||
|
||
namespace League\OAuth2\Client\Tool; | ||
|
||
/** | ||
* Provides a standard way to generate query strings. | ||
*/ | ||
trait QueryBuilderTrait | ||
{ | ||
/** | ||
* Build a query string from an array. | ||
* | ||
* @param array $params | ||
* | ||
* @return string | ||
*/ | ||
protected function buildQueryString(array $params) | ||
{ | ||
return http_build_query($params, null, '&'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Client\Test\Tool; | ||
|
||
use League\OAuth2\Client\Tool\QueryBuilderTrait; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
class QueryBuilderTraitTest extends PHPUnit_Framework_TestCase | ||
{ | ||
use QueryBuilderTrait; | ||
|
||
public function setUp() | ||
{ | ||
ini_set('arg_separator.output', '&'); | ||
} | ||
|
||
public function testBuildQueryString() | ||
{ | ||
$params = [ | ||
'a' => 'foo', | ||
'b' => 'bar', | ||
]; | ||
|
||
$query = $this->buildQueryString($params); | ||
|
||
$this->assertSame('a=foo&b=bar', $query); | ||
} | ||
} |