Skip to content

Commit 4edb2e4

Browse files
authored
Moves Flex Hello World to this repo (GoogleCloudPlatform#938)
1 parent e8d4f4f commit 4edb2e4

File tree

10 files changed

+203
-0
lines changed

10 files changed

+203
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test/*
2+
coverage/*
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/vendor
2+
**/settings.yml
3+
build/*
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# App Engine Flexible Hello World for PHP
2+
3+
This folder contains the sample code for running a Hello World application
4+
on [App Engine Flexible][flex-helloworld]
5+
6+
[flex-helloworld]: https://cloud.google.com/appengine/docs/flexible/php/quickstart
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
runtime: php
2+
env: flex
3+
4+
runtime_config:
5+
document_root: web
6+
7+
# This sample incurs costs to run on the App Engine flexible environment.
8+
# The settings below are to reduce costs during testing and are not appropriate
9+
# for production use. For more information, see:
10+
# https://cloud.google.com/appengine/docs/flexible/php/configuring-your-app-with-app-yaml
11+
manual_scaling:
12+
instances: 1
13+
resources:
14+
cpu: 1
15+
memory_gb: 0.5
16+
disk_size_gb: 10
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"require": {
3+
"php": "5.6.*|7.0.*|7.1.*|7.2.*",
4+
"silex/silex": "^1.3"
5+
},
6+
"require-dev": {
7+
"symfony/browser-kit": "^3.0",
8+
"symfony/http-kernel": "^3.0"
9+
}
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
location / {
2+
# try to serve file directly, fallback to front controller
3+
try_files $uri /index.php$is_args$args;
4+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2019 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+
<phpunit bootstrap="../../../testing/bootstrap.php" convertWarningsToExceptions="false">
18+
<testsuites>
19+
<testsuite name="PHP Getting Started Test Suite">
20+
<directory>test</directory>
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">./web</directory>
29+
</whitelist>
30+
</filter>
31+
</phpunit>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2019 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace Google\Cloud\Samples\Bookshelf;
20+
21+
use Silex\WebTestCase;
22+
23+
/**
24+
* Test for application controllers
25+
*/
26+
class ControllersTest extends WebTestCase
27+
{
28+
public function createApplication()
29+
{
30+
$app = require __DIR__ . '/../web/index.php';
31+
$app['debug'] = true;
32+
unset($app['exception_handler']);
33+
34+
return $app;
35+
}
36+
37+
public function testTopPage()
38+
{
39+
$client = $this->createClient();
40+
$crawlerexport = $client->request('GET', '/');
41+
$resp = $client->getResponse();
42+
$this->assertTrue($resp->isOk());
43+
$this->assertContains('Hello World', $resp->getContent());
44+
}
45+
46+
public function testGoodbye()
47+
{
48+
$client = $this->createClient();
49+
$crawlerexport = $client->request('GET', '/goodbye');
50+
$resp = $client->getResponse();
51+
$this->assertTrue($resp->isOk());
52+
$this->assertContains('Goodbye World', $resp->getContent());
53+
}
54+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/*
3+
* Copyright 2019 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+
namespace Google\Cloud\Samples\Bookshelf;
19+
20+
use Google\Cloud\TestUtils\AppEngineDeploymentTrait;
21+
use PHPUnit\Framework\TestCase;
22+
23+
/**
24+
* Class BookshelfTest
25+
*/
26+
class BookshelfTest extends TestCase
27+
{
28+
use AppEngineDeploymentTrait;
29+
30+
public function testIndex()
31+
{
32+
$resp = $this->client->get('/');
33+
$this->assertEquals('200', $resp->getStatusCode(),
34+
'index status code');
35+
$this->assertContains('Hello World', (string) $resp->getBody(),
36+
'index content');
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2019 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// [START appengine_flex_helloworld_index_php]
20+
require_once __DIR__ . '/../vendor/autoload.php';
21+
22+
$app = new Silex\Application();
23+
24+
$app->get('/', function () {
25+
return 'Hello World';
26+
});
27+
28+
$app->get('/goodbye', function () {
29+
return 'Goodbye World';
30+
});
31+
32+
// @codeCoverageIgnoreStart
33+
if (PHP_SAPI != 'cli') {
34+
$app->run();
35+
}
36+
// @codeCoverageIgnoreEnd
37+
38+
return $app;
39+
// [END appengine_flex_helloworld_index_php]

0 commit comments

Comments
 (0)