From c118ecf1f849d37cd2b53955ade7ba57c248c652 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 18 Apr 2018 11:18:11 -0700 Subject: [PATCH 1/8] Defer checking stackdriver integration required versions until composer has resolved dependencies --- .../src/Builder/GenFilesCommand.php | 11 +- .../src/ValidateGoogleCloud.php | 143 ------------------ .../enable_stackdriver_integration.sh | 15 +- .../enable_stackdriver_prepend.php | 38 +++++ .../locate_stackdriver_prepend.php | 36 ----- .../stackdriver_integration.php | 89 +++++++++++ 6 files changed, 132 insertions(+), 200 deletions(-) delete mode 100644 builder/gen-dockerfile/src/ValidateGoogleCloud.php mode change 100644 => 100755 php-base/stackdriver-files/enable_stackdriver_integration.sh create mode 100644 php-base/stackdriver-files/enable_stackdriver_prepend.php delete mode 100644 php-base/stackdriver-files/locate_stackdriver_prepend.php create mode 100644 php-base/stackdriver-files/stackdriver_integration.php diff --git a/builder/gen-dockerfile/src/Builder/GenFilesCommand.php b/builder/gen-dockerfile/src/Builder/GenFilesCommand.php index ad528cad..f63e7ca8 100644 --- a/builder/gen-dockerfile/src/Builder/GenFilesCommand.php +++ b/builder/gen-dockerfile/src/Builder/GenFilesCommand.php @@ -23,7 +23,6 @@ use Google\Cloud\Runtimes\Builder\Exception\MissingDocumentRootException; use Google\Cloud\Runtimes\Builder\Exception\RemovedEnvVarException; use Google\Cloud\Runtimes\DetectPhpVersion; -use Google\Cloud\Runtimes\ValidateGoogleCloud; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -281,14 +280,8 @@ public function createDockerfile($baseImage) } if (self::isStackdriverIntegrationEnabled($envs)) { $envs['IS_BATCH_DAEMON_RUNNING'] = 'true'; - $result = ValidateGoogleCloud::doCheck($this->workspace); - if ($result == ValidateGoogleCloud::FOUND_GOOGLE_CLOUD) { - $enableStackdriverCmd = 'RUN /bin/bash /stackdriver-files/' - . 'enable_stackdriver_integration.sh'; - } else { - $enableStackdriverCmd = 'RUN /bin/bash /stackdriver-files/' - . 'enable_stackdriver_integration.sh --individual'; - } + $enableStackdriverCmd = 'RUN /bin/bash /stackdriver-files/' + . 'enable_stackdriver_integration.sh'; } else { $enableStackdriverCmd = ''; } diff --git a/builder/gen-dockerfile/src/ValidateGoogleCloud.php b/builder/gen-dockerfile/src/ValidateGoogleCloud.php deleted file mode 100644 index 7d4dfcfd..00000000 --- a/builder/gen-dockerfile/src/ValidateGoogleCloud.php +++ /dev/null @@ -1,143 +0,0 @@ - self::MINIMUM_GOOGLE_CLOUD_VERSION, - 'google/cloud-logging' => self::MINIMUM_GOOGLE_LOGGING_VERSION, - 'google/cloud-error-reporting' => self::MINIMUM_GOOGLE_ER_VERSION - ]; - // Make sure there is `require` field in `composer.json`. - if (!(is_array($composer) && array_key_exists('require', $composer))) { - throw new GoogleCloudVersionException( - 'Required packages not found in composer.json. ' - . 'Consider running `composer require google/cloud`' - ); - } - // For google/cloud. - if (array_key_exists('google/cloud', $composer['require'])) { - $constraintsMap['google/cloud'] = - $composer['require']['google/cloud']; - } elseif (array_key_exists('google/cloud-logging', - $composer['require']) && - array_key_exists('google/cloud-error-reporting', - $composer['require'])) { - // For cloud-logging and cloud-error-reporting. - $constraintsMap['google/cloud-logging'] = - $composer['require']['google/cloud-logging']; - $constraintsMap['google/cloud-error-reporting'] = - $composer['require']['google/cloud-error-reporting']; - } else { - throw new GoogleCloudVersionException( - 'Required packages not found in composer.json. ' - . 'Consider running `composer require google/cloud`' - ); - } - - // Now we have $constraintsMap. All should have at least the minimum - // version. - - foreach ($constraintsMap as $package => $constraints) { - $versions = self::getCurrentPackageVersions($package); - - // Check all the available versions against the constraints - // and returns matched ones - $filtered = Semver::satisfiedBy($versions, $constraints); - if (count($filtered) === 0) { - throw new GoogleCloudVersionException( - "no available matching version of $package" - ); - } - $found = false; - foreach ($filtered as $version) { - if (Comparator::greaterThanOrEqualTo($version, $minimumVersionMap[$package])) { - $found = true; - break; - } - } - if ($found === false) { - throw new GoogleCloudVersionException( - "stackdriver integration needs $package " - . $minimumVersionMap[$package] . ' or higher' - ); - } - } - - if (array_key_exists('google/cloud', $constraintsMap)) { - return self::FOUND_GOOGLE_CLOUD; - } else { - return self::FOUND_INDIVIDUAL_PACKAGES; - } - } - - /** - * Determine available versions for a given package. - * @param string $package - * @return array - */ - private static function getCurrentPackageVersions($package) - { - exec( - "composer show --all $package |grep 'versions : '", - $output, - $ret - ); - if ($ret !== 0) { - throw new GoogleCloudVersionException( - "Failed to determine available versions of $package package" - ); - } - // Remove the title - $output = substr($output[0], strlen('versions : ')); - - // Split the version strings - $versions = preg_split('/[,\s]+/', $output); - - // Remove '*', indicator for the latest stable - $versions = array_diff($versions, ['*']); - return $versions; - } -} diff --git a/php-base/stackdriver-files/enable_stackdriver_integration.sh b/php-base/stackdriver-files/enable_stackdriver_integration.sh old mode 100644 new mode 100755 index 9f1e2801..a88639c5 --- a/php-base/stackdriver-files/enable_stackdriver_integration.sh +++ b/php-base/stackdriver-files/enable_stackdriver_integration.sh @@ -28,15 +28,6 @@ echo "Enabling stackdriver integration..." # To start the batch daemon cp /stackdriver-files/batch-daemon.conf /etc/supervisor/conf.d -# Detect the stackdriver prepend path -set +e -PREPEND_PATH=`php /stackdriver-files/locate_stackdriver_prepend.php` -set -e -if [ $? -ne 0 ]; then - if [ "${1}" = "--individual" ]; then - PREPEND_PATH="/app/vendor/google/cloud-error-reporting/prepend.php" - else - PREPEND_PATH="/app/vendor/google/cloud/src/ErrorReporting/prepend.php" - fi -fi -echo "auto_prepend_file=$PREPEND_PATH" > ${PHP_DIR}/lib/conf.d/stackdriver-prepend.ini +php /stackdriver-files/enable_stackdriver_prepend.php \ + -a ${APP_DIR} + -o ${PHP_DIR}/lib/conf.d/stackdriver-prepend.ini diff --git a/php-base/stackdriver-files/enable_stackdriver_prepend.php b/php-base/stackdriver-files/enable_stackdriver_prepend.php new file mode 100644 index 00000000..2dedc49f --- /dev/null +++ b/php-base/stackdriver-files/enable_stackdriver_prepend.php @@ -0,0 +1,38 @@ + '/app', + 'o' => 'php://stdout' +]; + +require_once $options['a'] . '/vendor/autoload.php'; +require_once __DIR__ . '/stackdriver_integration.php'; + +$integration = new StackdriverIntegration(); + +try { + $location = $integration->prependFileLocation(); + $fp = fopen($options['o'], 'w'); + try { + fwrite($fp, 'auto_prepend_file=' . $location . PHP_EOL); + } finally { + fclose($fp); + } +} catch (Exception $e) { + die($e->getMessage()); +} \ No newline at end of file diff --git a/php-base/stackdriver-files/locate_stackdriver_prepend.php b/php-base/stackdriver-files/locate_stackdriver_prepend.php deleted file mode 100644 index 931b03c1..00000000 --- a/php-base/stackdriver-files/locate_stackdriver_prepend.php +++ /dev/null @@ -1,36 +0,0 @@ -hasMethod('prependFileLocation')) { - echo Bootstrap::prependFileLocation() . PHP_EOL; - } else { - // default to same directory as the Bootstrap.php - echo realpath(dirname($reflection->getFileName()) . '/prepend.php') . PHP_EOL; - } -} else { - die('cannot find ErrorReporting\Bootstrap class'); -} diff --git a/php-base/stackdriver-files/stackdriver_integration.php b/php-base/stackdriver-files/stackdriver_integration.php new file mode 100644 index 00000000..6964d16e --- /dev/null +++ b/php-base/stackdriver-files/stackdriver_integration.php @@ -0,0 +1,89 @@ +validErrorReportingVersion()) { + throw new Exception('You must include either google/cloud >= 0.33.0 or google/error-reporting >= 0.4.0'); + } + + if (!$this->validLoggingVersion()) { + throw new Exception('You must include either google/cloud >= 0.33.0 or google/logging >= 1.3.0'); + } + + $file = null; + $reflection = new \ReflectionClass(Bootstrap::class); + if ($reflection->hasMethod('prependFileLocation')) { + $file = Bootstrap::prependFileLocation(); + } else { + // default to same directory as the Bootstrap.php + $file = realpath(dirname($reflection->getFileName()) . '/prepend.php'); + } + + if (!file_exists($file)) { + throw new Exception(sprintf('expected file %s to exist', $file)); + } + + return $file; + } + + /** + * Returns whether or not the ErrorReporting version is high enough. + * + * @return bool + */ + public function validErrorReportingVersion() + { + // Any version that has the `Bootstrap` class is considered high enough + return class_exists(Bootstrap::class); + } + + /** + * Returns whether or not the Logging version is high enough. + * + * @return bool + */ + public function validLoggingVersion() + { + return class_exists(LoggingClient::class) && + (float) LoggingClient::VERSION >= 1.3; + } +} \ No newline at end of file From 99becb5542bd72ef2ff93f2fae5a517eb2c07c71 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 18 Apr 2018 12:07:58 -0700 Subject: [PATCH 2/8] Fix code style --- php-base/stackdriver-files/enable_stackdriver_prepend.php | 2 +- php-base/stackdriver-files/stackdriver_integration.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php-base/stackdriver-files/enable_stackdriver_prepend.php b/php-base/stackdriver-files/enable_stackdriver_prepend.php index 2dedc49f..10599b77 100644 --- a/php-base/stackdriver-files/enable_stackdriver_prepend.php +++ b/php-base/stackdriver-files/enable_stackdriver_prepend.php @@ -35,4 +35,4 @@ } } catch (Exception $e) { die($e->getMessage()); -} \ No newline at end of file +} diff --git a/php-base/stackdriver-files/stackdriver_integration.php b/php-base/stackdriver-files/stackdriver_integration.php index 6964d16e..4576c5cf 100644 --- a/php-base/stackdriver-files/stackdriver_integration.php +++ b/php-base/stackdriver-files/stackdriver_integration.php @@ -86,4 +86,4 @@ public function validLoggingVersion() return class_exists(LoggingClient::class) && (float) LoggingClient::VERSION >= 1.3; } -} \ No newline at end of file +} From ae42e31e013d78d15b47663252e3cd4f343d0af4 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 18 Apr 2018 12:56:16 -0700 Subject: [PATCH 3/8] Remove gen dockerfile tests --- .../Exception/GoogleCloudVersionException.php | 22 ------------------- .../test_data/stackdriver_individual/app.yaml | 6 ----- .../stackdriver_individual/composer.json | 6 ----- .../stackdriver_no_composer/app.yaml | 6 ----- .../stackdriver_no_google_cloud/app.yaml | 6 ----- .../stackdriver_no_google_cloud/composer.json | 5 ----- .../test_data/stackdriver_old_er/app.yaml | 6 ----- .../stackdriver_old_er/composer.json | 6 ----- .../stackdriver_old_google_cloud/app.yaml | 6 ----- .../composer.json | 5 ----- .../stackdriver_old_logging/app.yaml | 6 ----- .../stackdriver_old_logging/composer.json | 6 ----- .../test_data/stackdriver_simple/app.yaml | 6 ----- .../stackdriver_simple/composer.json | 5 ----- .../test_data/stackdriver_wildcard/app.yaml | 6 ----- .../stackdriver_wildcard/composer.json | 5 ----- php-base/tests/InstallExtensionsTest.php | 8 +++---- .../samples/{phalcon.json => igbinary.json} | 2 +- php-base/tests/samples/mixed.json | 2 +- 19 files changed, 6 insertions(+), 114 deletions(-) delete mode 100644 builder/gen-dockerfile/src/Builder/Exception/GoogleCloudVersionException.php delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_individual/app.yaml delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_individual/composer.json delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_no_composer/app.yaml delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_no_google_cloud/app.yaml delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_no_google_cloud/composer.json delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_old_er/app.yaml delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_old_er/composer.json delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_old_google_cloud/app.yaml delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_old_google_cloud/composer.json delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_old_logging/app.yaml delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_old_logging/composer.json delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_simple/app.yaml delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_simple/composer.json delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_wildcard/app.yaml delete mode 100644 builder/gen-dockerfile/tests/test_data/stackdriver_wildcard/composer.json rename php-base/tests/samples/{phalcon.json => igbinary.json} (64%) diff --git a/builder/gen-dockerfile/src/Builder/Exception/GoogleCloudVersionException.php b/builder/gen-dockerfile/src/Builder/Exception/GoogleCloudVersionException.php deleted file mode 100644 index a58155c3..00000000 --- a/builder/gen-dockerfile/src/Builder/Exception/GoogleCloudVersionException.php +++ /dev/null @@ -1,22 +0,0 @@ -assertEquals(['phalcon' => '*'], $installer->extensions()); + $installer = new InstallExtensions(__DIR__ . '/samples/igbinary.json'); + $this->assertEquals(['igbinary'], $installer->extensions(), implode(',', $installer->errors())); } public function testDetectsSharedExtensions() { $installer = new InstallExtensions(__DIR__ . '/samples/shared.json'); - $this->assertEquals(['mbstring' => '*'], $installer->extensions()); + $this->assertEquals(['mbstring'], $installer->extensions()); } public function testInstallsExtensions() @@ -38,7 +38,7 @@ public function testInstallsExtensions() $output = tempnam("/tmp", "php.ini"); $installer = new InstallExtensions(__DIR__ . '/samples/mixed.json', $output); $this->assertTrue($installer->installExtensions()); - $this->assertEquals("extension=phalcon.so\nextension=mbstring.so\n", file_get_contents($output)); + $this->assertEquals("extension=igbinary.so\nextension=mbstring.so\n", file_get_contents($output)); unlink($output); } diff --git a/php-base/tests/samples/phalcon.json b/php-base/tests/samples/igbinary.json similarity index 64% rename from php-base/tests/samples/phalcon.json rename to php-base/tests/samples/igbinary.json index 8c9cbdbe..eae313d5 100644 --- a/php-base/tests/samples/phalcon.json +++ b/php-base/tests/samples/igbinary.json @@ -1,6 +1,6 @@ { "require": { "php": "7.0.*", - "ext-phalcon": "*" + "ext-igbinary": "*" } } diff --git a/php-base/tests/samples/mixed.json b/php-base/tests/samples/mixed.json index 6a0244bd..47796815 100644 --- a/php-base/tests/samples/mixed.json +++ b/php-base/tests/samples/mixed.json @@ -1,7 +1,7 @@ { "require": { "php": "7.0.*", - "ext-phalcon": "*", + "ext-igbinary": "*", "ext-mbstring": "*" } } From 2d918cbf711e991655143ada44f827c7a66d66bc Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 18 Apr 2018 12:57:02 -0700 Subject: [PATCH 4/8] Add base tests for stackdriver integration --- php-base/tests/StackdriverIntegrationTest.php | 51 ++ .../stackdriver_individual/composer.json | 6 + .../stackdriver_individual/composer.lock | 862 ++++++++++++++++++ .../stackdriver_no_google_cloud/composer.json | 5 + .../samples/stackdriver_old_er/composer.json | 6 + .../composer.json | 5 + .../stackdriver_old_logging/composer.json | 6 + .../samples/stackdriver_simple/composer.json | 5 + .../stackdriver_wildcard/composer.json | 5 + 9 files changed, 951 insertions(+) create mode 100644 php-base/tests/StackdriverIntegrationTest.php create mode 100644 php-base/tests/samples/stackdriver_individual/composer.json create mode 100644 php-base/tests/samples/stackdriver_individual/composer.lock create mode 100644 php-base/tests/samples/stackdriver_no_google_cloud/composer.json create mode 100644 php-base/tests/samples/stackdriver_old_er/composer.json create mode 100644 php-base/tests/samples/stackdriver_old_google_cloud/composer.json create mode 100644 php-base/tests/samples/stackdriver_old_logging/composer.json create mode 100644 php-base/tests/samples/stackdriver_simple/composer.json create mode 100644 php-base/tests/samples/stackdriver_wildcard/composer.json diff --git a/php-base/tests/StackdriverIntegrationTest.php b/php-base/tests/StackdriverIntegrationTest.php new file mode 100644 index 00000000..90ea03ab --- /dev/null +++ b/php-base/tests/StackdriverIntegrationTest.php @@ -0,0 +1,51 @@ +oldpwd = getcwd(); + } + + public function tearDown() + { + chdir($this->oldpwd); + parent::tearDown(); + } + + /** + * @dataProvider dataProvider + */ + public function testEnabler($directory) + { + $dir = realpath(__DIR__ . '/' . $directory); + exec("cd $dir && composer install"); + exec("php enable_stackdriver_prepend.php -a $dir"); + } + + public function dataProvider(){ + return [ + ['samples/stackdriver_individual'] + ]; + } +} diff --git a/php-base/tests/samples/stackdriver_individual/composer.json b/php-base/tests/samples/stackdriver_individual/composer.json new file mode 100644 index 00000000..d6e4bea4 --- /dev/null +++ b/php-base/tests/samples/stackdriver_individual/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "google/cloud-logging": "^1.3.1", + "google/cloud-error-reporting": "^0.4.1" + } +} diff --git a/php-base/tests/samples/stackdriver_individual/composer.lock b/php-base/tests/samples/stackdriver_individual/composer.lock new file mode 100644 index 00000000..c4951f53 --- /dev/null +++ b/php-base/tests/samples/stackdriver_individual/composer.lock @@ -0,0 +1,862 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "c14f26bde3705fb869e7e1006bf1c8e3", + "packages": [ + { + "name": "firebase/php-jwt", + "version": "v5.0.0", + "source": { + "type": "git", + "url": "https://github.com/firebase/php-jwt.git", + "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/9984a4d3a32ae7673d6971ea00bae9d0a1abba0e", + "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": " 4.8.35" + }, + "type": "library", + "autoload": { + "psr-4": { + "Firebase\\JWT\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Neuman Vong", + "email": "neuman+pear@twilio.com", + "role": "Developer" + }, + { + "name": "Anant Narayanan", + "email": "anant@php.net", + "role": "Developer" + } + ], + "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", + "homepage": "https://github.com/firebase/php-jwt", + "time": "2017-06-27T22:17:23+00:00" + }, + { + "name": "google/auth", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/google/google-auth-library-php.git", + "reference": "8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/google/google-auth-library-php/zipball/8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71", + "reference": "8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71", + "shasum": "" + }, + "require": { + "firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0", + "guzzlehttp/guzzle": "~5.3.1|~6.0", + "guzzlehttp/psr7": "^1.2", + "php": ">=5.4", + "psr/cache": "^1.0", + "psr/http-message": "^1.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^1.11", + "guzzlehttp/promises": "0.1.1|^1.3", + "phpunit/phpunit": "^4.8.36|^5.7", + "sebastian/comparator": ">=1.2.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Google\\Auth\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "Google Auth Library for PHP", + "homepage": "http://github.com/google/google-auth-library-php", + "keywords": [ + "Authentication", + "google", + "oauth2" + ], + "time": "2018-04-06T19:26:30+00:00" + }, + { + "name": "google/cloud-core", + "version": "v1.19.2", + "source": { + "type": "git", + "url": "https://github.com/GoogleCloudPlatform/google-cloud-php-core.git", + "reference": "c0d71125f31400b09d1a1097e6c336f3e2908532" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php-core/zipball/c0d71125f31400b09d1a1097e6c336f3e2908532", + "reference": "c0d71125f31400b09d1a1097e6c336f3e2908532", + "shasum": "" + }, + "require": { + "google/auth": "^1.2", + "guzzlehttp/guzzle": "^5.3|^6.0", + "guzzlehttp/psr7": "^1.2", + "monolog/monolog": "~1", + "php": ">=5.5", + "psr/http-message": "1.0.*", + "rize/uri-template": "~0.3" + }, + "require-dev": { + "erusev/parsedown": "^1.6", + "google/gax": "^0.31.1", + "opis/closure": "^3", + "phpdocumentor/reflection": "^3.0", + "phpunit/phpunit": "^4.8|^5.0", + "squizlabs/php_codesniffer": "2.*" + }, + "suggest": { + "opis/closure": "May be used to serialize closures to process jobs in the batch daemon. Please require version ^3.", + "symfony/lock": "Required for the Spanner cached based session pool. Please require the following commit: 3.3.x-dev#1ba6ac9" + }, + "bin": [ + "bin/google-cloud-batch" + ], + "type": "library", + "extra": { + "component": { + "id": "cloud-core", + "target": "GoogleCloudPlatform/google-cloud-php-core.git", + "path": "Core", + "entry": "src/ServiceBuilder.php" + } + }, + "autoload": { + "psr-4": { + "Google\\Cloud\\Core\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "Google Cloud PHP shared dependency, providing functionality useful to all components.", + "time": "2018-04-16T18:09:56+00:00" + }, + { + "name": "google/cloud-error-reporting", + "version": "v0.4.3", + "source": { + "type": "git", + "url": "https://github.com/GoogleCloudPlatform/google-cloud-php-errorreporting.git", + "reference": "6cf9f760cb3d1d46922611d2682da6b4af12ea00" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php-errorreporting/zipball/6cf9f760cb3d1d46922611d2682da6b4af12ea00", + "reference": "6cf9f760cb3d1d46922611d2682da6b4af12ea00", + "shasum": "" + }, + "require": { + "ext-grpc": "*", + "google/gax": "^0.23.0", + "google/proto-client": "^0.23.0" + }, + "type": "library", + "extra": { + "component": { + "id": "cloud-error-reporting", + "target": "GoogleCloudPlatform/google-cloud-php-errorreporting.git", + "path": "src/ErrorReporting", + "entry": null + } + }, + "autoload": { + "psr-4": { + "Google\\Cloud\\ErrorReporting\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "Stackdriver Error Reporting Client for PHP", + "time": "2017-09-05T20:40:19+00:00" + }, + { + "name": "google/cloud-logging", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/GoogleCloudPlatform/google-cloud-php-logging.git", + "reference": "0a06fcf1c0ead3e5491d3a68ffb0ef1d7b308f93" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php-logging/zipball/0a06fcf1c0ead3e5491d3a68ffb0ef1d7b308f93", + "reference": "0a06fcf1c0ead3e5491d3a68ffb0ef1d7b308f93", + "shasum": "" + }, + "require": { + "google/cloud-core": "^1.0", + "google/gax": "^0.23", + "google/proto-client": "^0.23" + }, + "type": "library", + "extra": { + "component": { + "id": "cloud-logging", + "target": "GoogleCloudPlatform/google-cloud-php-logging.git", + "path": "src/Logging", + "entry": "LoggingClient.php" + } + }, + "autoload": { + "psr-4": { + "Google\\Cloud\\Logging\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "Stackdriver Logging Client for PHP", + "time": "2017-09-12T20:49:36+00:00" + }, + { + "name": "google/gax", + "version": "0.23.0", + "source": { + "type": "git", + "url": "https://github.com/googleapis/gax-php.git", + "reference": "e09f219ed50ea1f6162d1945156d2ea6af6cd1f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/googleapis/gax-php/zipball/e09f219ed50ea1f6162d1945156d2ea6af6cd1f9", + "reference": "e09f219ed50ea1f6162d1945156d2ea6af6cd1f9", + "shasum": "" + }, + "require": { + "google/auth": "~0.9|^1.0", + "google/protobuf": "^3.4", + "grpc/grpc": "^1.4", + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "4.8.*", + "squizlabs/php_codesniffer": "2.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Google\\GAX\\": "src/", + "Google\\GAX\\UnitTests\\": "tests/", + "Google\\": "src/generated/Google/", + "GPBMetadata\\": "src/generated/GPBMetadata/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Google API Extensions for PHP", + "homepage": "https://github.com/googleapis/gax-php", + "keywords": [ + "google" + ], + "time": "2017-08-31T21:40:57+00:00" + }, + { + "name": "google/proto-client", + "version": "0.23.0", + "source": { + "type": "git", + "url": "https://github.com/googleapis/proto-client-php.git", + "reference": "b159f408b6acdba55bf727c3639d03bb0117fc27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/googleapis/proto-client-php/zipball/b159f408b6acdba55bf727c3639d03bb0117fc27", + "reference": "b159f408b6acdba55bf727c3639d03bb0117fc27", + "shasum": "" + }, + "require": { + "google/protobuf": "^3.3.2", + "php": ">=5.5" + }, + "require-dev": { + "google/gax": ">=0.20.0", + "phpunit/phpunit": "4.8.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Google\\": "src/Google/", + "GPBMetadata\\": "src/GPBMetadata/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Generated proto and gRPC classes for Google Cloud Platform in PHP", + "homepage": "https://github.com/googleapis/proto-client-php", + "keywords": [ + "google" + ], + "time": "2017-09-01T22:33:04+00:00" + }, + { + "name": "google/protobuf", + "version": "v3.5.2", + "source": { + "type": "git", + "url": "https://github.com/google/protobuf.git", + "reference": "b5fbb742af122b565925987e65c08957739976a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/google/protobuf/zipball/b5fbb742af122b565925987e65c08957739976a7", + "reference": "b5fbb742af122b565925987e65c08957739976a7", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": ">=4.8.0" + }, + "suggest": { + "ext-bcmath": "Need to support JSON deserialization" + }, + "type": "library", + "autoload": { + "psr-4": { + "Google\\Protobuf\\": "php/src/Google/Protobuf", + "GPBMetadata\\Google\\Protobuf\\": "php/src/GPBMetadata/Google/Protobuf" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "proto library for PHP", + "homepage": "https://developers.google.com/protocol-buffers/", + "keywords": [ + "proto" + ], + "time": "2018-03-06T03:54:18+00:00" + }, + { + "name": "grpc/grpc", + "version": "1.10.0", + "source": { + "type": "git", + "url": "https://github.com/grpc/grpc-php.git", + "reference": "741f59bac86c7b5e45818c8f2eec6980921bce23" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/grpc/grpc-php/zipball/741f59bac86c7b5e45818c8f2eec6980921bce23", + "reference": "741f59bac86c7b5e45818c8f2eec6980921bce23", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "google/auth": "v0.9" + }, + "suggest": { + "ext-protobuf": "For better performance, install the protobuf C extension.", + "google/protobuf": "To get started using grpc quickly, install the native protobuf library." + }, + "type": "library", + "autoload": { + "psr-4": { + "Grpc\\": "src/lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "gRPC library for PHP", + "homepage": "https://grpc.io", + "keywords": [ + "rpc" + ], + "time": "2018-03-28T22:54:08+00:00" + }, + { + "name": "guzzlehttp/guzzle", + "version": "6.3.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "68d0ea14d5a3f42a20e87632a5f84931e2709c90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/68d0ea14d5a3f42a20e87632a5f84931e2709c90", + "reference": "68d0ea14d5a3f42a20e87632a5f84931e2709c90", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.4", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.3-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2018-03-26T16:33:04+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-12-20T10:07:11+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2017-03-20T17:10:46+00:00" + }, + { + "name": "monolog/monolog", + "version": "1.23.0", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4", + "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "psr/log": "~1.0" + }, + "provide": { + "psr/log-implementation": "1.0.0" + }, + "require-dev": { + "aws/aws-sdk-php": "^2.4.9 || ^3.0", + "doctrine/couchdb": "~1.0@dev", + "graylog2/gelf-php": "~1.0", + "jakub-onderka/php-parallel-lint": "0.9", + "php-amqplib/php-amqplib": "~2.4", + "php-console/php-console": "^3.1.3", + "phpunit/phpunit": "~4.5", + "phpunit/phpunit-mock-objects": "2.3.0", + "ruflin/elastica": ">=0.90 <3.0", + "sentry/sentry": "^0.13", + "swiftmailer/swiftmailer": "^5.3|^6.0" + }, + "suggest": { + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-mongo": "Allow sending log messages to a MongoDB server", + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", + "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", + "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", + "php-console/php-console": "Allow sending log messages to Google Chrome", + "rollbar/rollbar": "Allow sending log messages to Rollbar", + "ruflin/elastica": "Allow sending log messages to an Elastic Search server", + "sentry/sentry": "Allow sending log messages to a Sentry server" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Monolog\\": "src/Monolog" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", + "homepage": "http://github.com/Seldaek/monolog", + "keywords": [ + "log", + "logging", + "psr-3" + ], + "time": "2017-06-19T01:22:40+00:00" + }, + { + "name": "psr/cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "time": "2016-08-06T20:24:11+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, + { + "name": "rize/uri-template", + "version": "0.3.2", + "source": { + "type": "git", + "url": "https://github.com/rize/UriTemplate.git", + "reference": "9e5fdd5c47147aa5adf7f760002ee591ed37b9ca" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rize/UriTemplate/zipball/9e5fdd5c47147aa5adf7f760002ee591ed37b9ca", + "reference": "9e5fdd5c47147aa5adf7f760002ee591ed37b9ca", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Rize\\UriTemplate": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marut K", + "homepage": "http://twitter.com/rezigned" + } + ], + "description": "PHP URI Template (RFC 6570) supports both expansion & extraction", + "keywords": [ + "RFC 6570", + "template", + "uri" + ], + "time": "2017-06-14T03:57:53+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/php-base/tests/samples/stackdriver_no_google_cloud/composer.json b/php-base/tests/samples/stackdriver_no_google_cloud/composer.json new file mode 100644 index 00000000..4cd458c0 --- /dev/null +++ b/php-base/tests/samples/stackdriver_no_google_cloud/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "google/cloud-logging": "*" + } +} diff --git a/php-base/tests/samples/stackdriver_old_er/composer.json b/php-base/tests/samples/stackdriver_old_er/composer.json new file mode 100644 index 00000000..7ffa29b7 --- /dev/null +++ b/php-base/tests/samples/stackdriver_old_er/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "google/cloud-logging": "^1.4.1", + "google/cloud-error-reporting": "^0.3.0" + } +} diff --git a/php-base/tests/samples/stackdriver_old_google_cloud/composer.json b/php-base/tests/samples/stackdriver_old_google_cloud/composer.json new file mode 100644 index 00000000..1732a5ea --- /dev/null +++ b/php-base/tests/samples/stackdriver_old_google_cloud/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "google/cloud": "^0.32" + } +} diff --git a/php-base/tests/samples/stackdriver_old_logging/composer.json b/php-base/tests/samples/stackdriver_old_logging/composer.json new file mode 100644 index 00000000..99a943fc --- /dev/null +++ b/php-base/tests/samples/stackdriver_old_logging/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "google/cloud-logging": "<=1.2.0", + "google/cloud-error-reporting": "^0.4.1" + } +} diff --git a/php-base/tests/samples/stackdriver_simple/composer.json b/php-base/tests/samples/stackdriver_simple/composer.json new file mode 100644 index 00000000..b62201bb --- /dev/null +++ b/php-base/tests/samples/stackdriver_simple/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "google/cloud": "^0.34.1" + } +} diff --git a/php-base/tests/samples/stackdriver_wildcard/composer.json b/php-base/tests/samples/stackdriver_wildcard/composer.json new file mode 100644 index 00000000..c555cdb3 --- /dev/null +++ b/php-base/tests/samples/stackdriver_wildcard/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "google/cloud": "*" + } +} From 8148f47c3de578ebda6b44ad83f147871824fb28 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 18 Apr 2018 16:53:07 -0700 Subject: [PATCH 5/8] Run the php-base tests. Add tests for version checking google/cloud libraries --- .../tests/GenFilesCommandTest.php | 89 ------- cloudbuild.yaml | 7 + php-base/build-scripts/detect_php_version.php | 65 +----- php-base/build-scripts/install_extensions.php | 201 +--------------- .../build-scripts/src/DetectPhpVersion.php | 80 +++++++ .../build-scripts/src/InstallExtensions.php | 217 ++++++++++++++++++ .../enable_stackdriver_prepend.php | 3 +- .../stackdriver_integration.php | 9 +- php-base/tests/DetectPhpVersionTest.php | 18 +- php-base/tests/InstallExtensionsTest.php | 12 +- php-base/tests/StackdriverIntegrationTest.php | 44 +++- php-base/tests/bootstrap.php | 2 + php-base/tests/samples/mixed.json | 4 +- .../samples/{igbinary.json => phalcon.json} | 2 +- php-base/tests/samples/shared.json | 2 +- .../samples/stackdriver_dev/composer.json | 11 + .../samples/stackdriver_old_er/composer.json | 2 +- 17 files changed, 392 insertions(+), 376 deletions(-) create mode 100644 php-base/build-scripts/src/DetectPhpVersion.php create mode 100644 php-base/build-scripts/src/InstallExtensions.php rename php-base/tests/samples/{igbinary.json => phalcon.json} (64%) create mode 100644 php-base/tests/samples/stackdriver_dev/composer.json diff --git a/builder/gen-dockerfile/tests/GenFilesCommandTest.php b/builder/gen-dockerfile/tests/GenFilesCommandTest.php index feaee36a..dfaafd56 100644 --- a/builder/gen-dockerfile/tests/GenFilesCommandTest.php +++ b/builder/gen-dockerfile/tests/GenFilesCommandTest.php @@ -187,73 +187,6 @@ public function dataProvider() [], '\\Google\\Cloud\\Runtimes\\Builder\\Exception\\InvalidComposerFlagsException' ], - [ - // stackdriver simple case - __DIR__ . '/test_data/stackdriver_simple', - null, - '', - '/app/web', - 'added by the php runtime builder', - 'gcr.io/google-appengine/php72:latest', - ["COMPOSER_FLAGS='--no-dev --prefer-dist' \\\n", - "FRONT_CONTROLLER_FILE='index.php' \\\n", - "DETECTED_PHP_VERSION='7.2' \\\n", - "IS_BATCH_DAEMON_RUNNING='true' \n", - "enable_stackdriver_integration.sh" - ] - ], - [ - // stackdriver wildcard dep - __DIR__ . '/test_data/stackdriver_wildcard', - null, - '', - '/app/web', - 'added by the php runtime builder', - 'gcr.io/google-appengine/php72:latest', - ["COMPOSER_FLAGS='--no-dev --prefer-dist' \\\n", - "FRONT_CONTROLLER_FILE='index.php' \\\n", - "DETECTED_PHP_VERSION='7.2' \\\n", - "IS_BATCH_DAEMON_RUNNING='true' \n", - "enable_stackdriver_integration.sh" - ] - ], - [ - // stackdriver individual packages - __DIR__ . '/test_data/stackdriver_individual', - null, - '', - '/app/web', - 'added by the php runtime builder', - 'gcr.io/google-appengine/php72:latest', - ["COMPOSER_FLAGS='--no-dev --prefer-dist' \\\n", - "FRONT_CONTROLLER_FILE='index.php' \\\n", - "DETECTED_PHP_VERSION='7.2' \\\n", - "IS_BATCH_DAEMON_RUNNING='true' \n", - "enable_stackdriver_integration.sh --individual" - ] - ], - [ - // stackdriver old logging - __DIR__ . '/test_data/stackdriver_old_logging', - null, - '', - '/app/web', - 'added by the php runtime builder', - 'gcr.io/google-appengine/php72:latest', - [], - '\\Google\\Cloud\\Runtimes\\Builder\\Exception\\GoogleCloudVersionException' - ], - [ - // stackdriver old error_reporting - __DIR__ . '/test_data/stackdriver_old_er', - null, - '', - '/app/web', - 'added by the php runtime builder', - 'gcr.io/google-appengine/php72:latest', - [], - '\\Google\\Cloud\\Runtimes\\Builder\\Exception\\GoogleCloudVersionException' - ], [ // stackdriver no composer.json __DIR__ . '/test_data/stackdriver_no_composer', @@ -265,28 +198,6 @@ public function dataProvider() [], '\\Google\\Cloud\\Runtimes\\Builder\\Exception\\GoogleCloudVersionException' ], - [ - // stackdriver no google/cloud - __DIR__ . '/test_data/stackdriver_no_google_cloud', - null, - '', - '/app/web', - 'added by the php runtime builder', - 'gcr.io/google-appengine/php72:latest', - [], - '\\Google\\Cloud\\Runtimes\\Builder\\Exception\\GoogleCloudVersionException' - ], - [ - // stackdriver old google/cloud - __DIR__ . '/test_data/stackdriver_old_google_cloud', - null, - '', - '/app/web', - 'added by the php runtime builder', - 'gcr.io/google-appengine/php72:latest', - [], - '\\Google\\Cloud\\Runtimes\\Builder\\Exception\\GoogleCloudVersionException' - ], [ // PHP 5.6 __DIR__ . '/test_data/php56', diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 03094c65..5fe9a0f6 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -67,6 +67,13 @@ steps: waitFor: ['php56'] id: test-runner + # base tests + - name: gcr.io/cloud-builders/docker + args: ['run', '-v', '/workspace/php-base:/workspace', 'gcr.io/${_GOOGLE_PROJECT_ID}/php-test-runner:$_TAG'] + waitFor: ['-'] + id: php-base-tests + waitFor: ['test-runner', 'php-base'] + # php-onbuild - name: gcr.io/cloud-builders/docker args: ['build', '-t', 'gcr.io/${_GOOGLE_PROJECT_ID}/php:$_TAG', '.'] diff --git a/php-base/build-scripts/detect_php_version.php b/php-base/build-scripts/detect_php_version.php index 19e81f95..fdc8664e 100644 --- a/php-base/build-scripts/detect_php_version.php +++ b/php-base/build-scripts/detect_php_version.php @@ -14,70 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require_once __DIR__ . '/vendor/autoload.php'; - -use Composer\Semver\Semver; - -class ExactVersionException extends Exception -{ -} - -class NoSpecifiedVersionException extends Exception -{ - public function __construct() - { - parent::__construct("No version found in composer.json"); - } -} - -class InvalidVersionException extends Exception -{ - public function __construct($constraint, $availableVersions) - { - parent::__construct("No suitable version for for '$constraint' in ${implode(',', $availableVersions)}"); - } -} - -class DetectPhpVersion -{ - public static function versionFromComposer($filename, $availableVersions = null) - { - $composer = json_decode(file_get_contents($filename), true); - if (is_array($composer) - && array_key_exists('require', $composer) - && array_key_exists('php', $composer['require'])) { - $constraints = $composer['require']['php']; - return self::version($constraints, $availableVersions); - } - throw new NoSpecifiedVersionException(); - } - public static function version($constraint, $availableVersions = null) - { - if (preg_match('/^\d+\.\d+\.\d+$/', $constraint)) { - throw new ExactVersionException(); - } - - $availableVersions = $availableVersions ?: self::detectAvailableVersions(); - foreach ($availableVersions as $version) { - if (Semver::satisfies($version, $constraint)) { - // The first match wins, picking the highest version possible. - return $version; - } - } - throw new InvalidVersionException($constraint, $availableVersions); - } - - private static function detectAvailableVersions() - { - return [ - trim(file_get_contents('/opt/php72_version')), - trim(file_get_contents('/opt/php71_version')), - trim(file_get_contents('/opt/php70_version')), - trim(file_get_contents('/opt/php56_version')) - ]; - } -} +require_once __DIR__ . '/vendor/autoload.php'; +require_once __DIR__ . '/src/DetectPhpVersion.php'; if (basename($argv[0]) == basename(__FILE__)) { if (count($argv) < 2) { diff --git a/php-base/build-scripts/install_extensions.php b/php-base/build-scripts/install_extensions.php index 75923768..88a8ead4 100644 --- a/php-base/build-scripts/install_extensions.php +++ b/php-base/build-scripts/install_extensions.php @@ -15,206 +15,7 @@ * limitations under the License. */ -class InstallExtensions -{ - const AVAILABLE_EXTENSIONS = [ - 'bcmath', - 'calendar', - 'exif', - 'ftp', - 'gd', - 'gettext', - 'intl', - 'mbstring', - 'mysql', - 'shmop', - 'soap', - 'sqlite3', - 'pdo_sqlite', - 'xmlrpc', - 'xsl', - ## Debian package extensions below - 'cassandra', - 'ev', - 'event', - 'grpc', - 'imagick', - 'mailparse', - 'memcache', - 'memcached', - 'mongodb', - 'oauth', - 'opencensus', - 'phalcon', - 'pq', - 'protobuf', - 'raphf', - 'rdkafka', - 'redis', - 'stackdriver_debugger' - ]; - const AVAILABLE_EXTENSIONS_TO_INSTALL = [ - 'amqp', - 'apm', - 'bitset', - 'couchbase', - 'ds', - 'eio', - 'hprose', - 'igbinary', - 'jsond', - 'krb5', - 'lua', - 'lzf', - 'memprof', - 'mongo', - 'seaslog', - 'stomp', - 'swoole', - 'sync', - 'tcpwrap', - 'timezonedb', - 'v8js', - 'vips', - 'yaconf', - 'yaf', - 'yaml' - ]; - const UNAVAILABLE_EXTENSIONS = [ - 'apm' => ['5.6'], - 'couchbase' => ['5.6'], - 'ds' => ['5.6'], - 'lua' => ['5.6'], - 'memcache' => ['7.0', '7.1', '7.2'], - 'mongo' => ['7.0', '7.1', '7.2'], - 'opencensus' => ['5.6'], - 'phalcon' => ['7.1', '7.2'], - 'stackdriver_debugger' => ['5.6'], - 'v8js' => ['5.6'], - 'vips' => ['5.6'], - 'yaconf' => ['5.6'] - ]; - - private $extensions = []; - private $extensionsToInstall = []; - private $phpVersion; - private $configFile; - private $errors = []; - - public function __construct($filename, $configFile = null, $phpVersion = null) - { - $this->phpVersion = $phpVersion; - $this->configFile = $configFile ?: $this->defaultConfigFile(); - $composer = json_decode(file_get_contents($filename), true); - if (is_array($composer) && array_key_exists('require', $composer)) { - foreach ($composer['require'] as $package => $version) { - if (substr($package, 0, 4) == 'ext-') { - $this->addExtension(substr($package, 4), $version); - } - } - } - } - - public function extensions() - { - return $this->extensions; - } - - public function errors() - { - return $this->errors; - } - - public function installExtensions() - { - // If there are errors, then bail out - if (!empty($this->errors)) { - return false; - } - - // Nothing to do - if (empty($this->extensions)) { - return true; - } - - // Install any new debian packages - $this->installPackages(); - - // Write a custom php.ini file that enables each extension - $this->writeConfigFile(); - - return true; - } - - public function packageName($extension) - { - return 'gcp-php' . str_replace('.', '', $this->phpVersion) . '-' . $extension; - } - - private function defaultConfigFile() - { - return implode([ - getenv('PHP_DIR'), - 'lib', - 'conf.d', - 'extensions.ini' - ], '/'); - } - - private function installPackages() - { - system('apt-get -y update'); - $command = 'apt-get install -y --no-install-recommends ' - . implode(array_map([$this, 'packageName'], $this->extensionsToInstall), ' '); - echo $command . PHP_EOL; - system($command); - } - - private function writeConfigFile() - { - $fp = fopen($this->configFile, 'a'); - foreach ($this->extensions as $extension) { - fwrite($fp, "extension=$extension.so" . PHP_EOL); - } - fclose($fp); - } - - private function addExtension($package, $version) - { - // If it's already loaded, no need for activation - if (extension_loaded($package)) { - return; - } - - // See if we support the package at all - if (!in_array($package, self::AVAILABLE_EXTENSIONS) && - !in_array($package, self::AVAILABLE_EXTENSIONS_TO_INSTALL)) { - $this->errors[] = "- $package $version is not available on your system."; - return; - } - - // Disallow any specific version pinning - if ($version != '*') { - $this->errors[] = "- $package is available, but version must be specified as \"*\" in your composer.json"; - return; - } - - // Check against our blacklist of php version/extension combinations - if (array_key_exists($package, self::UNAVAILABLE_EXTENSIONS) && - in_array($this->phpVersion, self::UNAVAILABLE_EXTENSIONS[$package])) { - $this->errors[] = "- $package is available, but not on php version {$this->phpVersion}"; - return; - } - - // We can install this extension - $this->extensions[] = $package; - - // See if we need to install the debian package - if (in_array($package, self::AVAILABLE_EXTENSIONS_TO_INSTALL)) { - $this->extensionsToInstall[] = $package; - } - } -} +require_once __DIR__ . '/src/InstallExtensions.php'; if (basename($argv[0]) == basename(__FILE__)) { if (count($argv) < 2) { diff --git a/php-base/build-scripts/src/DetectPhpVersion.php b/php-base/build-scripts/src/DetectPhpVersion.php new file mode 100644 index 00000000..b641538f --- /dev/null +++ b/php-base/build-scripts/src/DetectPhpVersion.php @@ -0,0 +1,80 @@ + ['5.6'], + 'couchbase' => ['5.6'], + 'ds' => ['5.6'], + 'lua' => ['5.6'], + 'memcache' => ['7.0', '7.1', '7.2'], + 'mongo' => ['7.0', '7.1', '7.2'], + 'opencensus' => ['5.6'], + 'phalcon' => ['7.1', '7.2'], + 'stackdriver_debugger' => ['5.6'], + 'v8js' => ['5.6'], + 'vips' => ['5.6'], + 'yaconf' => ['5.6'] + ]; + + private $extensions = []; + private $extensionsToInstall = []; + private $phpVersion; + private $configFile; + private $errors = []; + + public function __construct($filename, $configFile = null, $phpVersion = null) + { + $this->phpVersion = $phpVersion; + $this->configFile = $configFile ?: $this->defaultConfigFile(); + $composer = json_decode(file_get_contents($filename), true); + if (is_array($composer) && array_key_exists('require', $composer)) { + foreach ($composer['require'] as $package => $version) { + if (substr($package, 0, 4) == 'ext-') { + $this->addExtension(substr($package, 4), $version); + } + } + } + } + + public function extensions() + { + return $this->extensions; + } + + public function errors() + { + return $this->errors; + } + + public function installExtensions() + { + // If there are errors, then bail out + if (!empty($this->errors)) { + return false; + } + + // Nothing to do + if (empty($this->extensions)) { + return true; + } + + // Install any new debian packages + $this->installPackages(); + + // Write a custom php.ini file that enables each extension + $this->writeConfigFile(); + + return true; + } + + public function packageName($extension) + { + return 'gcp-php' . str_replace('.', '', $this->phpVersion) . '-' . $extension; + } + + private function defaultConfigFile() + { + return implode([ + getenv('PHP_DIR'), + 'lib', + 'conf.d', + 'extensions.ini' + ], '/'); + } + + private function installPackages() + { + system('apt-get -y update'); + $command = 'apt-get install -y --no-install-recommends ' + . implode(array_map([$this, 'packageName'], $this->extensionsToInstall), ' '); + echo $command . PHP_EOL; + system($command); + } + + private function writeConfigFile() + { + $fp = fopen($this->configFile, 'a'); + foreach ($this->extensions as $extension) { + fwrite($fp, "extension=$extension.so" . PHP_EOL); + } + fclose($fp); + } + + private function addExtension($package, $version) + { + // If it's already loaded, no need for activation + if (extension_loaded($package)) { + return; + } + + // See if we support the package at all + if (!in_array($package, self::AVAILABLE_EXTENSIONS) && + !in_array($package, self::AVAILABLE_EXTENSIONS_TO_INSTALL)) { + $this->errors[] = "- $package $version is not available on your system."; + return; + } + + // Disallow any specific version pinning + if ($version != '*') { + $this->errors[] = "- $package is available, but version must be specified as \"*\" in your composer.json"; + return; + } + + // Check against our blacklist of php version/extension combinations + if (array_key_exists($package, self::UNAVAILABLE_EXTENSIONS) && + in_array($this->phpVersion, self::UNAVAILABLE_EXTENSIONS[$package])) { + $this->errors[] = "- $package is available, but not on php version {$this->phpVersion}"; + return; + } + + // We can install this extension + $this->extensions[] = $package; + + // See if we need to install the debian package + if (in_array($package, self::AVAILABLE_EXTENSIONS_TO_INSTALL)) { + $this->extensionsToInstall[] = $package; + } + } +} diff --git a/php-base/stackdriver-files/enable_stackdriver_prepend.php b/php-base/stackdriver-files/enable_stackdriver_prepend.php index 10599b77..d552ade4 100644 --- a/php-base/stackdriver-files/enable_stackdriver_prepend.php +++ b/php-base/stackdriver-files/enable_stackdriver_prepend.php @@ -34,5 +34,6 @@ fclose($fp); } } catch (Exception $e) { - die($e->getMessage()); + echo $e->getMessage(); + exit(1); } diff --git a/php-base/stackdriver-files/stackdriver_integration.php b/php-base/stackdriver-files/stackdriver_integration.php index 4576c5cf..677fcb47 100644 --- a/php-base/stackdriver-files/stackdriver_integration.php +++ b/php-base/stackdriver-files/stackdriver_integration.php @@ -83,7 +83,12 @@ public function validErrorReportingVersion() */ public function validLoggingVersion() { - return class_exists(LoggingClient::class) && - (float) LoggingClient::VERSION >= 1.3; + if (!class_exists(LoggingClient::class)) { + return false; + } + list($major, $minor, $patch) = explode('.', LoggingClient::VERSION); + $major = (int) $major; + $minor = (int) $minor; + return $major > 1 || ($major == 1 && $minor >= 3); } } diff --git a/php-base/tests/DetectPhpVersionTest.php b/php-base/tests/DetectPhpVersionTest.php index 2240cf7d..fab8c3f3 100644 --- a/php-base/tests/DetectPhpVersionTest.php +++ b/php-base/tests/DetectPhpVersionTest.php @@ -17,7 +17,7 @@ use PHPUnit\Framework\TestCase; -require_once(__DIR__ . "/../build-scripts/detect_php_version.php"); +require_once(__DIR__ . "/../build-scripts/src/DetectPhpVersion.php"); class DetectPhpVersionTest extends TestCase { @@ -42,10 +42,20 @@ public function testDetectsHighestVersion() $this->assertEquals(self::PHP_71, $version); } - public function testFailureReturnsEmptyString() + /** + * @expectedException \ExactVersionException + */ + public function testExactVersionDirect() + { + $version = DetectPhpVersion::version('7.1.10', self::AVAILABLE_VERSIONS); + } + + /** + * @expectedException \InvalidVersionException + */ + public function testInvalidVersionDirect() { - $version = DetectPhpVersion::version('7.1.100', self::AVAILABLE_VERSIONS); - $this->assertEquals('', $version); + $version = DetectPhpVersion::version('^7.1.100', self::AVAILABLE_VERSIONS); } /** diff --git a/php-base/tests/InstallExtensionsTest.php b/php-base/tests/InstallExtensionsTest.php index 56ec13bb..e0384e77 100644 --- a/php-base/tests/InstallExtensionsTest.php +++ b/php-base/tests/InstallExtensionsTest.php @@ -17,28 +17,28 @@ use PHPUnit\Framework\TestCase; -require_once(__DIR__ . "/../build-scripts/install_extensions.php"); +require_once(__DIR__ . "/../build-scripts/src/InstallExtensions.php"); class InstallExtensionsTest extends TestCase { public function testDetectsPackagedExtensions() { - $installer = new InstallExtensions(__DIR__ . '/samples/igbinary.json'); - $this->assertEquals(['igbinary'], $installer->extensions(), implode(',', $installer->errors())); + $installer = new InstallExtensions(__DIR__ . '/samples/phalcon.json'); + $this->assertEquals(['phalcon'], $installer->extensions(), implode(',', $installer->errors())); } public function testDetectsSharedExtensions() { $installer = new InstallExtensions(__DIR__ . '/samples/shared.json'); - $this->assertEquals(['mbstring'], $installer->extensions()); + $this->assertEquals(['sqlite3'], $installer->extensions()); } public function testInstallsExtensions() { $output = tempnam("/tmp", "php.ini"); - $installer = new InstallExtensions(__DIR__ . '/samples/mixed.json', $output); + $installer = new InstallExtensions(__DIR__ . '/samples/shared.json', $output); $this->assertTrue($installer->installExtensions()); - $this->assertEquals("extension=igbinary.so\nextension=mbstring.so\n", file_get_contents($output)); + $this->assertEquals("extension=sqlite3.so\n", file_get_contents($output)); unlink($output); } diff --git a/php-base/tests/StackdriverIntegrationTest.php b/php-base/tests/StackdriverIntegrationTest.php index 90ea03ab..7fbe76d5 100644 --- a/php-base/tests/StackdriverIntegrationTest.php +++ b/php-base/tests/StackdriverIntegrationTest.php @@ -34,18 +34,50 @@ public function tearDown() } /** - * @dataProvider dataProvider + * @dataProvider validVersions */ - public function testEnabler($directory) + public function testValidVersions($directory, $expectedFile) { $dir = realpath(__DIR__ . '/' . $directory); - exec("cd $dir && composer install"); - exec("php enable_stackdriver_prepend.php -a $dir"); + exec("cd $dir && composer install --ignore-platform-reqs -q 2>&1", $output, $retVal); + $this->assertEquals(0, $retVal, 'command failed with: ' . implode(';', $output)); + + exec("php stackdriver-files/enable_stackdriver_prepend.php -a $dir", $output, $retVal); + $this->assertEquals(0, $retVal, 'command failed with: ' . implode(';', $output)); + $output = trim(array_pop($output)); + $this->assertStringStartsWith('auto_prepend_file=', $output); + $this->assertStringEndsWith($expectedFile, $output); } - public function dataProvider(){ + public function validVersions(){ + return [ + ['samples/stackdriver_individual', 'vendor/google/cloud-error-reporting/prepend.php'], + ['samples/stackdriver_simple', 'vendor/google/cloud/src/ErrorReporting/prepend.php'], + ['samples/stackdriver_wildcard', 'vendor/google/cloud/ErrorReporting/src/prepend.php'], + ['samples/stackdriver_dev', 'vendor/google/cloud/ErrorReporting/src/prepend.php'], + ]; + } + + /** + * @dataProvider invalidVersions + */ + public function testInvalidVersions($directory) + { + $dir = realpath(__DIR__ . '/' . $directory); + exec("cd $dir && composer install --ignore-platform-reqs -q 2>&1", $output, $retVal); + $this->assertEquals(0, $retVal, 'command failed with: ' . implode(';', $output)); + + exec("php stackdriver-files/enable_stackdriver_prepend.php -a $dir", $output, $retVal); + $this->assertNotEquals(0, $retVal, 'command: ' . implode(';', $output) . ' should have failed.'); + } + + public function invalidVersions() + { return [ - ['samples/stackdriver_individual'] + ['samples/stackdriver_no_google_cloud'], + ['samples/stackdriver_old_er'], + ['samples/stackdriver_old_google_cloud'], + ['samples/stackdriver_old_logging'] ]; } } diff --git a/php-base/tests/bootstrap.php b/php-base/tests/bootstrap.php index b3d9bbc7..6c8c4f51 100644 --- a/php-base/tests/bootstrap.php +++ b/php-base/tests/bootstrap.php @@ -1 +1,3 @@ Date: Wed, 18 Apr 2018 16:57:56 -0700 Subject: [PATCH 6/8] Fix phpcs --- php-base/build-scripts/src/DetectPhpVersion.php | 2 +- php-base/tests/StackdriverIntegrationTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/php-base/build-scripts/src/DetectPhpVersion.php b/php-base/build-scripts/src/DetectPhpVersion.php index b641538f..2400e750 100644 --- a/php-base/build-scripts/src/DetectPhpVersion.php +++ b/php-base/build-scripts/src/DetectPhpVersion.php @@ -77,4 +77,4 @@ private static function detectAvailableVersions() trim(file_get_contents('/opt/php56_version')) ]; } -} \ No newline at end of file +} diff --git a/php-base/tests/StackdriverIntegrationTest.php b/php-base/tests/StackdriverIntegrationTest.php index 7fbe76d5..172a7764 100644 --- a/php-base/tests/StackdriverIntegrationTest.php +++ b/php-base/tests/StackdriverIntegrationTest.php @@ -49,7 +49,8 @@ public function testValidVersions($directory, $expectedFile) $this->assertStringEndsWith($expectedFile, $output); } - public function validVersions(){ + public function validVersions() + { return [ ['samples/stackdriver_individual', 'vendor/google/cloud-error-reporting/prepend.php'], ['samples/stackdriver_simple', 'vendor/google/cloud/src/ErrorReporting/prepend.php'], From 15c60b12a362675537d51f277866fbd2c4109ab5 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 18 Apr 2018 17:22:35 -0700 Subject: [PATCH 7/8] Move no_composer test to php-base --- builder/gen-dockerfile/tests/GenFilesCommandTest.php | 11 ----------- .../stackdriver-files/enable_stackdriver_prepend.php | 5 ++++- php-base/tests/StackdriverIntegrationTest.php | 9 +++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/builder/gen-dockerfile/tests/GenFilesCommandTest.php b/builder/gen-dockerfile/tests/GenFilesCommandTest.php index dfaafd56..7bff7e02 100644 --- a/builder/gen-dockerfile/tests/GenFilesCommandTest.php +++ b/builder/gen-dockerfile/tests/GenFilesCommandTest.php @@ -187,17 +187,6 @@ public function dataProvider() [], '\\Google\\Cloud\\Runtimes\\Builder\\Exception\\InvalidComposerFlagsException' ], - [ - // stackdriver no composer.json - __DIR__ . '/test_data/stackdriver_no_composer', - null, - '', - '/app/web', - 'added by the php runtime builder', - 'gcr.io/google-appengine/php72:latest', - [], - '\\Google\\Cloud\\Runtimes\\Builder\\Exception\\GoogleCloudVersionException' - ], [ // PHP 5.6 __DIR__ . '/test_data/php56', diff --git a/php-base/stackdriver-files/enable_stackdriver_prepend.php b/php-base/stackdriver-files/enable_stackdriver_prepend.php index d552ade4..1043f8cb 100644 --- a/php-base/stackdriver-files/enable_stackdriver_prepend.php +++ b/php-base/stackdriver-files/enable_stackdriver_prepend.php @@ -20,7 +20,10 @@ 'o' => 'php://stdout' ]; -require_once $options['a'] . '/vendor/autoload.php'; +$autoload = $options['a'] . '/vendor/autoload.php'; +if (file_exists($autoload)) { + require_once $autoload; +} require_once __DIR__ . '/stackdriver_integration.php'; $integration = new StackdriverIntegration(); diff --git a/php-base/tests/StackdriverIntegrationTest.php b/php-base/tests/StackdriverIntegrationTest.php index 172a7764..12c93774 100644 --- a/php-base/tests/StackdriverIntegrationTest.php +++ b/php-base/tests/StackdriverIntegrationTest.php @@ -70,6 +70,7 @@ public function testInvalidVersions($directory) exec("php stackdriver-files/enable_stackdriver_prepend.php -a $dir", $output, $retVal); $this->assertNotEquals(0, $retVal, 'command: ' . implode(';', $output) . ' should have failed.'); + $this->assertContains('You must include', $output[0]); } public function invalidVersions() @@ -81,4 +82,12 @@ public function invalidVersions() ['samples/stackdriver_old_logging'] ]; } + + public function testNoComposer() + { + $dir = realpath(__DIR__ . '/samples/no_composer'); + exec("php stackdriver-files/enable_stackdriver_prepend.php -a $dir", $output, $retVal); + $this->assertNotEquals(0, $retVal, 'command: ' . implode(';', $output) . ' should have failed.'); + $this->assertContains('You must include', $output[0]); + } } From 15610e47882d583443d48393e983dd189eb70773 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Thu, 19 Apr 2018 11:10:15 -0700 Subject: [PATCH 8/8] Throw and log error if we cannot open or write the php.ini config --- php-base/stackdriver-files/enable_stackdriver_prepend.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/php-base/stackdriver-files/enable_stackdriver_prepend.php b/php-base/stackdriver-files/enable_stackdriver_prepend.php index 1043f8cb..3f72838d 100644 --- a/php-base/stackdriver-files/enable_stackdriver_prepend.php +++ b/php-base/stackdriver-files/enable_stackdriver_prepend.php @@ -31,8 +31,14 @@ try { $location = $integration->prependFileLocation(); $fp = fopen($options['o'], 'w'); + if ($fp === false) { + throw new RuntimeException(sprintf('Failed opening file %s for writing.', $options['o'])); + } try { - fwrite($fp, 'auto_prepend_file=' . $location . PHP_EOL); + $ret = fwrite($fp, 'auto_prepend_file=' . $location . PHP_EOL); + if ($ret === false) { + throw new RuntimeException(sprintf('Failed writing to file: %s', $options['o'])); + } } finally { fclose($fp); }