Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanKeeble committed Jun 2, 2017
1 parent faf7286 commit 5e6f213
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 73 deletions.
10 changes: 4 additions & 6 deletions tests/Api/AgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ class AgentTest extends TestCase
/** @test */
public function it_can_find_a_list_of_agents()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('agents', [])
->once()
->andReturn(json_decode('{"agents": [{}]}'));

$agents = (new Agent($client))->list();
$agents = (new Agent($this->mockedClient))->list();

$this->assertInstanceOf(Collection::class, $agents);
$this->assertInstanceOf(AgentModel::class, $agents[0]);
Expand All @@ -30,14 +29,13 @@ public function it_can_find_a_list_of_agents()
/** @test */
public function it_can_find_an_agent()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('agents/'.self::AGENT_EMAIL)
->once()
->andReturn(json_decode('{"agent": {"email" : "'.self::AGENT_EMAIL.'"}}'));

$agent = (new Agent($client))->find(self::AGENT_EMAIL);
$agent = (new Agent($this->mockedClient))->find(self::AGENT_EMAIL);

$this->assertInstanceOf(AgentModel::class, $agent);
$this->assertEquals(self::AGENT_EMAIL, $agent->email);
Expand Down
5 changes: 2 additions & 3 deletions tests/Api/AttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ class AttachmentTest extends TestCase
/** @test */
public function it_can_list_attachments()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('attachments', ['message' => 'messageID'])
->once()
->andReturn(json_decode('{"attachments": [{}]}'));

$attachments = (new Attachment($client))->list('messageID');
$attachments = (new Attachment($this->mockedClient))->list('messageID');

$this->assertInstanceOf(Collection::class, $attachments);
$this->assertInstanceOf(AttachmentModel::class, $attachments[0]);
Expand Down
15 changes: 6 additions & 9 deletions tests/Api/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ class CustomerTest extends TestCase
/** @test */
public function it_can_find_a_list_of_customers()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('customers', [])
->once()
->andReturn(json_decode('{"customers": [{}]}'));

$customers = (new Customer($client))->list();
$customers = (new Customer($this->mockedClient))->list();

$this->assertInstanceOf(Collection::class, $customers);
$this->assertInstanceOf(CustomerModel::class, $customers[0]);
Expand All @@ -30,14 +29,13 @@ public function it_can_find_a_list_of_customers()
/** @test */
public function it_can_find_a_customer()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('customers/'.self::CUSTOMER_EMAIL)
->once()
->andReturn(json_decode('{"customer": {"email": "'.self::CUSTOMER_EMAIL.'"}}'));

$customer = (new Customer($client))->find(self::CUSTOMER_EMAIL);
$customer = (new Customer($this->mockedClient))->find(self::CUSTOMER_EMAIL);

$this->assertInstanceOf(CustomerModel::class, $customer);
$this->assertEquals(self::CUSTOMER_EMAIL, $customer->email);
Expand All @@ -46,14 +44,13 @@ public function it_can_find_a_customer()
/** @test */
public function it_can_update_a_customer()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('put')
->with('customers/'.self::CUSTOMER_EMAIL, ['email' => 'updated@email.com'])
->once()
->andReturn(json_decode('{"customer": {"email": "updated@email.com"}}'));

$customer = (new Customer($client))->update(self::CUSTOMER_EMAIL, 'updated@email.com');
$customer = (new Customer($this->mockedClient))->update(self::CUSTOMER_EMAIL, 'updated@email.com');

$this->assertInstanceOf(CustomerModel::class, $customer);
$this->assertEquals('updated@email.com', $customer->email);
Expand Down
5 changes: 2 additions & 3 deletions tests/Api/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ class FolderTest extends TestCase
/** @test */
public function it_can_list_folders()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('folders', [])
->once()
->andReturn(json_decode('{"folders": [{"name": "a folder"}]}'));

$folders = (new Folder($client))->list();
$folders = (new Folder($this->mockedClient))->list();

$this->assertInstanceOf(Collection::class, $folders);
$this->assertInstanceOf(FolderModel::class, $folders[0]);
Expand Down
5 changes: 2 additions & 3 deletions tests/Api/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ class GroupTest extends TestCase
/** @test */
public function it_can_list_groups()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('groups')
->once()
->andReturn(json_decode('{"groups": [{}]}'));

$groups = (new Group($client))->list();
$groups = (new Group($this->mockedClient))->list();

$this->assertInstanceOf(Collection::class, $groups);
$this->assertInstanceOf(GroupModel::class, $groups[0]);
Expand Down
5 changes: 2 additions & 3 deletions tests/Api/MailboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ class MailboxTest extends TestCase
/** @test */
public function it_can_list_mailboxes()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('mailboxes')
->once()
->andReturn(json_decode('{"mailboxes": [{}]}'));

$agents = (new Mailbox($client))->list();
$agents = (new Mailbox($this->mockedClient))->list();

$this->assertInstanceOf(Collection::class, $agents);
$this->assertInstanceOf(MailboxModel::class, $agents[0]);
Expand Down
15 changes: 6 additions & 9 deletions tests/Api/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ class MessageTest extends TestCase
/** @test */
public function it_can_list_messages()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('tickets/ticketNumber/messages', [])
->once()
->andReturn(json_decode('{"messages": [{}]}'));

$messages = (new Message($client))->list('ticketNumber');
$messages = (new Message($this->mockedClient))->list('ticketNumber');

$this->assertInstanceOf(Collection::class, $messages);
$this->assertInstanceOf(MessageModel::class, $messages[0]);
Expand All @@ -28,14 +27,13 @@ public function it_can_list_messages()
/** @test */
public function it_can_find_a_message()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('messages/messageId')
->once()
->andReturn(json_decode('{"message": {"body" : "message body"}}'));

$message = (new Message($client))->find('messageId');
$message = (new Message($this->mockedClient))->find('messageId');

$this->assertInstanceOf(MessageModel::class, $message);
$this->assertEquals('message body', $message->body);
Expand All @@ -44,14 +42,13 @@ public function it_can_find_a_message()
/** @test */
public function it_can_create_a_message()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('post')
->with('tickets/ticketNumber/messages', ['body' => 'a new message'])
->once()
->andReturn(json_decode('{"message": {"body" : "a new message"}}'));

$message = (new Message($client))->create('ticketNumber', 'a new message');
$message = (new Message($this->mockedClient))->create('ticketNumber', 'a new message');

$this->assertInstanceOf(MessageModel::class, $message);
$this->assertEquals('a new message', $message->body);
Expand Down
45 changes: 18 additions & 27 deletions tests/Api/TicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ class TicketTest extends TestCase
/** @test */
public function it_can_create_a_ticket()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('post')
->with('tickets', ['body' => self::TICKET_BODY, 'from' => self::TICKET_FROM, 'to' => self::TICKET_TO])
->once()
->andReturn(json_decode('{"ticket": {"body": "'.self::TICKET_BODY.'"}}'));

$ticket = (new Ticket($client))->create(self::TICKET_BODY, self::TICKET_FROM, self::TICKET_TO);
$ticket = (new Ticket($this->mockedClient))->create(self::TICKET_BODY, self::TICKET_FROM, self::TICKET_TO);

$this->assertInstanceOf(TicketModel::class, $ticket);
$this->assertEquals(self::TICKET_BODY, $ticket->body);
Expand All @@ -33,14 +32,13 @@ public function it_can_create_a_ticket()
/** @test */
public function it_can_find_a_list_of_tickets()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('tickets', [])
->once()
->andReturn(json_decode('{"tickets": [{}]}'));

$tickets = (new Ticket($client))->list();
$tickets = (new Ticket($this->mockedClient))->list();

$this->assertInstanceOf(Collection::class, $tickets);
$this->assertInstanceOf(TicketModel::class, $tickets[0]);
Expand All @@ -49,14 +47,13 @@ public function it_can_find_a_list_of_tickets()
/** @test */
public function it_can_find_a_ticket()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('tickets/'.self::TICKET_NUMBER)
->once()
->andReturn(json_decode('{"ticket": {"number": "'.self::TICKET_NUMBER.'"}}'));

$ticket = (new Ticket($client))->find(self::TICKET_NUMBER);
$ticket = (new Ticket($this->mockedClient))->find(self::TICKET_NUMBER);

$this->assertInstanceOf(TicketModel::class, $ticket);
$this->assertEquals(self::TICKET_NUMBER, $ticket->number);
Expand All @@ -65,86 +62,80 @@ public function it_can_find_a_ticket()
/** @test */
public function it_can_update_a_tickets_assignee()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('put')
->with('tickets/'.self::TICKET_NUMBER.'/assignee', ['assignee' => 'assignee@email.com'])
->once();

$updated = (new Ticket($client))->updateAssignee(self::TICKET_NUMBER, 'assignee@email.com');
$updated = (new Ticket($this->mockedClient))->updateAssignee(self::TICKET_NUMBER, 'assignee@email.com');

$this->assertTrue($updated);
}

/** @test */
public function it_can_update_a_tickets_priority()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('put')
->with('tickets/'.self::TICKET_NUMBER.'/priority', ['priority' => 'urgent'])
->once();

$updated = (new Ticket($client))->updatePriority(self::TICKET_NUMBER, 'urgent');
$updated = (new Ticket($this->mockedClient))->updatePriority(self::TICKET_NUMBER, 'urgent');

$this->assertTrue($updated);
}

/** @test */
public function it_can_update_a_tickets_group()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('put')
->with('tickets/'.self::TICKET_NUMBER.'/assigned_group', ['group' => 'groupID'])
->once();

$updated = (new Ticket($client))->updateGroup(self::TICKET_NUMBER, 'groupID');
$updated = (new Ticket($this->mockedClient))->updateGroup(self::TICKET_NUMBER, 'groupID');

$this->assertTrue($updated);
}

/** @test */
public function it_can_find_a_tickets_state()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('tickets/'.self::TICKET_NUMBER.'/state')
->once()
->andReturn('unread');

$status = (new Ticket($client))->ticketState(self::TICKET_NUMBER);
$status = (new Ticket($this->mockedClient))->ticketState(self::TICKET_NUMBER);

$this->assertEquals('unread', $status);
}

/** @test */
public function it_can_find_a_tickets_assignee()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('tickets/'.self::TICKET_NUMBER.'/assignee')
->once()
->andReturn('test@email.com');

$assignee = (new Ticket($client))->ticketAssignee(self::TICKET_NUMBER);
$assignee = (new Ticket($this->mockedClient))->ticketAssignee(self::TICKET_NUMBER);

$this->assertEquals('test@email.com', $assignee);
}

/** @test */
public function it_can_find_a_tickets_count()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('get')
->with('tickets/count')
->once()
->andReturn('123');

$assignee = (new Ticket($client))->count();
$assignee = (new Ticket($this->mockedClient))->count();

$this->assertEquals('123', $assignee);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/Api/WebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ class WebhookTest extends TestCase
/** @test */
public function it_can_create_a_webhook()
{
$client = $this->getMockClient();
$client
$this->mockedClient
->shouldReceive('post')
->with('webhooks', ['event' => 'groove-event', 'url' => 'your-url'])
->once()
->andReturn(json_decode('{"webhook": {"event": "groove-event", "url": "your-url"}}'));

$webhook = (new Webhook($client))->create('groove-event', 'your-url');
$webhook = (new Webhook($this->mockedClient))->create('groove-event', 'your-url');

$this->assertInstanceOf(WebhookModel::class, $webhook);
$this->assertEquals($webhook->event, 'groove-event');
Expand Down
13 changes: 6 additions & 7 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

abstract class TestCase extends PHPUnitTestCase
{
/**
* Get mocked client.
*
* @return Mockery\Mock
*/
public function getMockClient()
protected $mockedClient;

protected function setUp()
{
return Mockery::mock(Groove::class, ['accessToken'])->makePartial();
parent::setUp();

$this->mockedClient = Mockery::mock(Groove::class, ['accessToken'])->makePartial();
}
}

0 comments on commit 5e6f213

Please sign in to comment.