koel/tests/Unit/Services/LastfmServiceTest.php

43 lines
1.2 KiB
PHP
Raw Normal View History

2017-12-09 22:39:34 +00:00
<?php
namespace Tests\Unit\Services;
2018-08-18 13:19:40 +00:00
use App\Services\LastfmService;
use Mockery;
use Mockery\Mock;
2017-12-09 22:39:34 +00:00
use Tests\TestCase;
class LastfmServiceTest extends TestCase
2017-12-09 22:39:34 +00:00
{
public function testBuildAuthCallParams(): void
2017-12-09 22:39:34 +00:00
{
/** @var Mock|LastfmService $lastfm */
$lastfm = Mockery::mock(LastfmService::class)->makePartial();
$lastfm->shouldReceive('getKey')->andReturn('key');
$lastfm->shouldReceive('getSecret')->andReturn('secret');
2017-12-09 22:39:34 +00:00
$params = [
'qux' => '安',
'bar' => 'baz',
];
// When I build Last.fm-compatible API parameters using the raw parameters
$builtParams = $lastfm->buildAuthCallParams($params);
$builtParamsAsString = $lastfm->buildAuthCallParams($params, true);
2017-12-09 22:39:34 +00:00
// Then I receive the Last.fm-compatible API parameters
2020-09-06 18:21:39 +00:00
self::assertEquals([
2017-12-09 22:39:34 +00:00
'api_key' => 'key',
'bar' => 'baz',
'qux' => '安',
'api_sig' => '7f21233b54edea994aa0f23cf55f18a2',
], $builtParams);
// And the string version as well
2020-09-06 18:21:39 +00:00
self::assertEquals(
2017-12-09 22:39:34 +00:00
'api_key=key&bar=baz&qux=安&api_sig=7f21233b54edea994aa0f23cf55f18a2',
$builtParamsAsString
);
}
}