Skip to content

Commit

Permalink
Minor refactor to remove references to the local "output" property an…
Browse files Browse the repository at this point in the history
…d "getOutput()" method, both of which are used in the parent class.
  • Loading branch information
ultrono committed Jun 14, 2020
1 parent 0fd9ccf commit c24c95d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
28 changes: 14 additions & 14 deletions src/Console/Commands/CheckQueueIsRunning.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class CheckQueueIsRunning extends Command
protected $description = 'Crudely, check if the Redis queue worker is running';

/** @var string */
protected $output = '';
protected $commandOutput = '';

/** @var int */
protected $processCount = 0;

/** @var null */
protected $process = null;
/** @var \Symfony\Component\Process\Process|null */
protected $processObject = null;

/**
* Create a new command instance.
Expand All @@ -59,12 +59,12 @@ public function handle()
// the number of expected processes
$expectedProcessCount = $options['processes'] ?? 1;

$process = $this->getProcess();
$process = $this->getProcessObject();
$process->run();

$this->output = $process->getOutput();
$this->commandOutput = $process->getOutput();

foreach (explode(PHP_EOL, $this->output) as $line) {
foreach (explode(PHP_EOL, $this->commandOutput) as $line) {
if (Str::contains($line, $expectedOutput)) {
$this->processCount++;
}
Expand All @@ -74,36 +74,36 @@ public function handle()
// The process count differing to the expected count could
// indicate issues too.
if ($this->processCount < $expectedProcessCount) {
event(new QueueCheckFailed($this->output ?? ''));
event(new QueueCheckFailed($this->getProcessOutput() ?? ''));
}
}

/**
* @return \Symfony\Component\Process\Process|mixed
*/
public function getProcess()
public function getProcessObject()
{
if (null === $this->process) {
return new Process(['ps', 'aux']);
if (null === $this->processObject) {
return $this->processObject = new Process(['ps', 'aux']);
}

return $this->process;
return $this->processObject;
}

/**
* @return string
*/
public function getOutput(): string
public function getProcessOutput(): string
{
return $this->output;
return $this->commandOutput;
}

/**
* @param null $process
*/
public function setProcess($process): void
{
$this->process = $process;
$this->processObject = $process;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Events/QueueCheckFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
class QueueCheckFailed
{
/** @var string */
public $output;
public $processOutput;

/**
* @param string|null $output
* @param string|null $processOutput
*/
public function __construct(?string $output)
public function __construct(?string $processOutput)
{
$this->output = $output;
$this->processOutput = $processOutput;
}

/**
* @return string|null
*/
public function getOutput(): ?string
{
return $this->output ?? null;
return $this->processOutput ?? null;
}
}
4 changes: 2 additions & 2 deletions tests/CheckQueueIsRunningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ public function it_determines_the_console_output()

$this->command->handle();

$this->assertEquals("abc123\nabc1234\n", $this->command->getOutput());
$this->assertEquals("abc123\nabc1234\n", $this->command->getProcessOutput());
}

/** @test */
public function it_fetches_the_process()
{
$this->command->handle();

$this->assertInstanceOf(Process::class, $this->command->getProcess());
$this->assertInstanceOf(Process::class, $this->command->getProcessObject());
}
}
4 changes: 4 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ protected function getPackageProviders($app): array
];
}

/**
* @param string $stub
* @return \Illuminate\Support\HigherOrderTapProxy|mixed|\Mockery\LegacyMockInterface|\Mockery\MockInterface
*/
public function getMockedObject(string $stub)
{
return tap(m::mock(Process::class), function ($mock) use ($stub) {
Expand Down

0 comments on commit c24c95d

Please sign in to comment.