Skip to content

Commit c6a6db2

Browse files
committed
fix tests
1 parent 4edbcfd commit c6a6db2

11 files changed

+93
-56
lines changed

Tests/Symfony/Client/ConsumeCommandTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Interop\Queue\Queue;
2323
use PHPUnit\Framework\TestCase;
2424
use Psr\Container\ContainerInterface;
25+
use Symfony\Component\Console\Attribute\AsCommand;
2526
use Symfony\Component\Console\Command\Command;
2627
use Symfony\Component\Console\Tester\CommandTester;
2728

@@ -44,11 +45,22 @@ public function testCouldBeConstructedWithRequiredAttributes()
4445
new ConsumeCommand($this->createMock(ContainerInterface::class), 'default');
4546
}
4647

47-
public function testShouldHaveCommandName()
48+
public function testShouldHaveAsCommandAttributeWithCommandName()
4849
{
49-
$command = new ConsumeCommand($this->createMock(ContainerInterface::class), 'default');
50+
$commandClass = ConsumeCommand::class;
51+
52+
$reflectionClass = new \ReflectionClass($commandClass);
53+
54+
$attributes = $reflectionClass->getAttributes(AsCommand::class);
55+
56+
$this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.');
57+
58+
// Get the first attribute instance (assuming there is only one AsCommand attribute)
59+
$asCommandAttribute = $attributes[0];
5060

51-
$this->assertEquals('enqueue:consume', $command->getName());
61+
// Verify the 'name' parameter value
62+
$attributeInstance = $asCommandAttribute->newInstance();
63+
$this->assertEquals('enqueue:consume', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.');
5264
}
5365

5466
public function testShouldHaveExpectedOptions()
@@ -641,7 +653,7 @@ private function createContextWithoutSubscriptionConsumerMock(): InteropContext
641653
/**
642654
* @return \PHPUnit\Framework\MockObject\MockObject|InteropContext
643655
*/
644-
private function createContextStub(Consumer $consumer = null): InteropContext
656+
private function createContextStub(?Consumer $consumer = null): InteropContext
645657
{
646658
$context = $this->createContextWithoutSubscriptionConsumerMock();
647659
$context

Tests/Symfony/Client/ProduceCommandTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Enqueue\Test\ClassExtensionTrait;
1010
use PHPUnit\Framework\TestCase;
1111
use Psr\Container\ContainerInterface;
12+
use Symfony\Component\Console\Attribute\AsCommand;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Tester\CommandTester;
1415

@@ -31,11 +32,22 @@ public function testCouldBeConstructedWithContainerAsFirstArgument()
3132
new ProduceCommand($this->createMock(ContainerInterface::class), 'default');
3233
}
3334

34-
public function testShouldHaveCommandName()
35+
public function testShouldHaveAsCommandAttributeWithCommandName()
3536
{
36-
$command = new ProduceCommand($this->createMock(ContainerInterface::class), 'default');
37+
$commandClass = ProduceCommand::class;
38+
39+
$reflectionClass = new \ReflectionClass($commandClass);
40+
41+
$attributes = $reflectionClass->getAttributes(AsCommand::class);
42+
43+
$this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.');
44+
45+
// Get the first attribute instance (assuming there is only one AsCommand attribute)
46+
$asCommandAttribute = $attributes[0];
3747

38-
$this->assertEquals('enqueue:produce', $command->getName());
48+
// Verify the 'name' parameter value
49+
$attributeInstance = $asCommandAttribute->newInstance();
50+
$this->assertEquals('enqueue:produce', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.');
3951
}
4052

4153
public function testShouldHaveExpectedOptions()

Tests/Symfony/Client/RoutesCommandTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Enqueue\Test\ClassExtensionTrait;
1212
use PHPUnit\Framework\TestCase;
1313
use Psr\Container\ContainerInterface;
14+
use Symfony\Component\Console\Attribute\AsCommand;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617

@@ -33,11 +34,22 @@ public function testCouldBeConstructedWithConfigAndRouteCollectionAsArguments()
3334
new RoutesCommand($this->createMock(ContainerInterface::class), 'default');
3435
}
3536

36-
public function testShouldHaveCommandName()
37+
public function testShouldHaveAsCommandAttributeWithCommandName()
3738
{
38-
$command = new RoutesCommand($this->createMock(ContainerInterface::class), 'default');
39+
$commandClass = RoutesCommand::class;
40+
41+
$reflectionClass = new \ReflectionClass($commandClass);
42+
43+
$attributes = $reflectionClass->getAttributes(AsCommand::class);
44+
45+
$this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.');
46+
47+
// Get the first attribute instance (assuming there is only one AsCommand attribute)
48+
$asCommandAttribute = $attributes[0];
3949

40-
$this->assertEquals('enqueue:routes', $command->getName());
50+
// Verify the 'name' parameter value
51+
$attributeInstance = $asCommandAttribute->newInstance();
52+
$this->assertEquals('enqueue:routes', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.');
4153
}
4254

4355
public function testShouldHaveCommandAliases()

Tests/Symfony/Client/SetupBrokerCommandTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Enqueue\Test\ClassExtensionTrait;
99
use PHPUnit\Framework\TestCase;
1010
use Psr\Container\ContainerInterface;
11+
use Symfony\Component\Console\Attribute\AsCommand;
1112
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\Tester\CommandTester;
1314

@@ -30,11 +31,22 @@ public function testCouldBeConstructedWithContainerAsFirstArgument()
3031
new SetupBrokerCommand($this->createMock(ContainerInterface::class), 'default');
3132
}
3233

33-
public function testShouldHaveCommandName()
34+
public function testShouldHaveAsCommandAttributeWithCommandName()
3435
{
35-
$command = new SetupBrokerCommand($this->createMock(ContainerInterface::class), 'default');
36+
$commandClass = SetupBrokerCommand::class;
37+
38+
$reflectionClass = new \ReflectionClass($commandClass);
39+
40+
$attributes = $reflectionClass->getAttributes(AsCommand::class);
41+
42+
$this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.');
43+
44+
// Get the first attribute instance (assuming there is only one AsCommand attribute)
45+
$asCommandAttribute = $attributes[0];
3646

37-
$this->assertEquals('enqueue:setup-broker', $command->getName());
47+
// Verify the 'name' parameter value
48+
$attributeInstance = $asCommandAttribute->newInstance();
49+
$this->assertEquals('enqueue:setup-broker', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.');
3850
}
3951

4052
public function testShouldHaveCommandAliases()

Tests/Symfony/Client/SimpleConsumeCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ public function testCouldBeConstructedWithRequiredAttributes()
3434
new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock());
3535
}
3636

37-
public function testShouldHaveCommandName()
38-
{
39-
$command = new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock());
40-
41-
$this->assertEquals('enqueue:consume', $command->getName());
42-
}
43-
4437
public function testShouldHaveExpectedOptions()
4538
{
4639
$command = new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock());

Tests/Symfony/Client/SimpleProduceCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ public function testCouldBeConstructedWithContainerAsFirstArgument()
2828
new SimpleProduceCommand($this->createProducerMock());
2929
}
3030

31-
public function testShouldHaveCommandName()
32-
{
33-
$command = new SimpleProduceCommand($this->createProducerMock());
34-
35-
$this->assertEquals('enqueue:produce', $command->getName());
36-
}
37-
3831
public function testShouldHaveExpectedOptions()
3932
{
4033
$command = new SimpleProduceCommand($this->createProducerMock());

Tests/Symfony/Client/SimpleRoutesCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ public function testCouldBeConstructedWithConfigAndRouteCollectionAsArguments()
3030
new SimpleRoutesCommand($this->createDriverMock());
3131
}
3232

33-
public function testShouldHaveCommandName()
34-
{
35-
$command = new SimpleRoutesCommand($this->createDriverMock());
36-
37-
$this->assertEquals('enqueue:routes', $command->getName());
38-
}
39-
4033
public function testShouldHaveCommandAliases()
4134
{
4235
$command = new SimpleRoutesCommand($this->createDriverMock());

Tests/Symfony/Client/SimpleSetupBrokerCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ public function testCouldBeConstructedWithContainerAsFirstArgument()
2828
new SimpleSetupBrokerCommand($this->createClientDriverMock());
2929
}
3030

31-
public function testShouldHaveCommandName()
32-
{
33-
$command = new SimpleSetupBrokerCommand($this->createClientDriverMock());
34-
35-
$this->assertEquals('enqueue:setup-broker', $command->getName());
36-
}
37-
3831
public function testShouldHaveCommandAliases()
3932
{
4033
$command = new SimpleSetupBrokerCommand($this->createClientDriverMock());

Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Interop\Queue\Queue as InteropQueue;
1616
use PHPUnit\Framework\TestCase;
1717
use Psr\Container\ContainerInterface;
18+
use Symfony\Component\Console\Attribute\AsCommand;
1819
use Symfony\Component\Console\Command\Command;
1920
use Symfony\Component\Console\Tester\CommandTester;
2021

@@ -37,11 +38,22 @@ public function testCouldBeConstructedWithRequiredAttributes()
3738
new ConfigurableConsumeCommand($this->createMock(ContainerInterface::class), 'default');
3839
}
3940

40-
public function testShouldHaveCommandName()
41+
public function testShouldHaveAsCommandAttributeWithCommandName()
4142
{
42-
$command = new ConfigurableConsumeCommand($this->createMock(ContainerInterface::class), 'default');
43+
$commandClass = ConfigurableConsumeCommand::class;
44+
45+
$reflectionClass = new \ReflectionClass($commandClass);
46+
47+
$attributes = $reflectionClass->getAttributes(AsCommand::class);
48+
49+
$this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.');
50+
51+
// Get the first attribute instance (assuming there is only one AsCommand attribute)
52+
$asCommandAttribute = $attributes[0];
4353

44-
$this->assertEquals('enqueue:transport:consume', $command->getName());
54+
// Verify the 'name' parameter value
55+
$attributeInstance = $asCommandAttribute->newInstance();
56+
$this->assertEquals('enqueue:transport:consume', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.');
4557
}
4658

4759
public function testShouldHaveExpectedOptions()
@@ -192,7 +204,7 @@ public function testShouldExecuteConsumptionWithSeveralCustomQueues()
192204

193205
public function testShouldExecuteConsumptionWhenProcessorImplementsQueueSubscriberInterface()
194206
{
195-
$processor = new class() implements Processor, QueueSubscriberInterface {
207+
$processor = new class implements Processor, QueueSubscriberInterface {
196208
public function process(InteropMessage $message, Context $context)
197209
{
198210
}

Tests/Symfony/Consumption/ConsumeCommandTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Interop\Queue\Queue;
1818
use PHPUnit\Framework\TestCase;
1919
use Psr\Container\ContainerInterface;
20+
use Symfony\Component\Console\Attribute\AsCommand;
2021
use Symfony\Component\Console\Command\Command;
2122
use Symfony\Component\Console\Tester\CommandTester;
2223

@@ -39,11 +40,22 @@ public function testCouldBeConstructedWithRequiredAttributes()
3940
new ConsumeCommand($this->createMock(ContainerInterface::class), 'default');
4041
}
4142

42-
public function testShouldHaveCommandName()
43+
public function testShouldHaveAsCommandAttributeWithCommandName()
4344
{
44-
$command = new ConsumeCommand($this->createMock(ContainerInterface::class), 'default');
45+
$commandClass = ConsumeCommand::class;
46+
47+
$reflectionClass = new \ReflectionClass($commandClass);
48+
49+
$attributes = $reflectionClass->getAttributes(AsCommand::class);
50+
51+
$this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.');
52+
53+
// Get the first attribute instance (assuming there is only one AsCommand attribute)
54+
$asCommandAttribute = $attributes[0];
4555

46-
$this->assertEquals('enqueue:transport:consume', $command->getName());
56+
// Verify the 'name' parameter value
57+
$attributeInstance = $asCommandAttribute->newInstance();
58+
$this->assertEquals('enqueue:transport:consume', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.');
4759
}
4860

4961
public function testShouldHaveExpectedOptions()
@@ -185,7 +197,7 @@ private function createContextWithoutSubscriptionConsumerMock(): InteropContext
185197
/**
186198
* @return \PHPUnit\Framework\MockObject\MockObject|InteropContext
187199
*/
188-
private function createContextStub(Consumer $consumer = null): InteropContext
200+
private function createContextStub(?Consumer $consumer = null): InteropContext
189201
{
190202
$context = $this->createContextWithoutSubscriptionConsumerMock();
191203
$context

Tests/Symfony/Consumption/SimpleConsumeCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ public function testCouldBeConstructedWithRequiredAttributes()
2929
new SimpleConsumeCommand($this->createQueueConsumerMock());
3030
}
3131

32-
public function testShouldHaveCommandName()
33-
{
34-
$command = new SimpleConsumeCommand($this->createQueueConsumerMock());
35-
36-
$this->assertEquals('enqueue:transport:consume', $command->getName());
37-
}
38-
3932
public function testShouldHaveExpectedOptions()
4033
{
4134
$command = new SimpleConsumeCommand($this->createQueueConsumerMock());

0 commit comments

Comments
 (0)