public function testServicesAreRegistered() { $config = new Config(); $config->import(new BeanstalkServer('default', ['host' => '127.0.0.1', 'tube' => 'test'])); $config->import(new BeanstalkServer('other', ['host' => '127.0.0.1', 'port' => 1234, 'tube' => 'test'])); $servicesFactory = $this->createMock(ServicesFactory::class); $servicesFactory->expects($this->exactly(2))->method('registerService')->with($this->isInstanceOf(ClassServiceSpecs::class)); $app = $this->createMock(ApplicationInterface::class); $app->method('getConfig')->willReturn($config); $app->method('getServicesFactory')->willReturn($servicesFactory); (new BeanstalkPackage())->registerServices($app); }
public function testMergingBehaviour() { $config = new Config(); $config->import(new TestSingleValueDirectiveGroup('first', 'other value')); $this->assertCount(1, $config); $this->assertTrue($config->has(TestSingleValueDirectiveGroup::class . '.first')); $this->assertEquals('other value', $config->get(TestSingleValueDirectiveGroup::class . '.first')); $config->import(new TestSingleValueDirectiveGroup('second', 'stacked value')); $this->assertCount(2, $config); $this->assertTrue($config->has(TestSingleValueDirectiveGroup::class . '.second')); $this->assertEquals('stacked value', $config->get(TestSingleValueDirectiveGroup::class . '.second')); // override previously imported value (default behaviour for non-array values) $config->import(new TestSingleValueDirectiveGroup('second', 'overwriting value')); $this->assertCount(2, $config); $this->assertTrue($config->has(TestSingleValueDirectiveGroup::class . '.second')); // next import is ignored because overwriting ability has been denied to hte directive $config->import((new TestSingleValueDirectiveGroup('second', 'over overwriting value'))->setMergePolicy(MergePolicy::SKIP)); $this->assertEquals('overwriting value', $config->get(TestSingleValueDirectiveGroup::class . '.second')); // check that a Multiple Directive full content can be retrieved as subset $this->assertEquals(['first' => 'other value', 'second' => 'overwriting value'], $config->subset(TestSingleValueDirectiveGroup::class)->toArray()); // test default merging behaviour for array values $config->import(new TestSingleValueDirectiveGroup('third', ['x' => 'y', 'z'])); $config->import(new TestSingleValueDirectiveGroup('third', ['x' => 'a', 'b'])); $config->import(new TestSingleValueDirectiveGroup('third', ['c' => 'd'])); $config->import(new TestSingleValueDirectiveGroup('third', 'e')); $this->assertEquals(['x' => 'a', 'z', 'b', 'c' => 'd', 'e'], $config->get(TestSingleValueDirectiveGroup::class . '.third')); }
public function testOverwritingBehaviour() { $config = new Config(); $config->import(new TestStackedValuesDirective('other value')); $this->assertCount(1, $config); $this->assertTrue($config->has(TestStackedValuesDirective::class)); $this->assertEquals(['other value'], $config->get(TestStackedValuesDirective::class)); // this import will stack the second value, because stacking is the default behaviour for StackedValuesDirective $config->import(new TestStackedValuesDirective('stacked value')); $this->assertCount(1, $config); $this->assertTrue($config->has(TestStackedValuesDirective::class)); $this->assertEquals(['other value', 'stacked value'], $config->get(TestStackedValuesDirective::class)); // next import is ignored because overwriting ability has been denied to the directive $config->import((new TestStackedValuesDirective('overwriting value'))->setMergePolicy(MergePolicy::REPLACE)); $this->assertCount(1, $config); $this->assertTrue($config->has(TestStackedValuesDirective::class)); $this->assertEquals(['overwriting value'], $config->get(TestStackedValuesDirective::class)); }
public function testMergingBehaviour() { $config = new Config(); $config->import(new TestSingleValueDirective('other value')); $this->assertCount(1, $config); $this->assertTrue($config->has(TestSingleValueDirective::class)); $this->assertEquals('other value', $config->get(TestSingleValueDirective::class)); // this import will override previous one, because overwriting is allowed by default // on scalar directives $config->import(new TestSingleValueDirective('overwriting value')); // next import is ignored because overwriting ability has been denied to hte directive $config->import((new TestSingleValueDirective('ignored value'))->setMergePolicy(MergePolicy::SKIP)); $this->assertCount(1, $config); $this->assertTrue($config->has(TestSingleValueDirective::class)); $this->assertEquals('overwriting value', $config->get(TestSingleValueDirective::class)); // next import is ignored because overwriting ability has been denied to hte directive $config->import((new TestSingleValueDirective('combined value'))->setMergePolicy(MergePolicy::COMBINE)); $this->assertEquals(['overwriting value', 'combined value'], $config->get(TestSingleValueDirective::class)); }