Refactor to a repository
This commit is contained in:
parent
eae47a9c87
commit
cdd7a466d2
|
@ -0,0 +1,4 @@
|
|||
services:
|
||||
Drupal\opdavies_talks\Controller\TalksPageController:
|
||||
autowire: true
|
||||
Drupal\opdavies_talks\Repository\TalkNodeRepository: []
|
|
@ -5,13 +5,17 @@ declare(strict_types=1);
|
|||
namespace Drupal\opdavies_talks\Controller;
|
||||
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\opdavies_talks\Repository\TalkNodeRepository;
|
||||
|
||||
final class TalksPageController {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
public function __construct(private TalkNodeRepository $talkRepository) {
|
||||
}
|
||||
|
||||
public function __invoke(): array {
|
||||
$talkCount = 2;
|
||||
$talkCount = $this->talkRepository->getCount();
|
||||
|
||||
return ['#markup' => $this->t('<span data-talk-count>:count talks</span>', [':count' => $talkCount])];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opdavies_talks\Repository;
|
||||
|
||||
final class TalkNodeRepository {
|
||||
|
||||
public function getCount(): int {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\opdavies_talks\Kernel\Repository;
|
||||
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\opdavies_talks\Repository\TalkNodeRepository;
|
||||
|
||||
final class TalkNodeRepositoryTest extends EntityKernelTestBase {
|
||||
|
||||
protected static $modules = ['opdavies_talks'];
|
||||
|
||||
public function test_it_returns_a_count(): void {
|
||||
$talkRepository = $this->container->get(TalkNodeRepository::class);
|
||||
|
||||
self::assertSame(2, $talkRepository->getCount());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue