Added some tests
Close to 65% coverage, just went for the low hanging fruit, mostly happy path.
This commit is contained in:
parent
a0de82967e
commit
13a407afa8
6 changed files with 79 additions and 0 deletions
BIN
tests/.AYAHTest.php.swp
Normal file
BIN
tests/.AYAHTest.php.swp
Normal file
Binary file not shown.
BIN
tests/.bootstrap.php.swp
Normal file
BIN
tests/.bootstrap.php.swp
Normal file
Binary file not shown.
BIN
tests/.phpunit.xml.swp
Normal file
BIN
tests/.phpunit.xml.swp
Normal file
Binary file not shown.
50
tests/AYAHTest.php
Normal file
50
tests/AYAHTest.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
class AYAHTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
// These keys are just for testing...
|
||||
private $config = [
|
||||
'publisher_key' => '01f70454bada303692be5f36a8fd104eba8b00dd',
|
||||
'scoring_key' => '80cc3f9c6e1da29369c238d55bd8528a968473ad',
|
||||
];
|
||||
|
||||
private $ayah;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->ayah = new AYAH($this->config);
|
||||
$this->ayah->debug_mode(false);
|
||||
}
|
||||
|
||||
public function testInstanceOf()
|
||||
{
|
||||
$this->assertInstanceOf('AYAH', $this->ayah);
|
||||
}
|
||||
|
||||
public function testGetPublisherHTML()
|
||||
{
|
||||
$this->assertRegExp(
|
||||
'/<div id=\'AYAH\'><\/div><script src=\'https:\/\/ws.areyouahuman.com\/ws\/script\/[a-z0-9]{40}\/ip[a-zA-Z0-9]{43}\' type=\'text\/javascript\' language=\'JavaScript\'><\/script>/',
|
||||
$this->ayah->getPublisherHTML()
|
||||
);
|
||||
}
|
||||
|
||||
// Unfortunately there's no way to test a true response (mock maybe?)
|
||||
public function testScoreResultFailure()
|
||||
{
|
||||
$this->assertFalse($this->ayah->scoreResult());
|
||||
}
|
||||
|
||||
public function testRecordConversionMissingSessionSecret()
|
||||
{
|
||||
$this->assertFalse($this->ayah->recordConversion());
|
||||
}
|
||||
|
||||
public function testDebugMode()
|
||||
{
|
||||
$this->expectOutputRegex('/Debug mode is now on./');
|
||||
$this->assertTrue($this->ayah->debug_mode(true));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
7
tests/bootstrap.php
Normal file
7
tests/bootstrap.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
ini_set('date.timezone', 'UTC');
|
||||
|
||||
require '../src/ayah.php';
|
||||
|
||||
?>
|
22
tests/phpunit.xml
Normal file
22
tests/phpunit.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<phpunit
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
|
||||
bootstrap="bootstrap.php"
|
||||
colors="true"
|
||||
strict="true"
|
||||
verbose="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Are You A Human? Tests">
|
||||
<directory>./</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<logging>
|
||||
<log
|
||||
type="coverage-html"
|
||||
target="/tmp/php-ayah"
|
||||
charset="UTF-8"
|
||||
highlight="true"
|
||||
/>
|
||||
</logging>
|
||||
</phpunit>
|
Loading…
Add table
Add a link
Reference in a new issue