Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions appengine/flexible/helloworld/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test/*
coverage/*
3 changes: 3 additions & 0 deletions appengine/flexible/helloworld/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/vendor
**/settings.yml
build/*
6 changes: 6 additions & 0 deletions appengine/flexible/helloworld/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# App Engine Flexible Hello World for PHP

This folder contains the sample code for running a Hello World application
on [App Engine Flexible][flex-helloworld]

[flex-helloworld]: https://cloud.google.com/appengine/docs/flexible/php/quickstart
16 changes: 16 additions & 0 deletions appengine/flexible/helloworld/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
runtime: php
env: flex

runtime_config:
document_root: web

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/php/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
10 changes: 10 additions & 0 deletions appengine/flexible/helloworld/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"require": {
"php": "5.6.*|7.0.*|7.1.*|7.2.*",
"silex/silex": "^1.3"
},
"require-dev": {
"symfony/browser-kit": "^3.0",
"symfony/http-kernel": "^3.0"
}
}
4 changes: 4 additions & 0 deletions appengine/flexible/helloworld/nginx-app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
location / {
# try to serve file directly, fallback to front controller
try_files $uri /index.php$is_args$args;
}
31 changes: 31 additions & 0 deletions appengine/flexible/helloworld/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2019 Google LLC.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<phpunit bootstrap="../../../testing/bootstrap.php" convertWarningsToExceptions="false">
<testsuites>
<testsuite name="PHP Getting Started Test Suite">
<directory>test</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<filter>
<whitelist>
<directory suffix=".php">./web</directory>
</whitelist>
</filter>
</phpunit>
54 changes: 54 additions & 0 deletions appengine/flexible/helloworld/test/ControllersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* Copyright 2019 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Samples\Bookshelf;

use Silex\WebTestCase;

/**
* Test for application controllers
*/
class ControllersTest extends WebTestCase
{
public function createApplication()
{
$app = require __DIR__ . '/../web/index.php';
$app['debug'] = true;
unset($app['exception_handler']);

return $app;
}

public function testTopPage()
{
$client = $this->createClient();
$crawlerexport = $client->request('GET', '/');
$resp = $client->getResponse();
$this->assertTrue($resp->isOk());
$this->assertContains('Hello World', $resp->getContent());
}

public function testGoodbye()
{
$client = $this->createClient();
$crawlerexport = $client->request('GET', '/goodbye');
$resp = $client->getResponse();
$this->assertTrue($resp->isOk());
$this->assertContains('Goodbye World', $resp->getContent());
}
}
38 changes: 38 additions & 0 deletions appengine/flexible/helloworld/test/DeployTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/*
* Copyright 2019 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Samples\Bookshelf;

use Google\Cloud\TestUtils\AppEngineDeploymentTrait;
use PHPUnit\Framework\TestCase;

/**
* Class BookshelfTest
*/
class BookshelfTest extends TestCase
{
use AppEngineDeploymentTrait;

public function testIndex()
{
$resp = $this->client->get('/');
$this->assertEquals('200', $resp->getStatusCode(),
'index status code');
$this->assertContains('Hello World', (string) $resp->getBody(),
'index content');
}
}
39 changes: 39 additions & 0 deletions appengine/flexible/helloworld/web/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* Copyright 2019 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// [START appengine_flex_helloworld_index_php]
require_once __DIR__ . '/../vendor/autoload.php';

$app = new Silex\Application();

$app->get('/', function () {
return 'Hello World';
});

$app->get('/goodbye', function () {
return 'Goodbye World';
});

// @codeCoverageIgnoreStart
if (PHP_SAPI != 'cli') {
$app->run();
}
// @codeCoverageIgnoreEnd

return $app;
// [END appengine_flex_helloworld_index_php]