-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle array in formatting helpers + tests (#341)
- Loading branch information
Showing
3 changed files
with
143 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atymic\Twitter\Tests\Unit\ApiV1\Traits; | ||
|
||
use Atymic\Twitter\Tests\Unit\AccessorTestCase; | ||
use Exception; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
||
abstract class ConcernTestCase extends AccessorTestCase | ||
{ | ||
protected MockObject $subject; | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->subject = $this->getMockForTrait($this->getTraitName()); | ||
} | ||
|
||
abstract protected function getTraitName(): string; | ||
} |
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,57 @@ | ||
<?php | ||
/** | ||
* @noinspection PhpParamsInspection | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atymic\Twitter\Tests\Unit\ApiV1\Traits; | ||
|
||
use Atymic\Twitter\ApiV1\Traits\FormattingHelpers; | ||
|
||
final class FormattingHelpersTest extends ConcernTestCase | ||
{ | ||
/** | ||
* @dataProvider dataGetUserLink | ||
*/ | ||
public function testGetUserLink($user): void | ||
{ | ||
$this->assertSame( | ||
'https://twitter.com/atymic', | ||
$this->subject->linkUser($user) | ||
); | ||
} | ||
|
||
public function dataGetUserLink(): array | ||
{ | ||
return [ | ||
'string' => ['atymic'], | ||
'object' => [(object) ['screen_name' => 'atymic']], | ||
'array' => [['screen_name' => 'atymic']], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider dataLinkAddTweetToFavorites | ||
*/ | ||
public function testLinkAddTweetToFavorites($tweet): void | ||
{ | ||
$this->assertSame( | ||
'https://twitter.com/intent/favorite?tweet_id=1381031025053155332', | ||
$this->subject->linkAddTweetToFavorites($tweet) | ||
); | ||
} | ||
|
||
public function dataLinkAddTweetToFavorites(): array | ||
{ | ||
return [ | ||
'object' => [(object) ['id_str' => '1381031025053155332']], | ||
'array' => [['id_str' => '1381031025053155332']], | ||
]; | ||
} | ||
|
||
protected function getTraitName(): string | ||
{ | ||
return FormattingHelpers::class; | ||
} | ||
} |