Skip to content

Commit

Permalink
fix DcaUtilTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ericges committed Mar 25, 2024
1 parent 40be021 commit ab18c1f
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions tests/Util/Dca/DcaUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,28 @@ public function testGetDcaFields()

public function testExecuteCallback()
{
$instance = $this->getTestInstance();
$controllerAdapter = $this->mockAdapter(['importStatic']);
$controllerAdapter->method('importStatic')->willReturn($this);

$this->assertSame('ham', $instance->executeCallback(function () {
return 'ham';
}));
$contaoFramework = $this->mockContaoFramework([
Controller::class => $controllerAdapter,
]);

$instance = $this->getTestInstance([
'contaoFramework' => $contaoFramework,
]);

$this->assertSame('ham', $instance->executeCallback(function () { return 'ham'; }));
$this->assertSame('spam', $instance->executeCallback(function ($value) {
return $value;
}, 'spam'));

$this->assertSame('spam_ham', $instance->executeCallback(
[\HeimrichHannot\UtilsBundle\Util\StringUtil::class, 'camelCaseToSnake'], 'spamHam')
);
$this->assertSame('ham', $instance->executeCallback([static::class, 'thisReturnsHam']));

$this->assertNull($instance->executeCallback(null));
$this->assertNull($instance->executeCallback(['toFewArguments']));
$this->assertNull($instance->executeCallback([static::class, 'thisIsNotCallable']));
$this->assertNull($instance->executeCallback(['\This\Is\Unheard\Of', 'notCallable']));
$this->assertNull($instance->executeCallback(['toFewArguments']));

try {
$instance->executeCallback([static::class, 'thisThrowsAnError']);
Expand All @@ -167,8 +171,16 @@ public function testExecuteCallback()
}
}

public function thisThrowsAnError()
/**
* @throws Exception
*/
public function thisThrowsAnError(): void
{
throw new Exception('I was thrown on purpose');
}

public function thisReturnsHam(): string
{
return 'ham';
}
}

0 comments on commit ab18c1f

Please sign in to comment.