function testPostMakesSuccessfulRequestWithClient()
 {
     $client = $this->getMockBuilder('\\Test\\HTTPClient')->getMock();
     $client->method('post')->with($this->equalTo('https://api.gathercontent.com/accounts'), $this->equalTo(['account_id' => '100']), $this->equalTo($this->default_headers))->willReturn(dummyObject(['status' => '202', 'body' => '']));
     $subject = new Request($client);
     $response = $subject->post('accounts', ['account_id' => '100']);
     $this->assertTrue($response->wasSuccessful());
     $this->assertNull($response->fetch('key'));
 }
 function testAllReturnsCollectionOfAccounts()
 {
     $http_response = dummyObject(['status' => '200', 'body' => '{"data":[{"id":1,"name":"Name","slug":"slug","timezone":"UTC"}]}']);
     $request = $this->getMockBuilder('\\Test\\Request')->getMock();
     $request->method('get')->with($this->equalTo('accounts'))->willReturn(new \GatherContent\Response($http_response));
     $subject = new AccountCollection($request);
     $accounts = $subject->all();
     $this->assertCount(1, $accounts);
     $account = $accounts[0];
     $this->assertInstanceOf('\\GatherContent\\Model\\Account', $account);
     $this->assertSame(1, $account->id);
     $this->assertEquals('Name', $account->name);
     $this->assertEquals('slug', $account->slug);
     $this->assertEquals('UTC', $account->timezone);
 }
 function testAllReturnsCollectionOfProjects()
 {
     $http_response = dummyObject(['status' => '200', 'body' => '{"data":[{"id":2,"account_id":1,"active":true,"name":"Project","overdue":false,"text_direction":"ltr"}]}']);
     $request = $this->getMockBuilder('\\Test\\Request')->getMock();
     $request->method('get')->with($this->equalTo('projects'), $this->equalTo(['account_id' => 1]))->willReturn(new \GatherContent\Response($http_response));
     $subject = new ProjectCollection($request);
     $projects = $subject->forAccountId(1);
     $this->assertCount(1, $projects);
     $project = $projects[0];
     $this->assertInstanceOf('\\GatherContent\\Model\\Project', $project);
     $this->assertSame(2, $project->id);
     $this->assertSame(1, $project->account_id);
     $this->assertEquals('Project', $project->name);
     $this->assertEquals('ltr', $project->text_direction);
     $this->assertTrue($project->active);
     $this->assertFalse($project->overdue);
 }
 function testForItemIdReturnsCollectionOfFiles()
 {
     $http_response = dummyObject(['status' => '200', 'body' => '{"data":[{"id":2,"item_id":1,"size":121,"field":"el1","filename":"food.jpg","url":"http://example.com/b33f"}]}']);
     $request = $this->getMockBuilder('\\Test\\Request')->getMock();
     $request->method('get')->with($this->equalTo('items/1/files'))->willReturn(new \GatherContent\Response($http_response));
     $subject = new FileCollection($request);
     $files = $subject->forItemId(1);
     $this->assertCount(1, $files);
     $file = $files[0];
     $this->assertInstanceOf('\\GatherContent\\Model\\File', $file);
     $this->assertSame(2, $file->id);
     $this->assertSame(1, $file->item_id);
     $this->assertSame(121, $file->size);
     $this->assertEquals('el1', $file->field);
     $this->assertEquals('food.jpg', $file->filename);
     $this->assertEquals('http://example.com/b33f', $file->url);
 }
 function testForProjectIdReturnsCollectionOfItems()
 {
     $http_response = dummyObject(['status' => '200', 'body' => '{"data":[{"id":2,"name":"Item","overdue":false,"parent_id":1,"position":0,"project_id":2,"template_id":3}]}']);
     $request = $this->getMockBuilder('\\Test\\Request')->getMock();
     $request->method('get')->with($this->equalTo('items'), $this->equalTo(['project_id' => '2']))->willReturn(new \GatherContent\Response($http_response));
     $subject = new ItemCollection($request);
     $items = $subject->forProjectId('2');
     $this->assertCount(1, $items);
     $item = $items[0];
     $this->assertInstanceOf('\\GatherContent\\Model\\Item', $item);
     $this->assertSame(2, $item->id);
     $this->assertSame(1, $item->parent_id);
     $this->assertSame(0, $item->position);
     $this->assertSame(2, $item->project_id);
     $this->assertSame(3, $item->template_id);
     $this->assertEquals('Item', $item->name);
     $this->assertFalse($item->overdue);
 }
 function testFetchReturnsNullWhenKeyDoesNotExist()
 {
     $http_response = dummyObject(['status' => 200, 'body' => '{"key":"value"}']);
     $subject = new Response($http_response);
     $this->assertNull($subject->fetch('missing'));
 }