File tree Expand file tree Collapse file tree 6 files changed +114
-14
lines changed
src/org/nameapi/ontology/input/context
functional/org/nameapi/client/services
unit/org/nameapi/ontology/input/context Expand file tree Collapse file tree 6 files changed +114
-14
lines changed Original file line number Diff line number Diff line change 22
33namespace org \nameapi \ontology \input \context ;
44
5- class Priority {
6- const __default = 'REALTIME ' ;
7- const REALTIME = 'REALTIME ' ;
8- const LOW = 'LOW ' ;
5+ /**
6+ * Class Priority
7+ *
8+ * Possible values are: REALTIME, LOW
9+ */
10+ final class Priority {
911
12+ private static $ realtime = null ;
13+ private static $ low = null ;
14+
15+ public static function REALTIME () {
16+ if (!Priority::$ realtime ) Priority::$ realtime = new Priority ('REALTIME ' );
17+ return Priority::$ realtime ;
18+ }
19+ public static function LOW () {
20+ if (!Priority::$ low ) Priority::$ low = new Priority ('LOW ' );
21+ return Priority::$ low ;
22+ }
23+
24+
25+ /**
26+ * @var string $value
27+ */
28+ private $ value = null ;
29+
30+ public function __construct ($ value ) {
31+ if ($ value !=='REALTIME ' && $ value !=='LOW ' ) {
32+ throw new \Exception ('Invalid value for Priority: ' .$ value .'! ' );
33+ }
34+ $ this ->value = $ value ;
35+ }
36+
37+
38+ public function __toString () {
39+ return $ this ->value ;
40+ }
1041
1142}
43+
Original file line number Diff line number Diff line change 22
33namespace org \nameapi \ontology \input \context ;
44
5- class TextCase {
6- const __default = 'TITLE_CASE ' ;
7- const TITLE_CASE = 'TITLE_CASE ' ;
8- const UPPER_CASE = 'UPPER_CASE ' ;
9- const LOWER_CASE = 'LOWER_CASE ' ;
5+ /**
6+ * Class Priority
7+ *
8+ * Possible values are: TITLE_CASE, UPPER_CASE, LOWER_CASE
9+ */
10+ final class TextCase {
1011
12+ private static $ titleCase = null ;
13+ private static $ upperCase = null ;
14+ private static $ lowerCase = null ;
15+
16+ public static function TITLE_CASE () {
17+ if (!TextCase::$ titleCase ) TextCase::$ titleCase = new TextCase ('TITLE_CASE ' );
18+ return TextCase::$ titleCase ;
19+ }
20+ public static function UPPER_CASE () {
21+ if (!TextCase::$ upperCase ) TextCase::$ upperCase = new TextCase ('UPPER_CASE ' );
22+ return TextCase::$ upperCase ;
23+ }
24+ public static function LOWER_CASE () {
25+ if (!TextCase::$ lowerCase ) TextCase::$ lowerCase = new TextCase ('LOWER_CASE ' );
26+ return TextCase::$ lowerCase ;
27+ }
28+
29+ /**
30+ * @var string $value
31+ */
32+ private $ value = null ;
33+
34+ public function __construct ($ value ) {
35+ if ($ value !=='TITLE_CASE ' && $ value !=='UPPER_CASE ' && $ value !=='LOWER_CASE ' ) {
36+ throw new \Exception ('Invalid value for TextCase: ' .$ value .'! ' );
37+ }
38+ $ this ->value = $ value ;
39+ }
40+
41+
42+ public function __toString () {
43+ return $ this ->value ;
44+ }
1145
1246}
47+
48+
Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ protected function makeContext() {
2525 }
2626 return Context::builder ()
2727 ->apiKey ($ this ->apiKey )
28- ->priority (Priority::REALTIME )
29- ->textCase (TextCase::TITLE_CASE )
28+ ->priority (Priority::REALTIME () )
29+ ->textCase (TextCase::TITLE_CASE () )
3030 ->build ();
3131 }
3232
@@ -37,4 +37,4 @@ protected function makeServiceFactory() {
3737 return new ServiceFactory ($ this ->makeContext ());
3838 }
3939
40- }
40+ }
Original file line number Diff line number Diff line change 77class ContextBuilderTest extends \PHPUnit_Framework_TestCase {
88
99 public function testOne () {
10- $ context = Context::builder ()->apiKey ('my-api-key ' )->geo ('DE ' )->priority (Priority::REALTIME )->build ();
10+ $ context = Context::builder ()->apiKey ('my-api-key ' )->geo ('DE ' )->priority (Priority::REALTIME () )->build ();
1111 $ this ->assertEquals ('my-api-key ' , $ context ->getApiKey ());
1212 $ this ->assertEquals ('DE ' , $ context ->getGeo ());
13- $ this ->assertEquals (Priority::REALTIME , $ context ->getPriority ());
13+ $ this ->assertEquals (Priority::REALTIME () , $ context ->getPriority ());
1414 $ this ->assertEquals (array (), $ context ->getProperties ());
1515 }
1616
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace org \nameapi \ontology \input \context ;
4+
5+ require_once (__DIR__ .'/../../../../../../../src/org/nameapi/ontology/input/context/Priority.php ' );
6+
7+ class PriorityTest extends \PHPUnit_Framework_TestCase {
8+
9+ public function testEquality () {
10+ $ this ->assertEquals (Priority::REALTIME (), Priority::REALTIME ());
11+ $ this ->assertTrue (Priority::REALTIME () === Priority::REALTIME ());
12+ $ this ->assertEquals ('REALTIME ' , (string )Priority::REALTIME ());
13+ }
14+
15+ }
16+
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace org \nameapi \ontology \input \context ;
4+
5+ require_once (__DIR__ .'/../../../../../../../src/org/nameapi/ontology/input/context/TextCase.php ' );
6+
7+ class TextCaseTest extends \PHPUnit_Framework_TestCase {
8+
9+ public function testEquality () {
10+ $ this ->assertEquals (TextCase::TITLE_CASE (), TextCase::TITLE_CASE ());
11+ $ this ->assertTrue (TextCase::TITLE_CASE () === TextCase::TITLE_CASE ());
12+ $ this ->assertEquals ('TITLE_CASE ' , (string )TextCase::TITLE_CASE ());
13+ }
14+
15+ }
16+
You can’t perform that action at this time.
0 commit comments