public function testItWorks() { $mock = M::mock('mindofmicah\\GoodReads\\Curl'); $mock->shouldReceive('fetchInfo')->once()->andReturn(file_get_contents(__DIR__ . '/stubs/shelves/list.txt')); $response = Request::shelves('list', array('id' => 21308373), $mock); $this->assertInstanceOf('mindofmicah\\GoodReads\\Response', $response); $this->assertInstanceOf('mindofmicah\\GoodReads\\ResponseObj', $response->get('shelves')); $this->assertEquals('shelf_list', $response->headers('method')); $first_shelf = $response->get('shelves'); $this->assertInstanceOf('mindofmicah\\GoodReads\\ResponseObj', $first_shelf); $first_child = current($first_shelf->child()); // print_r($first_child); $this->assertEquals('user_shelf', $first_child[0]->getType()); $this->assertEquals(1, count($response->get('shelves'))); }
/** * Check default value works * * Mock a method of the class and mock the http client handler * * @covers Cpeter\PhpQkeylmEmailNotification\Qkeylm\QkeylmApi::getDailyJournal */ public function testGetDailyJournal() { // Create a mock and queue a few responses. $mock = new MockHandler([new Response(200, ['Content-Length' => 0]), new Response(200, ['X-Foo' => 'Bar'], '<body> <div> <h1> Friday 11 March 2016 </h1> <div id="mainInner"> <img class="image-frame" src="http://www.host.org/webui/Files/Room/small/my/image.jpg"> </div> </div> </body> '), new Response(200, ['Content-Length' => 0]), new Response(200, ['Content-Length' => 0])]); $handler = HandlerStack::create($mock); $mock = M::mock('Cpeter\\PhpQkeylmEmailNotification\\Qkeylm\\QkeylmApi[login]', [['host' => 'http://www.host.org', 'page_journal' => '/journal_page', 'page_journal_date' => '/journal_page_print', 'child_name' => 'Adel', 'handler' => $handler]]); $mock->shouldReceive('login')->andReturn(true); $journal = $mock->getDailyJournal(); $this->assertTrue(isset($journal['images']['http://www.host.org/webui/Files/Room/small/my/image.jpg'])); $this->assertTrue(isset($journal['body'])); $this->assertTrue($journal['date'] == '2016-03-11'); }