From b683f886ad7f2d0c763ba6d95babd6350469fa01 Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Mon, 25 Mar 2024 17:49:21 +0100 Subject: [PATCH] add OptionsFactoryTest.php --- tests/Options/OptionsFactoryTest.php | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/Options/OptionsFactoryTest.php diff --git a/tests/Options/OptionsFactoryTest.php b/tests/Options/OptionsFactoryTest.php new file mode 100644 index 00000000..ba7f0473 --- /dev/null +++ b/tests/Options/OptionsFactoryTest.php @@ -0,0 +1,59 @@ +set('foo', 'foo'); + $options->bar = 'bar'; + + $this->assertTrue($options->has('foo')); + $this->assertTrue($options->has('bar')); + $this->assertFalse($options->has('baz')); + + $this->assertSame('foo', $options->get('foo')); + $this->assertSame('bar', $options->get('bar')); + $this->assertNull($options->get('baz')); + $this->assertSame('foobar', $options->get('baz', 'foobar')); + $this->assertSame('foo', $options->foo); + $this->assertSame('bar', $options->bar); + $this->assertNull($options->baz); + + $options->foo = 'bar'; + $options->del('bar'); + + $this->assertSame('bar', $options->foo); + $this->assertFalse($options->has('bar')); + } + + public function testOptionsFactoryInheritance() + { + $options = new class extends OptionsFactory { + public string $foo = 'foo'; + }; + + $this->assertTrue($options->has('foo')); + $this->assertSame('foo', $options->foo); + $this->assertSame('foo', $options->get('foo')); + + $options->set('foo', 'baz'); + $options->set('bar', 'bar'); + + $this->assertTrue($options->has('foo')); + $this->assertTrue($options->has('bar')); + $this->assertSame('baz', $options->foo); + $this->assertSame('bar', $options->bar); + + $options->del('foo'); + $options->del('bar'); + + $this->assertFalse($options->has('foo')); + $this->assertFalse($options->has('bar')); + } +} \ No newline at end of file