Skip to content

Commit 21507bc

Browse files
committed
switch to pestphp
1 parent e2f5d3f commit 21507bc

21 files changed

Lines changed: 1789 additions & 3295 deletions

Tests/Command/BaseCommandTest.php

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
<?php
22

3-
namespace OldSound\RabbitMqBundle\Tests\Command;
4-
5-
use PHPUnit\Framework\TestCase;
6-
7-
abstract class BaseCommandTest extends TestCase
8-
{
9-
protected $application;
10-
protected $definition;
11-
protected $helperSet;
12-
protected $command;
13-
14-
protected function setUp(): void
15-
{
16-
$this->application = $this->getMockBuilder('Symfony\\Component\\Console\\Application')
17-
->disableOriginalConstructor()
18-
->getMock();
19-
$this->definition = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputDefinition')
20-
->disableOriginalConstructor()
21-
->getMock();
22-
$this->helperSet = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\HelperSet')->getMock();
23-
24-
$this->application->expects($this->any())
25-
->method('getDefinition')
26-
->will($this->returnValue($this->definition));
27-
$this->definition->expects($this->any())
28-
->method('getArguments')
29-
->will($this->returnValue([]));
30-
}
31-
}
3+
// This file previously held an abstract BaseCommandTest class.
4+
// In Pest, shared setup is handled via beforeEach() in each test file directly,
5+
// since PHPUnit's protected getMockBuilder() cannot be called from global scope.
Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,45 @@
11
<?php
22

3-
namespace OldSound\RabbitMqBundle\Tests\Command;
4-
53
use OldSound\RabbitMqBundle\Command\ConsumerCommand;
4+
use Symfony\Component\Console\Application;
5+
use Symfony\Component\Console\Helper\HelperSet;
6+
use Symfony\Component\Console\Input\InputDefinition;
67
use Symfony\Component\Console\Input\InputOption;
78

8-
class ConsumerCommandTest extends BaseCommandTest
9-
{
10-
protected function setUp(): void
11-
{
12-
parent::setUp();
13-
$this->definition->expects($this->any())
14-
->method('getOptions')
15-
->will($this->returnValue([
16-
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
17-
new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'),
18-
new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'),
19-
]));
20-
$this->application->expects($this->once())
21-
->method('getHelperSet')
22-
->will($this->returnValue($this->helperSet));
23-
24-
$this->command = new ConsumerCommand();
25-
$this->command->setApplication($this->application);
26-
}
27-
28-
/**
29-
* testInputsDefinitionCommand
30-
*/
31-
public function testInputsDefinitionCommand()
32-
{
33-
$definition = $this->command->getDefinition();
34-
// check argument
35-
$this->assertTrue($definition->hasArgument('name'));
36-
$this->assertTrue($definition->getArgument('name')->isRequired()); // Name is required to find the service
37-
38-
//check options
39-
$this->assertTrue($definition->hasOption('messages'));
40-
$this->assertTrue($definition->getOption('messages')->isValueOptional()); // It should accept value
41-
42-
$this->assertTrue($definition->hasOption('route'));
43-
$this->assertTrue($definition->getOption('route')->isValueOptional()); // It should accept value
44-
45-
$this->assertTrue($definition->hasOption('without-signals'));
46-
$this->assertFalse($definition->getOption('without-signals')->acceptValue()); // It shouldn't accept value because it is a true/false input
47-
48-
$this->assertTrue($definition->hasOption('debug'));
49-
$this->assertFalse($definition->getOption('debug')->acceptValue()); // It shouldn't accept value because it is a true/false input
50-
}
51-
}
9+
beforeEach(function () {
10+
$this->application = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
11+
$this->definition = $this->getMockBuilder(InputDefinition::class)->disableOriginalConstructor()->getMock();
12+
$this->helperSet = $this->getMockBuilder(HelperSet::class)->getMock();
13+
14+
$this->application->method('getDefinition')->willReturn($this->definition);
15+
$this->definition->method('getArguments')->willReturn([]);
16+
$this->definition->method('getOptions')->willReturn([
17+
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
18+
new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'),
19+
new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'),
20+
]);
21+
22+
$this->application->expects($this->once())->method('getHelperSet')->willReturn($this->helperSet);
23+
24+
$this->command = new ConsumerCommand();
25+
$this->command->setApplication($this->application);
26+
});
27+
28+
test('consumer command has the correct input definition', function () {
29+
$definition = $this->command->getDefinition();
30+
31+
expect($definition->hasArgument('name'))->toBeTrue();
32+
expect($definition->getArgument('name')->isRequired())->toBeTrue();
33+
34+
expect($definition->hasOption('messages'))->toBeTrue();
35+
expect($definition->getOption('messages')->isValueOptional())->toBeTrue();
36+
37+
expect($definition->hasOption('route'))->toBeTrue();
38+
expect($definition->getOption('route')->isValueOptional())->toBeTrue();
39+
40+
expect($definition->hasOption('without-signals'))->toBeTrue();
41+
expect($definition->getOption('without-signals')->acceptValue())->toBeFalse();
42+
43+
expect($definition->hasOption('debug'))->toBeTrue();
44+
expect($definition->getOption('debug')->acceptValue())->toBeFalse();
45+
});
Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,48 @@
11
<?php
22

3-
namespace OldSound\RabbitMqBundle\Tests\Command;
4-
53
use OldSound\RabbitMqBundle\Command\DynamicConsumerCommand;
4+
use Symfony\Component\Console\Application;
5+
use Symfony\Component\Console\Helper\HelperSet;
6+
use Symfony\Component\Console\Input\InputDefinition;
67
use Symfony\Component\Console\Input\InputOption;
78

8-
class DynamicConsumerCommandTest extends BaseCommandTest
9-
{
10-
protected function setUp(): void
11-
{
12-
parent::setUp();
13-
$this->definition->expects($this->any())
14-
->method('getOptions')
15-
->will($this->returnValue([
16-
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
17-
new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'),
18-
new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'),
19-
]));
20-
$this->application->expects($this->once())
21-
->method('getHelperSet')
22-
->will($this->returnValue($this->helperSet));
23-
24-
$this->command = new DynamicConsumerCommand();
25-
$this->command->setApplication($this->application);
26-
}
27-
28-
/**
29-
* testInputsDefinitionCommand
30-
*/
31-
public function testInputsDefinitionCommand()
32-
{
33-
// check argument
34-
$definition = $this->command->getDefinition();
35-
$this->assertTrue($definition->hasArgument('name'));
36-
$this->assertTrue($definition->getArgument('name')->isRequired()); // Name is required to find the service
37-
38-
$this->assertTrue($definition->hasArgument('context'));
39-
$this->assertTrue($definition->getArgument('context')->isRequired()); // Context is required for the queue options provider
40-
41-
//check options
42-
$this->assertTrue($definition->hasOption('messages'));
43-
$this->assertTrue($definition->getOption('messages')->isValueOptional()); // It should accept value
44-
45-
$this->assertTrue($definition->hasOption('route'));
46-
$this->assertTrue($definition->getOption('route')->isValueOptional()); // It should accept value
47-
48-
$this->assertTrue($definition->hasOption('without-signals'));
49-
$this->assertFalse($definition->getOption('without-signals')->acceptValue()); // It shouldn't accept value because it is a true/false input
50-
51-
$this->assertTrue($definition->hasOption('debug'));
52-
$this->assertFalse($definition->getOption('debug')->acceptValue()); // It shouldn't accept value because it is a true/false input
53-
}
54-
}
9+
beforeEach(function () {
10+
$this->application = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
11+
$this->definition = $this->getMockBuilder(InputDefinition::class)->disableOriginalConstructor()->getMock();
12+
$this->helperSet = $this->getMockBuilder(HelperSet::class)->getMock();
13+
14+
$this->application->method('getDefinition')->willReturn($this->definition);
15+
$this->definition->method('getArguments')->willReturn([]);
16+
$this->definition->method('getOptions')->willReturn([
17+
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
18+
new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'),
19+
new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'),
20+
]);
21+
22+
$this->application->expects($this->once())->method('getHelperSet')->willReturn($this->helperSet);
23+
24+
$this->command = new DynamicConsumerCommand();
25+
$this->command->setApplication($this->application);
26+
});
27+
28+
test('dynamic consumer command has the correct input definition', function () {
29+
$definition = $this->command->getDefinition();
30+
31+
expect($definition->hasArgument('name'))->toBeTrue();
32+
expect($definition->getArgument('name')->isRequired())->toBeTrue();
33+
34+
expect($definition->hasArgument('context'))->toBeTrue();
35+
expect($definition->getArgument('context')->isRequired())->toBeTrue();
36+
37+
expect($definition->hasOption('messages'))->toBeTrue();
38+
expect($definition->getOption('messages')->isValueOptional())->toBeTrue();
39+
40+
expect($definition->hasOption('route'))->toBeTrue();
41+
expect($definition->getOption('route')->isValueOptional())->toBeTrue();
42+
43+
expect($definition->hasOption('without-signals'))->toBeTrue();
44+
expect($definition->getOption('without-signals')->acceptValue())->toBeFalse();
45+
46+
expect($definition->hasOption('debug'))->toBeTrue();
47+
expect($definition->getOption('debug')->acceptValue())->toBeFalse();
48+
});
Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,48 @@
11
<?php
22

3-
namespace OldSound\RabbitMqBundle\Tests\Command;
4-
53
use OldSound\RabbitMqBundle\Command\MultipleConsumerCommand;
4+
use Symfony\Component\Console\Application;
5+
use Symfony\Component\Console\Helper\HelperSet;
6+
use Symfony\Component\Console\Input\InputDefinition;
67
use Symfony\Component\Console\Input\InputOption;
78

8-
class MultipleConsumerCommandTest extends BaseCommandTest
9-
{
10-
protected function setUp(): void
11-
{
12-
parent::setUp();
13-
$this->definition->expects($this->any())
14-
->method('getOptions')
15-
->will($this->returnValue([
16-
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
17-
new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'),
18-
new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'),
19-
]));
20-
$this->application->expects($this->once())
21-
->method('getHelperSet')
22-
->will($this->returnValue($this->helperSet));
23-
24-
$this->command = new MultipleConsumerCommand();
25-
$this->command->setApplication($this->application);
26-
}
27-
28-
/**
29-
* testInputsDefinitionCommand
30-
*/
31-
public function testInputsDefinitionCommand()
32-
{
33-
// check argument
34-
$definition = $this->command->getDefinition();
35-
$this->assertTrue($definition->hasArgument('name'));
36-
$this->assertTrue($definition->getArgument('name')->isRequired()); // Name is required to find the service
37-
38-
$this->assertTrue($definition->hasArgument('context'));
39-
$this->assertFalse($definition->getArgument('context')->isRequired()); // Context is required for the queue options provider
40-
41-
//check options
42-
$this->assertTrue($definition->hasOption('messages'));
43-
$this->assertTrue($definition->getOption('messages')->isValueOptional()); // It should accept value
44-
45-
$this->assertTrue($definition->hasOption('route'));
46-
$this->assertTrue($definition->getOption('route')->isValueOptional()); // It should accept value
47-
48-
$this->assertTrue($definition->hasOption('without-signals'));
49-
$this->assertFalse($definition->getOption('without-signals')->acceptValue()); // It shouldn't accept value because it is a true/false input
50-
51-
$this->assertTrue($definition->hasOption('debug'));
52-
$this->assertFalse($definition->getOption('debug')->acceptValue()); // It shouldn't accept value because it is a true/false input
53-
}
54-
}
9+
beforeEach(function () {
10+
$this->application = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
11+
$this->definition = $this->getMockBuilder(InputDefinition::class)->disableOriginalConstructor()->getMock();
12+
$this->helperSet = $this->getMockBuilder(HelperSet::class)->getMock();
13+
14+
$this->application->method('getDefinition')->willReturn($this->definition);
15+
$this->definition->method('getArguments')->willReturn([]);
16+
$this->definition->method('getOptions')->willReturn([
17+
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
18+
new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'),
19+
new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'),
20+
]);
21+
22+
$this->application->expects($this->once())->method('getHelperSet')->willReturn($this->helperSet);
23+
24+
$this->command = new MultipleConsumerCommand();
25+
$this->command->setApplication($this->application);
26+
});
27+
28+
test('multiple consumer command has the correct input definition', function () {
29+
$definition = $this->command->getDefinition();
30+
31+
expect($definition->hasArgument('name'))->toBeTrue();
32+
expect($definition->getArgument('name')->isRequired())->toBeTrue();
33+
34+
expect($definition->hasArgument('context'))->toBeTrue();
35+
expect($definition->getArgument('context')->isRequired())->toBeFalse();
36+
37+
expect($definition->hasOption('messages'))->toBeTrue();
38+
expect($definition->getOption('messages')->isValueOptional())->toBeTrue();
39+
40+
expect($definition->hasOption('route'))->toBeTrue();
41+
expect($definition->getOption('route')->isValueOptional())->toBeTrue();
42+
43+
expect($definition->hasOption('without-signals'))->toBeTrue();
44+
expect($definition->getOption('without-signals')->acceptValue())->toBeFalse();
45+
46+
expect($definition->hasOption('debug'))->toBeTrue();
47+
expect($definition->getOption('debug')->acceptValue())->toBeFalse();
48+
});

Tests/Command/PurgeCommandTest.php

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11
<?php
22

3-
namespace OldSound\RabbitMqBundle\Tests\Command;
4-
53
use OldSound\RabbitMqBundle\Command\PurgeConsumerCommand;
4+
use Symfony\Component\Console\Application;
5+
use Symfony\Component\Console\Helper\HelperSet;
6+
use Symfony\Component\Console\Input\InputDefinition;
67
use Symfony\Component\Console\Input\InputOption;
78

8-
class PurgeCommandTest extends BaseCommandTest
9-
{
10-
protected function setUp(): void
11-
{
12-
parent::setUp();
13-
$this->definition->expects($this->any())
14-
->method('getOptions')
15-
->will($this->returnValue([
16-
new InputOption('--no-confirmation', null, InputOption::VALUE_NONE, 'Switches off confirmation mode.'),
17-
]));
18-
$this->application->expects($this->once())
19-
->method('getHelperSet')
20-
->will($this->returnValue($this->helperSet));
21-
22-
$this->command = new PurgeConsumerCommand();
23-
$this->command->setApplication($this->application);
24-
}
25-
26-
/**
27-
* testInputsDefinitionCommand
28-
*/
29-
public function testInputsDefinitionCommand()
30-
{
31-
// check argument
32-
$definition = $this->command->getDefinition();
33-
$this->assertTrue($definition->hasArgument('name'));
34-
$this->assertTrue($definition->getArgument('name')->isRequired()); // Name is required to find the service
35-
36-
//check options
37-
$this->assertTrue($definition->hasOption('no-confirmation'));
38-
$this->assertFalse($definition->getOption('no-confirmation')->acceptValue()); // It shouldn't accept value because it is a true/false input
39-
}
40-
}
9+
beforeEach(function () {
10+
$this->application = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
11+
$this->definition = $this->getMockBuilder(InputDefinition::class)->disableOriginalConstructor()->getMock();
12+
$this->helperSet = $this->getMockBuilder(HelperSet::class)->getMock();
13+
14+
$this->application->method('getDefinition')->willReturn($this->definition);
15+
$this->definition->method('getArguments')->willReturn([]);
16+
$this->definition->method('getOptions')->willReturn([
17+
new InputOption('--no-confirmation', null, InputOption::VALUE_NONE, 'Switches off confirmation mode.'),
18+
]);
19+
20+
$this->application->expects($this->once())->method('getHelperSet')->willReturn($this->helperSet);
21+
22+
$this->command = new PurgeConsumerCommand();
23+
$this->command->setApplication($this->application);
24+
});
25+
26+
test('purge command has the correct input definition', function () {
27+
$definition = $this->command->getDefinition();
28+
29+
expect($definition->hasArgument('name'))->toBeTrue();
30+
expect($definition->getArgument('name')->isRequired())->toBeTrue();
31+
32+
expect($definition->hasOption('no-confirmation'))->toBeTrue();
33+
expect($definition->getOption('no-confirmation')->acceptValue())->toBeFalse();
34+
});

0 commit comments

Comments
 (0)