|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2021 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\CloudFunctions\Tests; |
| 19 | + |
| 20 | +use Google\CloudFunctions\FunctionsFramework; |
| 21 | +use Google\CloudFunctions\FunctionsFrameworkTesting; |
| 22 | +use PHPUnit\Framework\TestCase; |
| 23 | +use Psr\Http\Message\ServerRequestInterface; |
| 24 | +use CloudEvents\V1\CloudEventInterface; |
| 25 | + |
| 26 | +/** |
| 27 | + * @group gcf-framework |
| 28 | + */ |
| 29 | +class FunctionsFrameworkTest extends TestCase |
| 30 | +{ |
| 31 | + public function testRegisterAndRetrieveHttpFunction(): void |
| 32 | + { |
| 33 | + $fn = function (ServerRequestInterface $request) { |
| 34 | + return "this is a test function"; |
| 35 | + }; |
| 36 | + |
| 37 | + FunctionsFramework::http('testFn', $fn); |
| 38 | + |
| 39 | + $this->assertEquals( |
| 40 | + $fn, |
| 41 | + FunctionsFrameworkTesting::getRegisteredFunction('testFn') |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + public function testRegisterAndRetrieveCloudEventFunction(): void |
| 46 | + { |
| 47 | + $fn = function (CloudEventInterface $event) { |
| 48 | + return "this is a test function"; |
| 49 | + }; |
| 50 | + |
| 51 | + FunctionsFramework::cloudEvent('testFn', $fn); |
| 52 | + |
| 53 | + $this->assertEquals( |
| 54 | + $fn, |
| 55 | + FunctionsFrameworkTesting::getRegisteredFunction('testFn') |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + public function testRetrieveNonexistantFunction(): void |
| 60 | + { |
| 61 | + $this->assertNull( |
| 62 | + FunctionsFrameworkTesting::getRegisteredFunction('thisDoesntExist') |
| 63 | + ); |
| 64 | + } |
| 65 | +} |
0 commit comments