Skip to content

Commit 3e37884

Browse files
author
Ace Nassri
authored
Merge branch 'master' into functions-scopes
2 parents 6f06176 + 0aa1285 commit 3e37884

File tree

87 files changed

+2888
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2888
-115
lines changed

.kokoro/secrets.sh.enc

28 Bytes
Binary file not shown.

.php_cs.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ return PhpCsFixer\Config::create()
1010
'method_argument_space' => [
1111
'keep_multiple_spaces_after_comma' => true
1212
],
13+
'return_type_declaration' => [
14+
'space_before' => 'none'
15+
],
1316
])
1417
->setFinder(
1518
PhpCsFixer\Finder::create()

appengine/php72/getting-started/test/CloudSqlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CloudSqlTest extends TestCase
2525
{
2626
use TestTrait;
2727

28-
public function setUp() : void
28+
public function setUp(): void
2929
{
3030
$connection = $this->requireEnv('CLOUDSQL_CONNECTION_NAME');
3131
$dbUser = $this->requireEnv('CLOUDSQL_USER');

cloud_sql/mysql/pdo/src/Votes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function createTableIfNotExists()
6868
*
6969
* @return array
7070
*/
71-
public function listVotes() : array
71+
public function listVotes(): array
7272
{
7373
$sql = "SELECT vote_value, time_cast FROM votes ORDER BY time_cast DESC LIMIT 5";
7474
$statement = $this->connection->prepare($sql);
@@ -82,7 +82,7 @@ public function listVotes() : array
8282
* @param string $value
8383
* @param int
8484
*/
85-
public function getCountByValue(string $value) : int
85+
public function getCountByValue(string $value): int
8686
{
8787
$sql = "SELECT COUNT(vote_id) as voteCount FROM votes WHERE vote_value = ?";
8888

@@ -98,7 +98,7 @@ public function getCountByValue(string $value) : int
9898
* @param string $value The value to vote for.
9999
* @return boolean
100100
*/
101-
public function insertVote(string $value) : bool
101+
public function insertVote(string $value): bool
102102
{
103103
$conn = $this->connection;
104104
$res = false;

cloud_sql/mysql/pdo/src/app.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
/**
5555
* @param $conn_config array driver-specific options for PDO
5656
*/
57-
function init_tcp_database_connection(array $conn_config) : PDO
57+
function init_tcp_database_connection(array $conn_config): PDO
5858
{
5959
$username = getenv('DB_USER');
6060
$password = getenv('DB_PASS');
@@ -107,7 +107,7 @@ function init_tcp_database_connection(array $conn_config) : PDO
107107
/**
108108
* @param $conn_config array driver-specific options for PDO
109109
*/
110-
function init_unix_database_connection(array $conn_config) : PDO
110+
function init_unix_database_connection(array $conn_config): PDO
111111
{
112112
$username = getenv('DB_USER');
113113
$password = getenv('DB_PASS');

cloud_sql/mysql/pdo/tests/VotesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class VotesTest extends TestCase
2929
{
3030
private $conn;
3131

32-
public function setUp() : void
32+
public function setUp(): void
3333
{
3434
$this->conn = $this->prophesize(PDO::class);
3535
}

cloud_sql/postgres/pdo/src/Votes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function createTableIfNotExists()
6868
*
6969
* @return array
7070
*/
71-
public function listVotes() : array
71+
public function listVotes(): array
7272
{
7373
$sql = "SELECT vote_value, time_cast FROM votes ORDER BY time_cast DESC LIMIT 5";
7474
$statement = $this->connection->prepare($sql);
@@ -82,7 +82,7 @@ public function listVotes() : array
8282
* @param string $value
8383
* @param int
8484
*/
85-
public function getCountByValue(string $value) : int
85+
public function getCountByValue(string $value): int
8686
{
8787
$sql = "SELECT COUNT(vote_id) as voteCount FROM votes WHERE vote_value = ?";
8888

@@ -98,7 +98,7 @@ public function getCountByValue(string $value) : int
9898
* @param string $value The value to vote for.
9999
* @return boolean
100100
*/
101-
public function insertVote(string $value) : bool
101+
public function insertVote(string $value): bool
102102
{
103103
$conn = $this->connection;
104104
$res = false;

cloud_sql/postgres/pdo/src/app.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,26 @@
5454
/**
5555
* @param $conn_config array driver-specific options for PDO
5656
*/
57-
function init_tcp_database_connection(array $conn_config) : PDO
57+
function init_tcp_database_connection(array $conn_config): PDO
5858
{
5959
$username = getenv('DB_USER');
6060
$password = getenv('DB_PASS');
6161
$db_name = getenv('DB_NAME');
6262
$host = getenv('DB_HOST');
6363

6464
try {
65-
// # [START cloud_sql_postgres_pdo_create_tcp]
66-
// // $username = 'your_db_user';
67-
// // $password = 'yoursupersecretpassword';
68-
// // $db_name = 'your_db_name';
69-
// // $host = "127.0.0.1";
65+
# [START cloud_sql_postgres_pdo_create_tcp]
66+
// $username = 'your_db_user';
67+
// $password = 'yoursupersecretpassword';
68+
// $db_name = 'your_db_name';
69+
// $host = "127.0.0.1";
7070

7171
// Connect using TCP
7272
$dsn = sprintf('pgsql:dbname=%s;host=%s', $db_name, $host);
7373

7474
// Connect to the database
7575
$conn = new PDO($dsn, $username, $password, $conn_config);
76+
# [END cloud_sql_postgres_pdo_create_tcp]
7677
} catch (TypeError $e) {
7778
throw new RuntimeException(
7879
sprintf(
@@ -115,12 +116,12 @@ function init_unix_database_connection(array $conn_config)
115116
$socket_dir = getenv('DB_SOCKET_DIR') ?: '/cloudsql';
116117

117118
try {
118-
// # [START cloud_sql_postgres_pdo_create_socket]
119-
// // $username = 'your_db_user';
120-
// // $password = 'yoursupersecretpassword';
121-
// // $db_name = 'your_db_name';
122-
// // $cloud_sql_connection_name = getenv("CLOUD_SQL_CONNECTION_NAME");
123-
// // $socket_dir = getenv('DB_SOCKET_DIR') ?: '/cloudsql';
119+
# [START cloud_sql_postgres_pdo_create_socket]
120+
// $username = 'your_db_user';
121+
// $password = 'yoursupersecretpassword';
122+
// $db_name = 'your_db_name';
123+
// $cloud_sql_connection_name = getenv("CLOUD_SQL_CONNECTION_NAME");
124+
// $socket_dir = getenv('DB_SOCKET_DIR') ?: '/cloudsql';
124125

125126
// Connect using UNIX sockets
126127
$dsn = sprintf(

cloud_sql/postgres/pdo/tests/VotesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class VotesTest extends TestCase
2929
{
3030
private $conn;
3131

32-
public function setUp() : void
32+
public function setUp(): void
3333
{
3434
$this->conn = $this->prophesize(PDO::class);
3535
}

cloud_sql/sqlserver/pdo/src/Votes.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function createTableIfNotExists()
7474
*
7575
* @return array
7676
*/
77-
public function listVotes() : array
77+
public function listVotes(): array
7878
{
7979
$sql = "SELECT TOP 5 vote_value, time_cast FROM votes ORDER BY time_cast DESC";
8080
$statement = $this->connection->prepare($sql);
@@ -88,7 +88,7 @@ public function listVotes() : array
8888
* @param string $value
8989
* @param int
9090
*/
91-
public function getCountByValue(string $value) : int
91+
public function getCountByValue(string $value): int
9292
{
9393
$sql = "SELECT COUNT(vote_id) as voteCount FROM votes WHERE vote_value = ?";
9494

@@ -104,12 +104,12 @@ public function getCountByValue(string $value) : int
104104
* @param string $value The value to vote for.
105105
* @return boolean
106106
*/
107-
public function insertVote(string $value) : bool
107+
public function insertVote(string $value): bool
108108
{
109109
$conn = $this->connection;
110110
$res = false;
111111

112-
# [START cloud_sql_server_pdo_connection]
112+
# [START cloud_sql_sqlserver_pdo_connection]
113113
// Use prepared statements to guard against SQL injection.
114114
$sql = "INSERT INTO votes (time_cast, vote_value) VALUES (GETDATE(), :voteValue)";
115115

@@ -126,7 +126,7 @@ public function insertVote(string $value) : bool
126126
$e
127127
);
128128
}
129-
# [END cloud_sql_server_pdo_connection]
129+
# [END cloud_sql_sqlserver_pdo_connection]
130130

131131
return $res;
132132
}

cloud_sql/sqlserver/pdo/src/app.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@
5050
$dsn = sprintf('sqlsrv:server=%s;Database=%s', $host, $db_name);
5151

5252
// Connect to the database.
53-
# [START cloud_sql_server_pdo_timeout]
53+
# [START cloud_sql_sqlserver_pdo_timeout]
5454
// Here we set the connection timeout to five seconds and ask PDO to
5555
// throw an exception if any errors occur.
5656
$conn = new PDO($dsn, $username, $password, [
5757
PDO::ATTR_TIMEOUT => 5,
5858
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
5959
]);
60-
# [END cloud_sql_server_pdo_timeout]
61-
# [END cloud_sql_server_pdo_create_tcp]
60+
# [END cloud_sql_sqlserver_pdo_timeout]
61+
# [END cloud_sql_sqlserver_pdo_create_tcp]
6262
} catch (TypeError $e) {
6363
throw new RuntimeException(
6464
sprintf(

cloud_sql/sqlserver/pdo/tests/VotesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class VotesTest extends TestCase
2929
{
3030
private $conn;
3131

32-
public function setUp() : void
32+
public function setUp(): void
3333
{
3434
$this->conn = $this->prophesize(PDO::class);
3535
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"require": {
3+
"google/cloud-functions-framework": "^0.7"
4+
},
5+
"scripts": {
6+
"start": [
7+
"Composer\\Config::disableProcessTimeout",
8+
"FUNCTION_TARGET=listFiles php -S localhost:${PORT:-8080} vendor/bin/router.php"
9+
]
10+
}
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
/**
3+
* Copyright 2020 Google LLC.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// [START functions_concepts_filesystem]
19+
20+
use Psr\Http\Message\ServerRequestInterface;
21+
22+
function listFiles(ServerRequestInterface $request): string
23+
{
24+
$contents = scandir(__DIR__);
25+
26+
$output = "Files:" . PHP_EOL;
27+
28+
foreach ($contents as $file) {
29+
$output .= "\t" . $file . PHP_EOL;
30+
}
31+
32+
return $output;
33+
}
34+
35+
// [END functions_concepts_filesystem]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
xml version="1.0" encoding="UTF-8"?>
2+
17+
<phpunit bootstrap="../../testing/bootstrap.php" convertWarningsToExceptions="false">
18+
<testsuites>
19+
<testsuite name="Cloud Functions List Files Test Suite">
20+
<directory>testdirectory>
21+
testsuite>
22+
testsuites>
23+
<logging>
24+
<log type="coverage-clover" target="build/logs/clover.xml"/>
25+
logging>
26+
<filter>
27+
<whitelist>
28+
<directory suffix=".php">.directory>
29+
<exclude>
30+
<directory>./vendordirectory>
31+
exclude>
32+
whitelist>
33+
filter>
34+
phpunit>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
/**
3+
* Copyright 2020 Google LLC.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
namespace Google\Cloud\Samples\Functions\ConceptsFilesystem\Test;
21+
22+
use Google\Cloud\TestUtils\CloudFunctionDeploymentTrait;
23+
use PHPUnit\Framework\TestCase;
24+
25+
require_once __DIR__ . '/TestCasesTrait.php';
26+
27+
/**
28+
* Class DeployTest.
29+
*
30+
* This test is not run by the CI system.
31+
*
32+
* To skip deployment of a new function, run with "GOOGLE_SKIP_DEPLOYMENT=true".
33+
* To skip deletion of the tested function, run with "GOOGLE_KEEP_DEPLOYMENT=true".
34+
*/
35+
class DeployTest extends TestCase
36+
{
37+
use CloudFunctionDeploymentTrait;
38+
use TestCasesTrait;
39+
40+
private static $entryPoint = 'listFiles';
41+
42+
/**
43+
* @dataProvider cases
44+
*/
45+
public function testFunction($file): void
46+
{
47+
// Send a request to the function.
48+
$resp = $this->client->get('', [
49+
// Uncomment and CURLOPT_VERBOSE debug content will be sent to stdout.
50+
// 'debug' => true
51+
]);
52+
53+
// Assert status code.
54+
$this->assertEquals('200', $resp->getStatusCode());
55+
56+
// Assert function output.
57+
$output = trim((string) $resp->getBody());
58+
// Failures often lead to a large HTML page in the response body.
59+
$this->assertContains($file, $output);
60+
}
61+
}

0 commit comments

Comments
 (0)