/** * Test method for the <tt>setTags($setTagsRequest)</tt> function. * * @group PushwooshTest.setTags */ public function testSetTags() { // Create a fake CURL client $cURLClient = $this->getMock('Gomoob\\Pushwoosh\\ICURLClient'); $cURLClient->expects($this->any())->method('pushwooshCall')->will($this->returnValue(array('status_code' => 200, 'status_message' => 'OK'))); $pushwoosh = new Pushwoosh(); $pushwoosh->setCURLClient($cURLClient); $setTagsRequest = SetTagsRequest::create()->setHwid('hwid')->setTag('tag0', 'tag0Value')->setTag('tag1', 'tag1Value'); // Test with the 'application' parameter not defined try { $pushwoosh->setTags($setTagsRequest); $this->fail('Must have thrown a PushwooshException !'); } catch (PushwooshException $pe) { // Expected } // Test with the 'application' parameter defined in the Pushwoosh client $pushwoosh->setApplication('APPLICATION'); $setTagsRequest->setApplication(null); $pushwoosh->setTags($setTagsRequest); // Test with the 'application' parameter definied in the request $pushwoosh->setApplication(null); $setTagsRequest->setApplication('APPLICATION'); $setTagsResponse = $pushwoosh->setTags($setTagsRequest); $this->assertTrue($setTagsResponse->isOk()); $this->assertEquals(200, $setTagsResponse->getStatusCode()); $this->assertEquals('OK', $setTagsResponse->getStatusMessage()); // Test a call with an error response $cURLClient = $this->getMock('Gomoob\\Pushwoosh\\ICURLClient'); $cURLClient->expects($this->any())->method('pushwooshCall')->will($this->returnValue(array('status_code' => 400, 'status_message' => 'KO'))); $pushwoosh->setCURLClient($cURLClient); $setTagsResponse = $pushwoosh->setTags($setTagsRequest); $this->assertFalse($setTagsResponse->isOk()); $this->assertEquals(400, $setTagsResponse->getStatusCode()); $this->assertEquals('KO', $setTagsResponse->getStatusMessage()); }