Skip to content

Commit 6240208

Browse files
committed
Added functional tests. Most tests are still in the separate software nameapi-client-php-functionaltests.
1 parent 7e2d75c commit 6240208

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
require '../../src/org/nameapi/client/services/ServiceFactory.php';
4+
use org\nameapi\client\services\Host;
5+
use org\nameapi\client\services\ServiceFactory;
6+
use org\nameapi\ontology\input\context\Context;
7+
use org\nameapi\ontology\input\context\Priority;
8+
9+
10+
/**
11+
*
12+
* This is just one simple call. For all functional tests see the separate project at
13+
* https://github.com/optimaize/nameapi-client-php-functionaltests
14+
*
15+
*
16+
*/
17+
class DisposableEmailAddressDetectorServiceTest extends \PHPUnit_Framework_TestCase {
18+
19+
public function testDea() {
20+
//setup code:
21+
$context = Context::builder()
22+
->priority(Priority::REALTIME())
23+
->build();
24+
$myApiKey = 'test'; //grab one from nameapi.org
25+
$serviceFactory = new ServiceFactory($myApiKey, $context, Host::http('rc50-api.nameapi.org'), '5.0');
26+
27+
//the call:
28+
$deaDetector = $serviceFactory->emailServices()->disposableEmailAddressDetector();
29+
$result = $deaDetector->isDisposable("[email protected]");
30+
31+
//the assertions:
32+
$this->assertEquals('YES', (string)$result->getDisposable());
33+
}
34+
35+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
require '../../src/org/nameapi/client/services/ServiceFactory.php';
4+
use org\nameapi\client\services\Host;
5+
use org\nameapi\client\services\ServiceFactory;
6+
use org\nameapi\ontology\input\context\Context;
7+
use org\nameapi\ontology\input\context\Priority;
8+
use org\nameapi\ontology\input\entities\person\NaturalInputPerson;
9+
use org\nameapi\ontology\input\entities\person\name\InputPersonName;
10+
11+
12+
/**
13+
*
14+
* This is just one simple call. For all functional tests see the separate project at
15+
* https://github.com/optimaize/nameapi-client-php-functionaltests
16+
*
17+
*
18+
*/
19+
class PersonNameParserServiceTest extends \PHPUnit_Framework_TestCase {
20+
21+
public function testParse() {
22+
//setup code:
23+
$context = Context::builder()
24+
->priority(Priority::REALTIME())
25+
->build();
26+
$myApiKey = 'test'; //grab one from nameapi.org
27+
$serviceFactory = new ServiceFactory($myApiKey, $context, Host::http('rc50-api.nameapi.org'), '5.0');
28+
$personNameParser = $serviceFactory->parserServices()->personNameParser();
29+
30+
//the call:
31+
$inputPerson = NaturalInputPerson::builder()
32+
->name(InputPersonName::westernBuilder()
33+
->fullname( "John Doe" )
34+
->build())
35+
->gender(new org\nameapi\ontology\input\entities\person\gender\StoragePersonGender("FEMALE"))
36+
->build();
37+
$parseResult = $personNameParser->parse($inputPerson);
38+
39+
//the assertions:
40+
$bestMatch = $parseResult->getBestMatch();
41+
$this->assertEquals('NATURAL', (string)$bestMatch->getParsedPerson()->getPersonType());
42+
$this->assertEquals('PRIMARY', (string)$bestMatch->getParsedPerson()->getPersonRole());
43+
$this->assertEquals('John', $bestMatch->getParsedPerson()->getAddressingGivenName());
44+
$this->assertEquals('Doe', $bestMatch->getParsedPerson()->getAddressingSurname());
45+
$this->assertEquals('John', $bestMatch->getParsedPerson()->getOutputPersonName()->getFirst('GIVENNAME')->getString());
46+
$this->assertEquals('Doe', $bestMatch->getParsedPerson()->getOutputPersonName()->getFirst('SURNAME')->getString());
47+
}
48+
49+
}

tests/functional/PingServiceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ public function testPing() {
2222
->priority(Priority::REALTIME())
2323
->build();
2424
$myApiKey = 'test'; //grab one from nameapi.org
25-
$serviceFactory = new ServiceFactory($myApiKey, $context, Host::http('preview-api.nameapi.org'), '5.0');
26-
$deaDetector = $serviceFactory->emailServices()->disposableEmailAddressDetector();
25+
$serviceFactory = new ServiceFactory($myApiKey, $context, Host::http('rc50-api.nameapi.org'), '5.0');
2726

2827
//the call:
2928
$pingService = $serviceFactory->systemServices()->ping();
3029
$result = $pingService->ping();
30+
31+
//the assertions:
3132
$this->assertEquals('pong', $result);
3233
}
3334

0 commit comments

Comments
 (0)