Skip to content

Commit

Permalink
Add tests to clarify how/when config is applied
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Apr 20, 2022
1 parent c7e261a commit 80019bf
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions tests/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 80019bf

Please sign in to comment.