Namespace
Drupal\testing_example\Controller
File
-
modules/testing_example/src/Controller/ContrivedController.php
View source
<?php
namespace Drupal\testing_example\Controller;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ContrivedController implements ContainerInjectionInterface {
use StringTranslationTrait;
public static function create(ContainerInterface $container) {
return new static($container->get('string_translation'));
}
public function __construct(TranslationInterface $translation) {
$this->setStringTranslation($translation);
}
public function displayAddedNumbers($first, $second) {
return [
'#markup' => '<p>' . $this->handCount($first, $second) . '</p>',
];
}
protected function handCount($first, $second) {
$sum = abs($this->add((int) $first, (int) $second));
if ($sum <= 5) {
$message = $this->t('I can count these on one hand.');
}
elseif ($sum <= 10) {
$message = $this->t('I need two hands to count these.');
}
else {
$message = $this->t("That's just too many numbers to count.");
}
return $message;
}
protected function add($first, $second) {
return $first + $second;
}
}
Classes
| Title |
Deprecated |
Summary |
| ContrivedController |
|
A highly-contrived controller class used to demonstrate unit testing. |