Skip to content

Commit eed61d5

Browse files
committed
Checking some methods (as like getFirstRecord) to work for all methods.
1 parent 3d6a8de commit eed61d5

8 files changed

Lines changed: 125 additions & 47 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# FMDataAPI Ver.28 [![Build Status](https://github.com/msyk/FMDataAPI/actions/workflows/php.yml/badge.svg)](https://github.com/msyk/FMDataAPI/actions/workflows/php.yml)
1+
# FMDataAPI Ver.29 [![Build Status](https://github.com/msyk/FMDataAPI/actions/workflows/php.yml/badge.svg)](https://github.com/msyk/FMDataAPI/actions/workflows/php.yml)
22

33
by Masayuki Nii (nii@msyk.net)
44

@@ -65,7 +65,7 @@ FMDataAPI has "composer.json," so you can add your composer.json file in your pr
6565
...
6666
"require": {
6767
...
68-
"inter-mediator/fmdataapi":"28"
68+
"inter-mediator/fmdataapi":"29"
6969
} ...
7070
```
7171

@@ -170,8 +170,9 @@ MIT License
170170
- 2022-08-04: [Ver.28]
171171
Added the getContainerData(URL) method to the FMDataAPI class for accessing container data from the url containing /Streaming/MainDB.
172172
[BUG FIX] The FileMakerRelation class's toArray method didn't return array (Thanks to Talwinder Singh).
173-
- 2022-xx-xx: [Ver.29]
173+
- 2022-12-28: [Ver.29]
174174
Fixed the 'HTTP/2 stream 0 was not closed cleanly' problem with the new FileMaker (Thanks to @thijsmeijer)
175+
Also fixed the getPortalNames issue for single record relation (Thanks to @PGMMattias).
175176

176177
## API Differences between ver.8 and 7.
177178
### FMDataAPI class

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "inter-mediator/fmdataapi",
3-
"version": "28",
4-
"time": "2022-08-04",
3+
"version": "29",
4+
"time": "2022-12-28",
55
"repositories": [
66
{
77
"type": "git",

src/FMDataAPI.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* @link https://github.com/msyk/FMDataAPI GitHub Repository
1414
* @property-read FileMakerLayout $<<layout_name>> Returns the FileMakerLayout object from the layout named with the property.
1515
* If the layout doesn't exist, no error arises here. Any errors might arise on methods of FileMakerLayout class.
16-
* @version 28
16+
* @version 29
1717
* @author Masayuki Nii <nii@msyk.net>
18-
* @copyright 2017-2022 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
18+
* @copyright 2017-2023 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
1919
* @source 1 100000 The source code.
2020
*/
2121
class FMDataAPI
@@ -37,8 +37,8 @@ class FMDataAPI
3737
private $provider = null;
3838

3939
/**
40-
* FMDataAPI constructor. If you want to activate OAuth authentication, $user and $pasword are set as
41-
* oAuthRequestId and oAuthIdentifier. Moreover call useOAuth method before accessing layouts.
40+
* FMDataAPI constructor. If you want to activate OAuth authentication, $user and $password are set as
41+
* oAuthRequestId and oAuthIdentifier. Moreover, call useOAuth method before accessing layouts.
4242
* @param String $solution The database file name which is just hosting.
4343
* Every database must have the access privillege 'fmrest' including external data sources.
4444
* @param String $user The fmrest privilege accessible user to the database.

src/Supporting/CommunicationProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*
88
* @package INTER-Mediator\FileMakerServer\RESTAPI
99
* @link https://github.com/msyk/FMDataAPI GitHub Repository
10-
* @version 28
10+
* @version 29
1111
* @author Masayuki Nii <nii@msyk.net>
12-
* @copyright 2017-2022 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
12+
* @copyright 2017-2023 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
1313
*/
1414
class CommunicationProvider
1515
{

src/Supporting/FileMakerLayout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*
1111
* @package INTER-Mediator\FileMakerServer\RESTAPI
1212
* @link https://github.com/msyk/FMDataAPI GitHub Repository
13-
* @version 28
13+
* @version 29
1414
* @author Masayuki Nii <nii@msyk.net>
15-
* @copyright 2017-2022 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
15+
* @copyright 2017-2023 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
1616
*/
1717
class FileMakerLayout
1818
{

src/Supporting/FileMakerRelation.php

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* @property string $<<field_name>> The field value named as the property name.
1515
* @property FileMakerRelation $<<portal_name>> FileMakerRelation object associated with the property name.
1616
* The table occurrence name of the portal can be the 'portal_name,' and also the object name of the portal.
17-
* @version 28
17+
* @version 29
1818
* @author Masayuki Nii <nii@msyk.net>
19-
* @copyright 2017-2022 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
19+
* @copyright 2017-2023 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
2020
*/
2121
class FileMakerRelation implements Iterator
2222
{
@@ -46,7 +46,7 @@ class FileMakerRelation implements Iterator
4646
*/
4747
private $pointer = 0;
4848
/**
49-
* @var null
49+
* @var string|null
5050
* @ignore
5151
*/
5252
private $portalName = null;
@@ -190,7 +190,17 @@ public function moveTo($position): void
190190
*/
191191
public function count(): int
192192
{
193-
return count($this->data);
193+
switch ($this->result) {
194+
case "OK":
195+
case "PORTAL":
196+
return count($this->data);
197+
break;
198+
case "RECORD":
199+
case "PORTALRECORD":
200+
return 1;
201+
break;
202+
}
203+
return 0;
194204
}
195205

196206
/**
@@ -342,6 +352,7 @@ public function getPortalNames()
342352
foreach ($key->portalData as $name => $val) {
343353
array_push($list, $name);
344354
}
355+
break 2;
345356
}
346357
}
347358
break;
@@ -384,10 +395,10 @@ public function field($name, $toName = null)
384395
} else if (isset($this->data[$this->pointer]->portalData) &&
385396
isset($this->data[$this->pointer]->portalData->$name)
386397
) {
387-
$value = new FileMakerRelation(
388-
$this->data[$this->pointer]->portalData->$name,
389-
property_exists($this->data[$this->pointer], 'portalDataInfo') ? $this->data[$this->pointer]->portalDataInfo : null,
390-
"PORTAL", 0, null, $this->restAPI);
398+
$infoData = property_exists($this->data[$this->pointer], 'portalDataInfo') ?
399+
$this->data[$this->pointer]->portalDataInfo : null;
400+
$value = new FileMakerRelation($this->data[$this->pointer]->portalData->$name,
401+
$infoData, "PORTAL", 0, $name, $this->restAPI);
391402
}
392403
}
393404
break;
@@ -402,9 +413,8 @@ public function field($name, $toName = null)
402413
if (isset($this->data->fieldData) && isset($this->data->fieldData->$name)) {
403414
$value = $this->data->fieldData->$name;
404415
} else if (isset($this->data->portalData) && isset($this->data->portalData->$name)) {
405-
$value = new FileMakerRelation(
406-
$this->data->portalData->$name,
407-
property_exists($this->data, 'portalDataInfo') ? $this->data->portalDataInfo : null,
416+
$infoData = property_exists($this->data, 'portalDataInfo') ? $this->data->portalDataInfo : null;
417+
$value = new FileMakerRelation($this->data->portalData->$name, $infoData,
408418
"PORTAL", 0, $name, $this->restAPI);
409419
} else if (isset($this->data->fieldData->$fieldName)) {
410420
$value = $this->data->fieldData->$fieldName;
@@ -534,21 +544,29 @@ public function getContainerData($name, $toName = null)
534544
public function current(): ?FileMakerRelation
535545
{
536546
$value = null;
537-
if (isset($this->data) &&
538-
isset($this->data[$this->pointer])
539-
) {
540-
$tmpInfo = $this->getDataInfo();
541-
$dataInfo = null;
542-
if ($tmpInfo !== null && is_object($tmpInfo)) {
543-
$dataInfo = clone $tmpInfo;
544-
$dataInfo->returnedCount = 1;
545-
}
546-
$value = new FileMakerRelation(
547-
$this->data[$this->pointer], $dataInfo,
548-
($this->result == "PORTAL") ? "PORTALRECORD" : "RECORD",
549-
$this->errorCode, $this->portalName, $this->restAPI);
547+
switch ($this->result) {
548+
case "OK":
549+
case "PORTAL":
550+
if (isset($this->data) &&
551+
isset($this->data[$this->pointer])
552+
) {
553+
$tmpInfo = $this->getDataInfo();
554+
$dataInfo = null;
555+
if ($tmpInfo !== null && is_object($tmpInfo)) {
556+
$dataInfo = clone $tmpInfo;
557+
$dataInfo->returnedCount = 1;
558+
}
559+
$result = ($this->result == "PORTAL") ? "PORTALRECORD" : "RECORD";
560+
$portalName = $this->portalName;
561+
$value = new FileMakerRelation($this->data[$this->pointer], $dataInfo, $result,
562+
$this->errorCode, $portalName, $this->restAPI);
563+
}
564+
break;
565+
case "RECORD":
566+
case "PORTALRECORD":
567+
$value = $this;
568+
break;
550569
}
551-
552570
return $value;
553571
}
554572

@@ -569,12 +587,19 @@ public function key(): int
569587
*/
570588
public function valid(): bool
571589
{
572-
if (isset($this->data) &&
573-
isset($this->data[$this->pointer])
574-
) {
575-
return true;
590+
switch ($this->result) {
591+
case "OK":
592+
case "PORTAL":
593+
if (isset($this->data) && isset($this->data[$this->pointer])
594+
) {
595+
return true;
596+
}
597+
break;
598+
case "RECORD":
599+
case "PORTALRECORD":
600+
return $this->pointer == 0;
601+
break;
576602
}
577-
578603
return false;
579604
}
580605

test/.phpunit.result.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":1,"defects":[],"times":{"INTERMediator\\FileMakerServer\\RESTAPI\\FMDataAPIUnitTest::test_initializeObjects":0.005,"INTERMediator\\FileMakerServer\\RESTAPI\\FMDataAPIUnitTest::test_Query":0.019,"INTERMediator\\FileMakerServer\\RESTAPI\\FMDataAPIUnitTest::test_ErrorQuery":0.001}}
1+
{"version":1,"defects":{"INTERMediator\\FileMakerServer\\RESTAPI\\FMDataAPIUnitTest::test_SingleRecord":3,"INTERMediator\\FileMakerServer\\RESTAPI\\FMDataAPIUnitTest::test_Query":4},"times":{"INTERMediator\\FileMakerServer\\RESTAPI\\FMDataAPIUnitTest::test_initializeObjects":0.004,"INTERMediator\\FileMakerServer\\RESTAPI\\FMDataAPIUnitTest::test_Query":0.001,"INTERMediator\\FileMakerServer\\RESTAPI\\FMDataAPIUnitTest::test_ErrorQuery":0,"INTERMediator\\FileMakerServer\\RESTAPI\\FMDataAPIUnitTest::test_SingleRecord":0}}

test/FMDataAPIUnitTest.php

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function test_Query()
3636
$this->assertEquals($result->getTotalCount(), 3, 'Checking the total record number.');
3737
$this->assertEquals($result->getFoundCount(), 3, 'Checking the found record number.');
3838
$this->assertEquals($result->getReturnedCount(), 3, 'Checking the returned record number.');
39+
$this->assertEquals($result->getPortalNames(), ['Contact', 'History'], 'The query result returns portal names.');
3940

4041
$counter = 0;
4142
foreach ($result as $record) {
@@ -44,6 +45,9 @@ public function test_Query()
4445
$this->assertEquals($record->id, 1, 'Field value has to match with defined value.');
4546
$this->assertEquals($record->name, 'Masayuki Nii', 'Field value has to match with defined value.');
4647
$this->assertEquals($record->mail, 'msyk@msyk.net', 'Field value has to match with defined value.');
48+
49+
$this->assertEquals($record->getModId(), 6, 'It has ModID.');
50+
$this->assertEquals($record->getRecordId(), 1, 'It has RecordID.');
4751
$pcounter = 0;
4852
$this->assertEquals($contacts->count(), 3, 'Checking the record number.');
4953
$this->assertEquals($contacts->getTargetTable(), 'contact_to', 'Checking the table occurrence name.');
@@ -52,12 +56,13 @@ public function test_Query()
5256
$this->assertEquals($contacts->getReturnedCount(), 3, 'Checking the returned record number.');
5357

5458
foreach ($contacts as $item) {
59+
$item->setPortalName("contact_to");
5560
if ($pcounter === 0) {
56-
$this->assertEquals($item->field("datetime", "contact_to"), '12/01/2009 15:23:00', 'Portal field value has to match with defined value.');
61+
$this->assertEquals($item->field("datetime"), '12/01/2009 15:23:00', 'Portal field value has to match with defined value.');
5762
} else if ($pcounter === 1) {
58-
$this->assertEquals($item->field("datetime", "contact_to"), '12/02/2009 15:23:00', 'Portal field value has to match with defined value.');
63+
$this->assertEquals($item->field("datetime"), '12/02/2009 15:23:00', 'Portal field value has to match with defined value.');
5964
} else if ($pcounter === 2) {
60-
$this->assertEquals($item->field("datetime", "contact_to"), '12/03/2009 15:23:00', 'Portal field value has to match with defined value.');
65+
$this->assertEquals($item->field("datetime"), '12/03/2009 15:23:00', 'Portal field value has to match with defined value.');
6166
}
6267
$pcounter += 1;
6368
}
@@ -110,6 +115,53 @@ public function test_ErrorQuery()
110115
$this->assertEquals($fm->curlErrorCode(), 6, 'The error code has to be 6.');
111116
}
112117

118+
public function test_SingleRecord()
119+
{
120+
$result = $this->fmdataapi->person_layout->query();
121+
$record = $result->getFirstRecord();
122+
$this->assertEquals($record->id, 1, 'Field value has to match with defined value.');
123+
$this->assertEquals($record->name, 'Masayuki Nii', 'Field value has to match with defined value.');
124+
$this->assertEquals($record->mail, 'msyk@msyk.net', 'Field value has to match with defined value.');
125+
$pcounter = 0;
126+
$contacts = $record->Contact;
127+
$this->assertEquals($contacts->count(), 3, 'Checking the record number.');
128+
$this->assertEquals($contacts->getTargetTable(), 'contact_to', 'Checking the table occurrence name.');
129+
$this->assertNull($contacts->getTotalCount(), 'Checking NULL as the total record number.');
130+
$this->assertEquals($contacts->getFoundCount(), 3, 'Checking the found record number.');
131+
$this->assertEquals($contacts->getReturnedCount(), 3, 'Checking the returned record number.');
132+
133+
foreach ($contacts as $item) {
134+
if ($pcounter === 0) {
135+
$this->assertEquals($item->field("datetime", "contact_to"), '12/01/2009 15:23:00', 'Portal field value has to match with defined value.');
136+
} else if ($pcounter === 1) {
137+
$this->assertEquals($item->field("datetime", "contact_to"), '12/02/2009 15:23:00', 'Portal field value has to match with defined value.');
138+
} else if ($pcounter === 2) {
139+
$this->assertEquals($item->field("datetime", "contact_to"), '12/03/2009 15:23:00', 'Portal field value has to match with defined value.');
140+
}
141+
$pcounter += 1;
142+
}
143+
$this->assertEquals($pcounter, 3, 'Cheking the record number in portal.');
144+
145+
$this->assertEquals($record->count(), 1, 'The single record is just one record.');
146+
$currentRecord = $record->current();
147+
$this->assertEquals($currentRecord->id, 1, 'The single record can call current and return a Relation.');
148+
$this->assertEquals($record->getPortalNames(), ['Contact', 'History'], 'The single record returns portal names.');
149+
$this->assertEquals($record->getModId(), 6, 'The single record returns ModID.');
150+
$this->assertEquals($record->getRecordId(), 1, 'The single record returns RecordID.');
151+
$this->assertEquals($record->getTargetTable(), 'person_to', 'The single record returns the target table.');
152+
153+
$pcount = 0;
154+
foreach ($record as $item) {
155+
$this->assertEquals($item->id, 1, 'The single record can iterate.');
156+
$pcount++;
157+
}
158+
$this->assertEquals($pcount, 1, 'The single record has to repeat just once.');
159+
$this->assertEquals($record->getTotalCount(), 3,'Checking the total record number for queried data.');
160+
$this->assertEquals($record->getFoundCount(), 3, 'Checking the found record number for queried data.');
161+
$this->assertEquals($record->getReturnedCount(), 1, 'Checking the returned record number.');
162+
163+
}
164+
113165
// public function test_OldVersionFMS()
114166
// {
115167
// $fm = new FMDataAPI("TestDB", "web", "password", "10.0.1.21", "443", "https", false, true);

0 commit comments

Comments
 (0)