/** * @covers PingdomGateway::addOrModifyAlert */ public function testAddOrModifyAlert() { $getChecks = (object) ['checks' => [(object) ['id' => 578657, 'name' => '/dev/check/suite', 'hostname' => 'test.com', 'resolution' => 1, 'type' => 'http', 'status' => 'UP']]]; $this->api->expects($this->at(0))->method('request')->with($this->equalTo('GET'), $this->equalTo('checks'))->will($this->returnValue($getChecks)); $getCheck = (object) ['check' => (object) ['id' => 578657, 'name' => '/dev/check/suite', 'hostname' => 'test.com', 'resolution' => 1, 'type' => (object) ['http' => (object) ['encryption' => true, 'url' => '/dev/check/suite']], 'encryption' => true, 'status' => 'UP']]; $this->api->expects($this->at(1))->method('request')->with($this->equalTo('GET'), $this->equalTo('checks/578657'))->will($this->returnValue($getCheck)); $postNotificationContact = (object) ['contact' => (object) ['id' => 123456, 'name' => 'contact name']]; $this->api->expects($this->at(2))->method('request')->with($this->equalTo('POST'), $this->equalTo('notification_contacts'))->will($this->returnValue($postNotificationContact)); $putCheck = (object) ['message' => 'silly message']; $this->api->expects($this->at(3))->method('request')->with($this->equalTo('PUT'), $this->equalTo('checks/578657'))->will($this->returnValue($putCheck)); $pw = PingdomGateway::create(); $success = $pw->addOrModifyAlert('https://test.com/dev/check/suite', [['email' => '*****@*****.**', 'name' => 'contact name']], 1, false); $this->assertEquals($pw->getLastError(), null); $this->assertTrue($success); }
/** * @param array $params * @return array */ public function findExistingCheck($params) { $checks = $this->getChecks(); $url = $params['encryption'] ? 'https://' : 'http://'; $url .= $params['host'] . $params['url']; foreach ($checks as $check) { if ($check->hostname != $params['host']) { continue; } $detailedCheck = $this->pingdom->getCheck($check->id); $existingUrl = $this->getCheckURL($detailedCheck); // we found an existing check if ($existingUrl == $url) { return $detailedCheck; } } }