Skip to content

Commit

Permalink
add OptionsFactoryTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ericges committed Mar 25, 2024
1 parent ab18c1f commit b683f88
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/Options/OptionsFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Options;

use Contao\TestCase\ContaoTestCase;
use HeimrichHannot\UtilsBundle\Options\OptionsFactory;

class OptionsFactoryTest extends ContaoTestCase
{
public function testOptionsFactory()
{
$options = new OptionsFactory();
$options->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'));
}
}

0 comments on commit b683f88

Please sign in to comment.