From 80019bfa0937843b154961efda299b830ba501e3 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Wed, 20 Apr 2022 14:26:33 +1200 Subject: [PATCH] Add tests to clarify how/when config is applied --- tests/GeneratorTest.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php index 628adf01a..1b718a1c6 100644 --- a/tests/GeneratorTest.php +++ b/tests/GeneratorTest.php @@ -116,20 +116,34 @@ public function testRemoveProcessorNotFound(): void }); } - public function testConfig() + protected function assertOperationIdHash(Generator $generator, bool $expected) { - $assertOperationId = function (Generator $generator, bool $expected) { - foreach ($generator->getProcessors() as $processor) { - if ($processor instanceof OperationId) { - $this->assertEquals($expected, $processor->isHash()); - } + foreach ($generator->getProcessors() as $processor) { + if ($processor instanceof OperationId) { + $this->assertEquals($expected, $processor->isHash()); } - }; + } + } + public function testConfig() + { $generator = new Generator(); - $assertOperationId($generator, true); + $this->assertOperationIdHash($generator, true); $generator->setConfig(['operationId' => ['hash' => false]]); - $assertOperationId($generator, false); + $this->assertOperationIdHash($generator, false); + } + + public function testCallableProcessor() + { + $generator = new Generator(); + // not the default + $operationId = new OperationId(false); + $generator->addProcessor(function (Analysis $analysis) use ($operationId) { + $operationId($analysis); + }); + + $this->assertOperationIdHash($generator, true); + $this->assertFalse($operationId->isHash()); } }