|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace OpenFeature\Test\unit; |
| 6 | + |
| 7 | +use InvalidArgumentException; |
| 8 | +use OpenFeature\implementation\flags\EvaluationContext; |
| 9 | +use OpenFeature\implementation\multiprovider\strategy\StrategyEvaluationContext; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +class StrategyEvaluationContextTest extends TestCase |
| 13 | +{ |
| 14 | + public function testValidBooleanFlagType(): void |
| 15 | + { |
| 16 | + $context = new StrategyEvaluationContext('flag-key', 'boolean', true, new EvaluationContext()); |
| 17 | + $this->assertEquals('flag-key', $context->getFlagKey()); |
| 18 | + $this->assertEquals('boolean', $context->getFlagType()); |
| 19 | + $this->assertTrue($context->getDefaultValue()); |
| 20 | + $this->assertInstanceOf(EvaluationContext::class, $context->getEvaluationContext()); |
| 21 | + } |
| 22 | + |
| 23 | + public function testValidStringFlagType(): void |
| 24 | + { |
| 25 | + $context = new StrategyEvaluationContext('flag-key', 'string', 'default', new EvaluationContext()); |
| 26 | + $this->assertEquals('string', $context->getFlagType()); |
| 27 | + $this->assertEquals('default', $context->getDefaultValue()); |
| 28 | + } |
| 29 | + |
| 30 | + public function testValidIntegerFlagType(): void |
| 31 | + { |
| 32 | + $context = new StrategyEvaluationContext('flag-key', 'integer', 42, new EvaluationContext()); |
| 33 | + $this->assertEquals('integer', $context->getFlagType()); |
| 34 | + $this->assertEquals(42, $context->getDefaultValue()); |
| 35 | + } |
| 36 | + |
| 37 | + public function testValidFloatFlagType(): void |
| 38 | + { |
| 39 | + $context = new StrategyEvaluationContext('flag-key', 'float', 3.14, new EvaluationContext()); |
| 40 | + $this->assertEquals('float', $context->getFlagType()); |
| 41 | + $this->assertEquals(3.14, $context->getDefaultValue()); |
| 42 | + } |
| 43 | + |
| 44 | + public function testValidObjectFlagType(): void |
| 45 | + { |
| 46 | + $context = new StrategyEvaluationContext('flag-key', 'object', ['key' => 'value'], new EvaluationContext()); |
| 47 | + $this->assertEquals('object', $context->getFlagType()); |
| 48 | + $this->assertEquals(['key' => 'value'], $context->getDefaultValue()); |
| 49 | + } |
| 50 | + |
| 51 | + public function testInvalidBooleanDefaultValueThrows(): void |
| 52 | + { |
| 53 | + $this->expectException(InvalidArgumentException::class); |
| 54 | + new StrategyEvaluationContext('flag-key', 'boolean', 'not-a-bool', new EvaluationContext()); |
| 55 | + } |
| 56 | + |
| 57 | + public function testInvalidStringDefaultValueThrows(): void |
| 58 | + { |
| 59 | + $this->expectException(InvalidArgumentException::class); |
| 60 | + new StrategyEvaluationContext('flag-key', 'string', 123, new EvaluationContext()); |
| 61 | + } |
| 62 | + |
| 63 | + public function testInvalidIntegerDefaultValueThrows(): void |
| 64 | + { |
| 65 | + $this->expectException(InvalidArgumentException::class); |
| 66 | + new StrategyEvaluationContext('flag-key', 'integer', 'not-an-int', new EvaluationContext()); |
| 67 | + } |
| 68 | + |
| 69 | + public function testInvalidFloatDefaultValueThrows(): void |
| 70 | + { |
| 71 | + $this->expectException(InvalidArgumentException::class); |
| 72 | + new StrategyEvaluationContext('flag-key', 'float', 'not-a-float', new EvaluationContext()); |
| 73 | + } |
| 74 | + |
| 75 | + public function testInvalidObjectDefaultValueThrows(): void |
| 76 | + { |
| 77 | + $this->expectException(InvalidArgumentException::class); |
| 78 | + new StrategyEvaluationContext('flag-key', 'object', 'not-an-array', new EvaluationContext()); |
| 79 | + } |
| 80 | + |
| 81 | + public function testUnknownFlagTypeThrows(): void |
| 82 | + { |
| 83 | + $this->expectException(InvalidArgumentException::class); |
| 84 | + new StrategyEvaluationContext('flag-key', 'unknown-type', 'value', new EvaluationContext()); |
| 85 | + } |
| 86 | +} |
0 commit comments