This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'github/master'
- Loading branch information
Showing
8 changed files
with
171 additions
and
7 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
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
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,82 @@ | ||
<?php | ||
|
||
namespace seregazhuk\tests\Bot\Api; | ||
|
||
use Mockery; | ||
use PHPUnit_Framework_TestCase; | ||
use seregazhuk\PinterestBot\Api\Request; | ||
use seregazhuk\PinterestBot\Api\Response; | ||
use seregazhuk\PinterestBot\Api\ProvidersContainer; | ||
use seregazhuk\PinterestBot\Api\Providers\Core\Provider; | ||
use seregazhuk\PinterestBot\Api\Traits\ResolvesCurrentUsername; | ||
|
||
/** | ||
* Class ProviderTest. | ||
*/ | ||
class ResolvesCurrentUsernameTest extends PHPUnit_Framework_TestCase | ||
{ | ||
protected function tearDown() | ||
{ | ||
Mockery::close(); | ||
} | ||
|
||
/** @test */ | ||
public function it_calls_user_provider_to_get_current_user_name() | ||
{ | ||
$username = 'John Doe'; | ||
|
||
$provider = $this->makeProvider($this->makeRequest($username)); | ||
|
||
$this->assertEquals($username, $provider->getCurrentUserName()); | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @return DummyUsernameProvider | ||
*/ | ||
protected function makeProvider(Request $request) | ||
{ | ||
$container = new ProvidersContainer($request, new Response()); | ||
|
||
/** @var DummyUsernameProvider $provider */ | ||
$provider = Mockery::mock(DummyUsernameProvider::class, [$container])->makePartial(); | ||
|
||
return $provider; | ||
} | ||
|
||
protected function makeRequest($username) | ||
{ | ||
/** @var Request $request */ | ||
$request = Mockery::mock(Request::class) | ||
->shouldReceive('exec') | ||
->andReturn(json_encode($this->makePinterestProfileResponse($username))) | ||
->getMock(); | ||
|
||
$request->shouldReceive('isLoggedIn')->andReturn(true); | ||
|
||
return $request; | ||
} | ||
|
||
/** | ||
* @param $username | ||
* @return array | ||
*/ | ||
protected function makePinterestProfileResponse($username) | ||
{ | ||
return ['resource_response' => ['data' => ['username' => $username]]]; | ||
} | ||
} | ||
|
||
|
||
class DummyUsernameProvider extends Provider { | ||
|
||
use ResolvesCurrentUsername; | ||
|
||
/** | ||
* @return array|bool|Response | ||
*/ | ||
public function getCurrentUserName() | ||
{ | ||
return $this->resolveCurrentUsername(); | ||
} | ||
} |