|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2024 SURFnet B.V. |
| 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 OpenConext\MonitorBundle\Tests\Value; |
| 20 | + |
| 21 | +use OpenConext\MonitorBundle\Value\BuildEnvVars; |
| 22 | +use OpenConext\MonitorBundle\Value\BuildEnvVarsFactory; |
| 23 | +use OpenConext\MonitorBundle\Value\BuildInformation; |
| 24 | +use PHPUnit\Framework\TestCase; |
| 25 | + |
| 26 | +class EnvVarFactoryTest extends TestCase |
| 27 | +{ |
| 28 | + public function test_happy_flow() |
| 29 | + { |
| 30 | + $expectedSemverVersion = '1.1.0'; |
| 31 | + $expectedRevision = 'e3f5a1f0'; |
| 32 | + $expectedDate = '2024-01-01'; |
| 33 | + $envVarVO = BuildEnvVarsFactory::buildFrom($expectedSemverVersion, $expectedRevision, $expectedDate); |
| 34 | + $this->assertInstanceOf(BuildInformation::class, $envVarVO); |
| 35 | + $this->assertInstanceOf(BuildEnvVars::class, $envVarVO); |
| 36 | + $this->assertTrue($envVarVO->hasRevision() && $envVarVO->hasVersion() && $envVarVO->hasCommitDate()); |
| 37 | + $this->assertEquals($expectedSemverVersion, $envVarVO->getVersion()); |
| 38 | + $this->assertEquals($expectedRevision, $envVarVO->getRevision()); |
| 39 | + $this->assertEquals($expectedDate, $envVarVO->getCommitDate()); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @dataProvider buildValidVariants |
| 44 | + */ |
| 45 | + public function test_happy_flow_variants( |
| 46 | + string $expectedSemverVersion, |
| 47 | + string $expectedRevision, |
| 48 | + ?string $expectedDate = null, |
| 49 | + ) { |
| 50 | + $envVarVO = BuildEnvVarsFactory::buildFrom($expectedSemverVersion, $expectedRevision, $expectedDate); |
| 51 | + $this->assertInstanceOf(BuildInformation::class, $envVarVO); |
| 52 | + $this->assertInstanceOf(BuildEnvVars::class, $envVarVO); |
| 53 | + $this->assertEquals($expectedSemverVersion, $envVarVO->getVersion()); |
| 54 | + $this->assertEquals($expectedRevision, $envVarVO->getRevision()); |
| 55 | + $this->assertEquals($expectedDate, $envVarVO->getCommitDate()); |
| 56 | + } |
| 57 | + |
| 58 | + public function buildValidVariants() |
| 59 | + { |
| 60 | + return [ |
| 61 | + 'all set' => ['1.1.0', 'e97bbfc3', '2000-01-01'], |
| 62 | + 'all set, long date' => ['1.1.0', 'e97bbfc3', '2000-01-01 00:00:00'], |
| 63 | + 'no date' => ['1.1.0', 'e97bbfc3'], |
| 64 | + 'full commit hash' => ['1.1.0', 'e97bbfc39653cb5541d453e704c64a7fab4f5b1'], |
| 65 | + 'non-semver hash' => ['beta-1', 'e97bbfc39653cb5541d453e704c64a7fab4f5b1'], |
| 66 | + ]; |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments