Skip to content

Commit b8422e9

Browse files
authored
Don't mock what you don't own (#66)
* Do not rely on mock for Doctrine manager nor registry * Do not rely on mock for event dispatcher * Do not rely on mock for symfony normalizer nor denormalizer * Remove phpspec/prophecy-phpunit dev dependency from packages that are no longer using it
1 parent ca99989 commit b8422e9

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

tests/RunJobCommandTest.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPUnit\Framework\TestCase;
99
use Prophecy\Argument;
1010
use Prophecy\PhpUnit\ProphecyTrait;
11+
use Prophecy\Prophecy\ObjectProphecy;
1112
use Psr\EventDispatcher\EventDispatcherInterface;
1213
use Symfony\Component\Console\Output\OutputInterface;
1314
use Symfony\Component\Console\Tester\CommandTester;
@@ -29,10 +30,13 @@ class RunJobCommandTest extends TestCase
2930

3031
private const JOBNAME = 'testing';
3132

33+
private JobInterface|ObjectProphecy $job;
34+
private JobExecutionAccessor $accessor;
35+
private JobExecutor $executor;
36+
3237
protected function setUp(): void
3338
{
3439
$this->job = $this->prophesize(JobInterface::class);
35-
$this->dispatcher = $this->prophesize(EventDispatcherInterface::class);
3640

3741
$this->accessor = new JobExecutionAccessor(
3842
new JobExecutionFactory(new UniqidJobExecutionIdGenerator()),
@@ -41,24 +45,10 @@ protected function setUp(): void
4145
$this->executor = new JobExecutor(
4246
JobRegistry::fromJobArray([self::JOBNAME => $this->job->reveal()]),
4347
new InMemoryJobExecutionStorage(),
44-
$this->dispatcher->reveal()
48+
null
4549
);
4650
}
4751

48-
private function execute(string $configuration = null, int $verbosity = OutputInterface::VERBOSITY_NORMAL): array
49-
{
50-
$options = ['verbosity' => $verbosity];
51-
$input = ['job' => self::JOBNAME];
52-
if ($configuration !== null) {
53-
$input['configuration'] = $configuration;
54-
}
55-
56-
$tester = new CommandTester(new RunJobCommand($this->accessor, $this->executor));
57-
$tester->execute($input, $options);
58-
59-
return [$tester->getStatusCode(), $tester->getDisplay()];
60-
}
61-
6252
public function testRunWithMalformedConfiguration(): void
6353
{
6454
$this->expectException(JsonException::class);
@@ -164,4 +154,18 @@ public function verbosity(): \Generator
164154
yield 'very verbose' => [OutputInterface::VERBOSITY_VERY_VERBOSE];
165155
yield 'debug' => [OutputInterface::VERBOSITY_DEBUG];
166156
}
157+
158+
private function execute(string $configuration = null, int $verbosity = OutputInterface::VERBOSITY_NORMAL): array
159+
{
160+
$options = ['verbosity' => $verbosity];
161+
$input = ['job' => self::JOBNAME];
162+
if ($configuration !== null) {
163+
$input['configuration'] = $configuration;
164+
}
165+
166+
$tester = new CommandTester(new RunJobCommand($this->accessor, $this->executor));
167+
$tester->execute($input, $options);
168+
169+
return [$tester->getStatusCode(), $tester->getDisplay()];
170+
}
167171
}

0 commit comments

Comments
 (0)