Skip to content

Commit f09dd79

Browse files
authored
Merge pull request #62 from silinternational/develop
Add non-functioning twoStepVerification turnOff method placeholder
2 parents 1ec0854 + 3a46bcb commit f09dd79

File tree

4 files changed

+175
-382
lines changed

4 files changed

+175
-382
lines changed

SilMock/Google/Service/Directory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use SilMock\Google\Service\Directory\UsersResource;
88
use SilMock\Google\Service\Directory\UsersAliasesResource;
99
use SilMock\Google\Service\Directory\VerificationCodesResource;
10+
use SilMock\Google\Service\Directory\Resource\TwoStepVerification;
1011

1112
class Directory
1213
{
@@ -15,6 +16,7 @@ class Directory
1516
public $users;
1617
public $users_aliases;
1718
public $verificationCodes;
19+
public $twoStepVerification;
1820

1921
/**
2022
* Sets the users and users_aliases properties to be instances of
@@ -30,5 +32,6 @@ public function __construct($client, $dbFile = null)
3032
$this->users = new UsersResource($dbFile);
3133
$this->users_aliases = new UsersAliasesResource($dbFile);
3234
$this->verificationCodes = new VerificationCodesResource($dbFile);
35+
$this->twoStepVerification = new TwoStepVerification($dbFile);
3336
}
3437
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace SilMock\Google\Service\Directory\Resource;
4+
5+
use SilMock\Google\Service\DbClass;
6+
7+
class TwoStepVerification extends dbClass
8+
{
9+
public function __construct(string $dbFile = '')
10+
{
11+
parent::__construct($dbFile, 'directory', 'twoStepVerification');
12+
}
13+
14+
/**
15+
* Turn off 2SV for a given email account.
16+
*
17+
* NOTE: This doesn't need to work. It just needs to exist.
18+
*
19+
* @param $userKey
20+
* @param array $optParams
21+
* @return void
22+
*/
23+
public function turnOff($userKey, $optParams = [])
24+
{
25+
// Grab the corresponding twoStepVerification record.
26+
$sqliteUtils = $this->getSqliteUtils();
27+
$twoStepVerificationRecord = $sqliteUtils->getAllRecordsByDataKey(
28+
$this->dataType,
29+
$this->dataClass,
30+
'twoStepVerification',
31+
$userKey
32+
);
33+
// Update it
34+
$twoStepVerificationRecord['onOrOff'] = 'off';
35+
// Get the record id and update it, as needed.
36+
$recordId = $twoStepVerificationRecord['id'];
37+
// If there was a recordId, then it probably would be functional
38+
// However, we just need this method to exist, not actually work
39+
if (! empty($recordId)) {
40+
$sqliteUtils->updateRecordById($recordId, json_encode($twoStepVerificationRecord));
41+
}
42+
}
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Service\Directory\Resource;
4+
5+
use Exception;
6+
use PHPUnit\Framework\TestCase;
7+
use SilMock\Google\Service\Directory\Resource\TwoStepVerification;
8+
9+
class TwoStepVerificationTest extends TestCase
10+
{
11+
public $dataFile = DATAFILE2;
12+
13+
public function testTwoStepVerificationTurnOff()
14+
{
15+
$twoStepVerfication = new TwoStepVerification($this->dataFile);
16+
$this->assertIsObject($twoStepVerfication, 'Unable to instantiate twoStepVerification Mock object');
17+
18+
try {
19+
$twoStepVerfication->turnOff('[email protected]');
20+
} catch (Exception $exception) {
21+
$this->assertFalse(
22+
true,
23+
sprintf(
24+
'Was expecting the turnOff method to function, but got: %s',
25+
$exception->getMessage()
26+
)
27+
);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)