protected function createNodeReportFromValidatorResult(\SimpleHealth\ValidatorResult $result, Collection $endpoint_reports) { if ($result->pass === true) { return new \SimpleHealth\NodeReport(true, StringLiteral::fromNative(''), $endpoint_reports); } else { return new \SimpleHealth\NodeReport(false, $result->message, $endpoint_reports); } }
public function isValid(Collection $reports) { foreach ($reports->toArray() as $report) { if ($report->pass === false) { return new ValidatorResult(false, $report->message); } } return new ValidatorResult(true, StringLiteral::fromNative('')); }
public function check() { try { $response = $this->mechanism->request(); } catch (\GuzzleHttp\Exception\TransferException $ex) { return new EndpointReport($this->endpoint, false, StringLiteral::fromNative($ex->getMessage())); } $report = $this->validator->isValid($response); return new EndpointReport($this->endpoint, $report->pass, $report->message); }
public function testWhenThereIsAFailedReport() { $report_mock = \Mockery::mock('\\SimpleHealth\\EndpointReport'); $report_mock->pass = false; $report_mock->message = StringLiteral::fromNative(''); $reports = new Collection(\SplFixedArray::fromArray([$report_mock])); $subject = new NodeValidator(); $report = $subject->isValid($reports); $this->assertEquals($report->pass, false); }
public function testWhenMechanismWorksTheCorrectReportIsReturned() { $mechanism_mock = \Mockery::mock('\\SimpleHealth\\EndpointMechanismInterface'); $validator_mock = \Mockery::mock('\\SimpleHealth\\ValidatorInterface'); $response_mock = \Mockery::mock('\\Guzzle\\ResponseInterface'); $report_mock = \Mockery::mock('\\SimpleHealth\\ValidatorResult'); $mechanism_mock->shouldReceive('request')->andReturn($response_mock); $validator_mock->shouldReceive('isValid')->andReturn($report_mock); $report_mock->pass = true; $report_mock->message = StringLiteral::fromNative(''); $healthcheck = new EndpointHealthCheck(Url::fromNative('http://www.php.net'), $mechanism_mock, $validator_mock); $report = $healthcheck->check(); $this->assertEquals($report->pass, true); }
public function testFromNative() { $string = StringLiteral::fromNative('foo'); $constructedString = new StringLiteral('foo'); $this->assertTrue($string->sameValueAs($constructedString)); }