CallbackTest.php in Drupal 8
File
core/modules/migrate/tests/src/Unit/process/CallbackTest.php
View source
<?php
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\migrate\Plugin\migrate\process\Callback;
class CallbackTest extends MigrateProcessTestCase {
public function testCallback($callable) {
$configuration = [
'callable' => $callable,
];
$this->plugin = new Callback($configuration, 'map', []);
$value = $this->plugin
->transform('FooBar', $this->migrateExecutable, $this->row, 'destination_property');
$this
->assertSame('foobar', $value);
}
public function providerCallback() {
return [
'function' => [
'strtolower',
],
'class method' => [
[
self::class,
'strtolower',
],
],
];
}
public function testCallbackExceptions($message, $configuration) {
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage($message);
$this->plugin = new Callback($configuration, 'map', []);
}
public function providerCallbackExceptions() {
return [
'not set' => [
'message' => 'The "callable" must be set.',
'configuration' => [],
],
'invalid method' => [
'message' => 'The "callable" must be a valid function or method.',
'configuration' => [
'callable' => 'nonexistent_callable',
],
],
];
}
public static function strToLower($string) {
return mb_strtolower($string);
}
}