|
| 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 | +} |
0 commit comments