Created
May 21, 2015 23:26
-
-
Save DuffleOne/75bbe0501e173668ea14 to your computer and use it in GitHub Desktop.
Base spec for Pushman PHP Library
This file contains hidden or 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
<?php | |
namespace spec\Pushman\PHPLib; | |
use GuzzleHttp\Client; | |
use GuzzleHttp\Message\Response; | |
use GuzzleHttp\Stream\Stream; | |
use GuzzleHttp\Subscriber\Mock; | |
use PhpSpec\ObjectBehavior; | |
use Prophecy\Argument; | |
class PushmanSpec extends ObjectBehavior { | |
function let() | |
{ | |
$client = new Client(); | |
$mock = $this->buildMockResponses(); | |
$client->getEmitter()->attach($mock); | |
$this->beConstructedWith('Qu48pcP2DSUBHA64nHxAhuv7S74He13GuBGZz5ebNeOplyKhzEPw8lk38LdN', [], $client); | |
} | |
function it_is_initializable() | |
{ | |
$this->shouldHaveType('Pushman\PHPLib\Pushman'); | |
} | |
function it_should_grab_a_channel_token() | |
{ | |
$tokenTest = $this->token('public'); | |
$tokenTest->shouldbeArray(); | |
$tokenTest->shouldHaveKey('token'); | |
} | |
function it_should_return_an_array_of_channels() | |
{ | |
$channelTest = $this->channels(); | |
$channelTest->shouldBeArray(); | |
} | |
function it_should_return_a_single_channels_information() | |
{ | |
$channelTest = $this->channel('public'); | |
$channelTest->shouldBeArray(); | |
$channelTest->shouldHaveKey('name'); | |
$channelTest->shouldHaveKey('public'); | |
$channelTest->shouldHaveKey('id'); | |
} | |
function it_should_push_an_event_to_pushman() | |
{ | |
$eventPush = $this->push('test_event'); | |
$eventPush->shouldBeArray(); | |
$eventPush->shouldHaveSomething('status'); | |
$eventPush->shouldHaveCount(7); | |
#$eventPush->shouldHaveKeyWithValue('status', 'value'); | |
} | |
public function getMatchers() | |
{ | |
return [ | |
'haveSomething' => function ($subject, $key) { | |
die(var_dump($subject, $key)); | |
} | |
]; | |
} | |
function it_should_not_allow_for_blank_event_names() | |
{ | |
} | |
function it_should_not_allow_spaces_in_event_names() | |
{ | |
} | |
function it_should_now_allow_spaces_in_channel_names() | |
{ | |
} | |
private function buildMockResponses() | |
{ | |
$channelsMockResponse = new Response(200); | |
$channelsMockResponseBody = Stream::factory(fopen(__DIR__ . '/../../../tests/channels.txt', 'r+')); | |
$channelsMockResponse->setBody($channelsMockResponseBody); | |
$channelMockResponse = new Response(200); | |
$channelMockResponseBody = Stream::factory(fopen(__DIR__ . '/../../../tests/channel.txt', 'r+')); | |
$channelMockResponse->setBody($channelMockResponseBody); | |
$pushMockResponse = new Response(200); | |
$pushMockResponseBody = Stream::factory(fopen(__DIR__ . '/../../../tests/push.txt', 'r+')); | |
$pushMockResponse->setBody($pushMockResponseBody); | |
$mock = new Mock([ | |
$channelMockResponse, | |
$channelsMockResponse, | |
$channelMockResponse, | |
$pushMockResponse | |
]); | |
return $mock; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment