Skip to content

Commit

Permalink
NEW Add CheckSuite::addCheckDetail and finish tests for CheckSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Dec 20, 2017
1 parent a9aa6df commit 5160045
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/CheckSuite.php
Expand Up @@ -151,14 +151,32 @@ public function addCheckDetail($key, array $metrics)
}

/**
* Get the details result for the checks in this suite
* Get the detailed results for the checks in this suite
* @return array
*/
public function getCheckDetails()
{
return $this->checkDetails;
}

/**
* Get the detailed result for one of the checks in this suite
*
* @param string $key
* @return array
* @throws Exception If the check was not in the details
*/
public function getCheckDetail($key)
{
$checks = $this->getCheckDetails();

if (isset($checks[$key])) {
return $checks[$key];
}

throw new Exception('Check with code ' . $key. ' was not found');
}

/**
* Get the registered check class instances
*
Expand Down
50 changes: 50 additions & 0 deletions tests/CheckSuiteTest.php
Expand Up @@ -66,4 +66,54 @@ public function testRunWithDelegatedCallback()
$this->assertTrue($called, 'Callback method was run');
$this->assertSame(5, $this->checkSuite->getPoints(), 'Callback method delegated');
}

public function testGetSetAddPoints()
{
$this->assertSame(0, $this->checkSuite->getPoints());

$this->checkSuite->setPoints(100);
$this->assertSame(100, $this->checkSuite->getPoints());

$this->checkSuite->addPoints(5);
$this->assertSame(105, $this->checkSuite->getPoints());
}

public function testGetSetAddCheckDetails()
{
$this->assertSame([], $this->checkSuite->getCheckDetails());

$this->checkSuite->setCheckDetails([
'some_check' => ['foo' => 'bar'],
]);
$this->assertSame(['foo' => 'bar'], $this->checkSuite->getCheckDetails()['some_check']);

$this->checkSuite->addCheckDetail('another_check', ['metric' => 10]);
$this->assertSame(['metric' => 10], $this->checkSuite->getCheckDetail('another_check'));
}

/**
* @expectedException Exception
*/
public function testGetCheckDetailThrowsExceptionOnUnknownCheck()
{
$this->checkSuite->getCheckDetail('some_check_that_doesnt_exist');
}

public function testGetSetAddChecks()
{
$this->checkSuite->setChecks([]);
$this->assertEmpty($this->checkSuite->getChecks());

$this->checkSuite->addCheck(new CheckSuiteTest\StubCheckFail());
$this->assertContainsOnlyInstancesOf(Check::class, $this->checkSuite->getChecks());
}

public function testSetModuleRoot()
{
$this->checkSuite->setModuleRoot('foo/bar');
$this->assertSame('foo/bar', $this->checkSuite->getModuleRoot());

$this->checkSuite->setModuleRoot('foo/bar/');
$this->assertSame('foo/bar', $this->checkSuite->getModuleRoot());
}
}

0 comments on commit 5160045

Please sign in to comment.