Skip to content

Instantly share code, notes, and snippets.

@nevercodealone
Created November 24, 2018 13:01
Show Gist options
  • Save nevercodealone/19dfcd7886d3b4a2cce3344b36e31fef to your computer and use it in GitHub Desktop.
Save nevercodealone/19dfcd7886d3b4a2cce3344b36e31fef to your computer and use it in GitHub Desktop.
<?php namespace NCATesting\service;
use App\Service\YouTubeService;
use Codeception\Stub;
use NCATesting\UnitTester;
use Mockery as m;
class YouTubeServiceCest
{
private $fixture;
public function _before(UnitTester $I)
{
$_ENV['GOOGLE_API_KEY'] = 'testify';
$this->fixture = new YouTubeService();
}
// tests
public function getItemsFromChannelReverseArrayFromPlaylistItemsListByPlaylistId(UnitTester $I)
{
$array = [
'one',
'two',
'three'
];
$externalMock = m::mock('overload:\Google_Service_YouTube');
$externalMock->shouldReceive('foo')
->once()
->andReturn($array)
->set('playlistItems', 'listPlaylistItems')
;
$externalMock->playlistItems = 'listPlaylistItems';
$obj = new \stdClass();
$obj->playlistItems = new \stdClass();
$obj->playlistItems->listPlaylistItems = $array
$this->fixture = Stub::make(
$this->fixture,
[
'playlistItemsListByPlaylistId' => ['items' => $array]
]
);
$itemsFromChannel = $this->fixture->getItemsFromChannel();
$I->assertSame(array_reverse($array), $itemsFromChannel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment