Skip to content

Commit c76b5cf

Browse files
Merge branch '4.4' into 5.1
* 4.4: Use createMock() and use import instead of FQCN
2 parents 6a37b0d + 97bfe13 commit c76b5cf

7 files changed

+30
-24
lines changed

Tests/DefinitionTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Symfony\Component\Workflow\Definition;
7+
use Symfony\Component\Workflow\Exception\LogicException;
78
use Symfony\Component\Workflow\Transition;
89

910
class DefinitionTest extends TestCase
@@ -36,7 +37,7 @@ public function testSetInitialPlaces()
3637

3738
public function testSetInitialPlaceAndPlaceIsNotDefined()
3839
{
39-
$this->expectException(\Symfony\Component\Workflow\Exception\LogicException::class);
40+
$this->expectException(LogicException::class);
4041
$this->expectExceptionMessage('Place "d" cannot be the initial place as it does not exist.');
4142
new Definition([], [], 'd');
4243
}
@@ -54,7 +55,7 @@ public function testAddTransition()
5455

5556
public function testAddTransitionAndFromPlaceIsNotDefined()
5657
{
57-
$this->expectException(\Symfony\Component\Workflow\Exception\LogicException::class);
58+
$this->expectException(LogicException::class);
5859
$this->expectExceptionMessage('Place "c" referenced in transition "name" does not exist.');
5960
$places = range('a', 'b');
6061

@@ -63,7 +64,7 @@ public function testAddTransitionAndFromPlaceIsNotDefined()
6364

6465
public function testAddTransitionAndToPlaceIsNotDefined()
6566
{
66-
$this->expectException(\Symfony\Component\Workflow\Exception\LogicException::class);
67+
$this->expectException(LogicException::class);
6768
$this->expectExceptionMessage('Place "c" referenced in transition "name" does not exist.');
6869
$places = range('a', 'b');
6970

Tests/EventListener/GuardListenerTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ protected function setUp(): void
3939
];
4040
$expressionLanguage = new ExpressionLanguage();
4141
$token = new UsernamePasswordToken('username', 'credentials', 'provider', ['ROLE_USER']);
42-
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();
42+
$tokenStorage = $this->createMock(TokenStorageInterface::class);
4343
$tokenStorage->expects($this->any())->method('getToken')->willReturn($token);
44-
$this->authenticationChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
45-
$trustResolver = $this->getMockBuilder(AuthenticationTrustResolverInterface::class)->getMock();
46-
$this->validator = $this->getMockBuilder(ValidatorInterface::class)->getMock();
44+
$this->authenticationChecker = $this->createMock(AuthorizationCheckerInterface::class);
45+
$trustResolver = $this->createMock(AuthenticationTrustResolverInterface::class);
46+
$this->validator = $this->createMock(ValidatorInterface::class);
4747
$roleHierarchy = new RoleHierarchy([]);
4848
$this->listener = new GuardListener($this->configuration, $expressionLanguage, $tokenStorage, $this->authenticationChecker, $trustResolver, $roleHierarchy, $this->validator);
4949
}
@@ -138,7 +138,7 @@ private function createEvent(Transition $transition = null)
138138
$subject = new Subject();
139139
$transition = $transition ?: new Transition('name', 'from', 'to');
140140

141-
$workflow = $this->getMockBuilder(WorkflowInterface::class)->getMock();
141+
$workflow = $this->createMock(WorkflowInterface::class);
142142

143143
return new GuardEvent($subject, new Marking($subject->getMarking() ?? []), $transition, $workflow);
144144
}

Tests/Metadata/InMemoryMetadataStoreTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Component\Workflow\Tests\Metadata;
44

55
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\Workflow\Exception\InvalidArgumentException;
67
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
78
use Symfony\Component\Workflow\Transition;
89

@@ -77,7 +78,7 @@ public function testGetMetadata()
7778

7879
public function testGetMetadataWithUnknownType()
7980
{
80-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidArgumentException::class);
81+
$this->expectException(InvalidArgumentException::class);
8182
$this->expectExceptionMessage('Could not find a MetadataBag for the subject of type "bool".');
8283
$this->store->getMetadata('title', true);
8384
}

Tests/RegistryTest.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Symfony\Component\Workflow\Definition;
7+
use Symfony\Component\Workflow\Exception\InvalidArgumentException;
78
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
89
use Symfony\Component\Workflow\Registry;
910
use Symfony\Component\Workflow\SupportStrategy\WorkflowSupportStrategyInterface;
@@ -18,9 +19,9 @@ protected function setUp(): void
1819
{
1920
$this->registry = new Registry();
2021

21-
$this->registry->addWorkflow(new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow1'), $this->createWorkflowSupportStrategy(Subject1::class));
22-
$this->registry->addWorkflow(new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow2'), $this->createWorkflowSupportStrategy(Subject2::class));
23-
$this->registry->addWorkflow(new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow3'), $this->createWorkflowSupportStrategy(Subject2::class));
22+
$this->registry->addWorkflow(new Workflow(new Definition([], []), $this->createMock(MarkingStoreInterface::class), $this->createMock(EventDispatcherInterface::class), 'workflow1'), $this->createWorkflowSupportStrategy(Subject1::class));
23+
$this->registry->addWorkflow(new Workflow(new Definition([], []), $this->createMock(MarkingStoreInterface::class), $this->createMock(EventDispatcherInterface::class), 'workflow2'), $this->createWorkflowSupportStrategy(Subject2::class));
24+
$this->registry->addWorkflow(new Workflow(new Definition([], []), $this->createMock(MarkingStoreInterface::class), $this->createMock(EventDispatcherInterface::class), 'workflow3'), $this->createWorkflowSupportStrategy(Subject2::class));
2425
}
2526

2627
protected function tearDown(): void
@@ -55,7 +56,7 @@ public function testGetWithSuccess()
5556

5657
public function testGetWithMultipleMatch()
5758
{
58-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidArgumentException::class);
59+
$this->expectException(InvalidArgumentException::class);
5960
$this->expectExceptionMessage('Too many workflows (workflow2, workflow3) match this subject (Symfony\Component\Workflow\Tests\Subject2); set a different name on each and use the second (name) argument of this method.');
6061
$w1 = $this->registry->get(new Subject2());
6162
$this->assertInstanceOf(Workflow::class, $w1);
@@ -64,7 +65,7 @@ public function testGetWithMultipleMatch()
6465

6566
public function testGetWithNoMatch()
6667
{
67-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidArgumentException::class);
68+
$this->expectException(InvalidArgumentException::class);
6869
$this->expectExceptionMessage('Unable to find a workflow for class "stdClass".');
6970
$w1 = $this->registry->get(new \stdClass());
7071
$this->assertInstanceOf(Workflow::class, $w1);
@@ -100,7 +101,7 @@ public function testAllWithNoMatch()
100101

101102
private function createWorkflowSupportStrategy($supportedClassName)
102103
{
103-
$strategy = $this->getMockBuilder(WorkflowSupportStrategyInterface::class)->getMock();
104+
$strategy = $this->createMock(WorkflowSupportStrategyInterface::class);
104105
$strategy->expects($this->any())->method('supports')
105106
->willReturnCallback(function ($workflow, $subject) use ($supportedClassName) {
106107
return $subject instanceof $supportedClassName;

Tests/Validator/StateMachineValidatorTest.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Symfony\Component\Workflow\Definition;
7+
use Symfony\Component\Workflow\Exception\InvalidDefinitionException;
78
use Symfony\Component\Workflow\Transition;
89
use Symfony\Component\Workflow\Validator\StateMachineValidator;
910

1011
class StateMachineValidatorTest extends TestCase
1112
{
1213
public function testWithMultipleTransitionWithSameNameShareInput()
1314
{
14-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
15+
$this->expectException(InvalidDefinitionException::class);
1516
$this->expectExceptionMessage('A transition from a place/state must have an unique name.');
1617
$places = ['a', 'b', 'c'];
1718
$transitions[] = new Transition('t1', 'a', 'b');
@@ -35,7 +36,7 @@ public function testWithMultipleTransitionWithSameNameShareInput()
3536

3637
public function testWithMultipleTos()
3738
{
38-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
39+
$this->expectException(InvalidDefinitionException::class);
3940
$this->expectExceptionMessage('A transition in StateMachine can only have one output.');
4041
$places = ['a', 'b', 'c'];
4142
$transitions[] = new Transition('t1', 'a', ['b', 'c']);
@@ -58,7 +59,7 @@ public function testWithMultipleTos()
5859

5960
public function testWithMultipleFroms()
6061
{
61-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
62+
$this->expectException(InvalidDefinitionException::class);
6263
$this->expectExceptionMessage('A transition in StateMachine can only have one input.');
6364
$places = ['a', 'b', 'c'];
6465
$transitions[] = new Transition('t1', ['a', 'b'], 'c');
@@ -106,7 +107,7 @@ public function testValid()
106107

107108
public function testWithTooManyInitialPlaces()
108109
{
109-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
110+
$this->expectException(InvalidDefinitionException::class);
110111
$this->expectExceptionMessage('The state machine "foo" can not store many places. But the definition has 2 initial places. Only one is supported.');
111112
$places = range('a', 'c');
112113
$transitions = [];

Tests/Validator/WorkflowValidatorTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Symfony\Component\Workflow\Definition;
7+
use Symfony\Component\Workflow\Exception\InvalidDefinitionException;
78
use Symfony\Component\Workflow\Tests\WorkflowBuilderTrait;
89
use Symfony\Component\Workflow\Transition;
910
use Symfony\Component\Workflow\Validator\WorkflowValidator;
@@ -14,7 +15,7 @@ class WorkflowValidatorTest extends TestCase
1415

1516
public function testWorkflowWithInvalidNames()
1617
{
17-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
18+
$this->expectException(InvalidDefinitionException::class);
1819
$this->expectExceptionMessage('All transitions for a place must have an unique name. Multiple transitions named "t1" where found for place "a" in workflow "foo".');
1920
$places = range('a', 'c');
2021

Tests/WorkflowTest.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Workflow\Event\Event;
99
use Symfony\Component\Workflow\Event\GuardEvent;
1010
use Symfony\Component\Workflow\Event\TransitionEvent;
11+
use Symfony\Component\Workflow\Exception\LogicException;
1112
use Symfony\Component\Workflow\Exception\NotEnabledTransitionException;
1213
use Symfony\Component\Workflow\Exception\UndefinedTransitionException;
1314
use Symfony\Component\Workflow\Marking;
@@ -23,17 +24,17 @@ class WorkflowTest extends TestCase
2324

2425
public function testGetMarkingWithInvalidStoreReturn()
2526
{
26-
$this->expectException(\Symfony\Component\Workflow\Exception\LogicException::class);
27+
$this->expectException(LogicException::class);
2728
$this->expectExceptionMessage('The value returned by the MarkingStore is not an instance of "Symfony\Component\Workflow\Marking" for workflow "unnamed".');
2829
$subject = new Subject();
29-
$workflow = new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock());
30+
$workflow = new Workflow(new Definition([], []), $this->createMock(MarkingStoreInterface::class));
3031

3132
$workflow->getMarking($subject);
3233
}
3334

3435
public function testGetMarkingWithEmptyDefinition()
3536
{
36-
$this->expectException(\Symfony\Component\Workflow\Exception\LogicException::class);
37+
$this->expectException(LogicException::class);
3738
$this->expectExceptionMessage('The Marking is empty and there is no initial place for workflow "unnamed".');
3839
$subject = new Subject();
3940
$workflow = new Workflow(new Definition([], []), new MethodMarkingStore());
@@ -43,7 +44,7 @@ public function testGetMarkingWithEmptyDefinition()
4344

4445
public function testGetMarkingWithImpossiblePlace()
4546
{
46-
$this->expectException(\Symfony\Component\Workflow\Exception\LogicException::class);
47+
$this->expectException(LogicException::class);
4748
$this->expectExceptionMessage('Place "nope" is not valid for workflow "unnamed".');
4849
$subject = new Subject();
4950
$subject->setMarking(['nope' => 1]);

0 commit comments

Comments
 (0)