Skip to content

Commit

Permalink
Fix config controller; Use constants
Browse files Browse the repository at this point in the history
  • Loading branch information
karniv00l committed Jul 24, 2020
1 parent 94532c1 commit 9312c92
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Command/CreateAdminCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Buddy\Repman\Message\Admin\ChangeConfig;
use Buddy\Repman\Message\User\CreateUser;
use Buddy\Repman\Service\Config;
use Buddy\Repman\Service\Telemetry;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if ($this->getHelper('question')->ask($input, $output, $question) === true) {
$this->bus->dispatch(new ChangeConfig([
'telemetry' => 'enabled',
Config::TELEMETRY => Config::TELEMETRY_ENABLED,
]));
}

Expand Down
4 changes: 3 additions & 1 deletion src/Controller/Admin/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function toggleTelemetry(Request $request): Response
{
$this->telemetry->generateInstanceId();
$this->dispatchMessage(new ChangeConfig([
'telemetry' => $request->isMethod(Request::METHOD_POST) ? 'enable' : 'disable',
Config::TELEMETRY => $request->isMethod(Request::METHOD_POST)
? Config::TELEMETRY_ENABLED
: Config::TELEMETRY_DISABLED,
]));

return $this->redirectToRoute('index');
Expand Down
7 changes: 4 additions & 3 deletions src/Form/Type/Admin/ConfigType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Buddy\Repman\Form\Type\Admin;

use Buddy\Repman\Service\Config;
use Buddy\Repman\Service\Telemetry;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
Expand Down Expand Up @@ -53,10 +54,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'data-style' => 'btn-secondary',
],
])
->add('telemetry', ChoiceType::class, [
->add(Config::TELEMETRY, ChoiceType::class, [
'choices' => [
'enabled' => 'enabled',
'disabled' => 'disabled',
Config::TELEMETRY_ENABLED => Config::TELEMETRY_ENABLED,
Config::TELEMETRY_DISABLED => Config::TELEMETRY_DISABLED,
],
'help' => "Enable collecting and sending anonymous usage data (<a href=\"{$this->telemetry->docsUrl()}\" target=\"_blank\" rel=\"noopener noreferrer\">more info</a>)",
'attr' => [
Expand Down
5 changes: 4 additions & 1 deletion src/Service/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
final class Config
{
const CACHE_KEY = 'values';
const TELEMETRY = 'telemetry';
const TELEMETRY_ENABLED = 'enabled';
const TELEMETRY_DISABLED = 'disabled';

private ConfigQuery $configQuery;
private CacheInterface $cache;
Expand Down Expand Up @@ -54,7 +57,7 @@ public function userRegistrationEnabled(): bool

public function telemetryEnabled(): bool
{
return $this->get('telemetry') === 'enabled';
return $this->get('telemetry') === self::TELEMETRY_ENABLED;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Functional/Command/SendTelemetryCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Buddy\Repman\Tests\Functional\Command;

use Buddy\Repman\Command\SendTelemetryCommand;
use Buddy\Repman\Service\Config;
use Buddy\Repman\Service\Telemetry\TelemetryEndpoint;
use Buddy\Repman\Tests\Functional\FunctionalTestCase;
use Ramsey\Uuid\Uuid;
Expand All @@ -26,7 +27,7 @@ public function testSendTelemetryWithoutInstanceIdFile(): void
public function testSendTelemetryWithTelemetryDisabled(): void
{
$this->generateInstanceIdFile();
$this->fixtures->changeConfig('telemetry', 'disabled');
$this->fixtures->changeConfig(Config::TELEMETRY, Config::TELEMETRY_DISABLED);

$commandTester = new CommandTester(
$this->container()->get(SendTelemetryCommand::class)
Expand All @@ -40,7 +41,7 @@ public function testSendTelemetry(): void
$this->fixtures->createPackage(Uuid::uuid4()->toString());

$this->generateInstanceIdFile();
$this->fixtures->changeConfig('telemetry', 'enabled');
$this->fixtures->changeConfig(Config::TELEMETRY, Config::TELEMETRY_ENABLED);

$commandTester = new CommandTester(
$this->container()->get(SendTelemetryCommand::class)
Expand Down

0 comments on commit 9312c92

Please sign in to comment.