Skip to content

Commit 97bfe13

Browse files
OskarStarknicolas-grekas
authored andcommitted
Use createMock() and use import instead of FQCN
1 parent 8eea52a commit 97bfe13

File tree

8 files changed

+38
-33
lines changed

8 files changed

+38
-33
lines changed

Tests/DefinitionTest.php

Lines changed: 4 additions & 3 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 2 additions & 1 deletion
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 "boolean".');
8283
$this->store->getMetadata('title', true);
8384
}

Tests/RegistryTest.php

Lines changed: 9 additions & 8 deletions
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\SupportStrategyInterface;
@@ -19,9 +20,9 @@ protected function setUp(): void
1920
{
2021
$this->registry = new Registry();
2122

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

2728
protected function tearDown(): void
@@ -37,7 +38,7 @@ public function testAddIsDeprecated()
3738
{
3839
$registry = new Registry();
3940

40-
$registry->add($w = new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), 'workflow1'), $this->createSupportStrategy(Subject1::class));
41+
$registry->add($w = new Workflow(new Definition([], []), $this->createMock(MarkingStoreInterface::class), $this->createMock(EventDispatcherInterface::class), 'workflow1'), $this->createSupportStrategy(Subject1::class));
4142

4243
$workflow = $registry->get(new Subject1());
4344
$this->assertInstanceOf(Workflow::class, $workflow);
@@ -61,7 +62,7 @@ public function testGetWithSuccess()
6162

6263
public function testGetWithMultipleMatch()
6364
{
64-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidArgumentException::class);
65+
$this->expectException(InvalidArgumentException::class);
6566
$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.');
6667
$w1 = $this->registry->get(new Subject2());
6768
$this->assertInstanceOf(Workflow::class, $w1);
@@ -70,7 +71,7 @@ public function testGetWithMultipleMatch()
7071

7172
public function testGetWithNoMatch()
7273
{
73-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidArgumentException::class);
74+
$this->expectException(InvalidArgumentException::class);
7475
$this->expectExceptionMessage('Unable to find a workflow for class "stdClass".');
7576
$w1 = $this->registry->get(new \stdClass());
7677
$this->assertInstanceOf(Workflow::class, $w1);
@@ -109,7 +110,7 @@ public function testAllWithNoMatch()
109110
*/
110111
private function createSupportStrategy($supportedClassName)
111112
{
112-
$strategy = $this->getMockBuilder(SupportStrategyInterface::class)->getMock();
113+
$strategy = $this->createMock(SupportStrategyInterface::class);
113114
$strategy->expects($this->any())->method('supports')
114115
->willReturnCallback(function ($workflow, $subject) use ($supportedClassName) {
115116
return $subject instanceof $supportedClassName;
@@ -123,7 +124,7 @@ private function createSupportStrategy($supportedClassName)
123124
*/
124125
private function createWorkflowSupportStrategy($supportedClassName)
125126
{
126-
$strategy = $this->getMockBuilder(WorkflowSupportStrategyInterface::class)->getMock();
127+
$strategy = $this->createMock(WorkflowSupportStrategyInterface::class);
127128
$strategy->expects($this->any())->method('supports')
128129
->willReturnCallback(function ($workflow, $subject) use ($supportedClassName) {
129130
return $subject instanceof $supportedClassName;

Tests/SupportStrategy/ClassInstanceSupportStrategyTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public function testSupportsIfNotClassInstance()
3030

3131
private function createWorkflow()
3232
{
33-
return $this->getMockBuilder(Workflow::class)
34-
->disableOriginalConstructor()
35-
->getMock();
33+
return $this->createMock(Workflow::class);
3634
}
3735
}

Tests/Validator/StateMachineValidatorTest.php

Lines changed: 5 additions & 4 deletions
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

Lines changed: 4 additions & 3 deletions
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 testSinglePlaceWorkflowValidatorAndComplexWorkflow()
1617
{
17-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
18+
$this->expectException(InvalidDefinitionException::class);
1819
$this->expectExceptionMessage('The marking store of workflow "foo" can not store many places.');
1920
$definition = $this->createComplexWorkflowDefinition();
2021

@@ -33,7 +34,7 @@ public function testSinglePlaceWorkflowValidatorAndSimpleWorkflow()
3334

3435
public function testWorkflowWithInvalidNames()
3536
{
36-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
37+
$this->expectException(InvalidDefinitionException::class);
3738
$this->expectExceptionMessage('All transitions for a place must have an unique name. Multiple transitions named "t1" where found for place "a" in workflow "foo".');
3839
$places = range('a', 'c');
3940

@@ -49,7 +50,7 @@ public function testWorkflowWithInvalidNames()
4950

5051
public function testWithTooManyInitialPlaces()
5152
{
52-
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
53+
$this->expectException(InvalidDefinitionException::class);
5354
$this->expectExceptionMessage('The marking store of workflow "foo" can not store many places. But the definition has 2 initial places. Only one is supported.');
5455
$places = range('a', 'c');
5556
$transitions = [];

Tests/WorkflowTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
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;
13+
use Symfony\Component\Workflow\Exception\UndefinedTransitionException;
1214
use Symfony\Component\Workflow\Marking;
1315
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
1416
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
@@ -22,17 +24,17 @@ class WorkflowTest extends TestCase
2224

2325
public function testGetMarkingWithInvalidStoreReturn()
2426
{
25-
$this->expectException(\Symfony\Component\Workflow\Exception\LogicException::class);
27+
$this->expectException(LogicException::class);
2628
$this->expectExceptionMessage('The value returned by the MarkingStore is not an instance of "Symfony\Component\Workflow\Marking" for workflow "unnamed".');
2729
$subject = new Subject();
28-
$workflow = new Workflow(new Definition([], []), $this->getMockBuilder(MarkingStoreInterface::class)->getMock());
30+
$workflow = new Workflow(new Definition([], []), $this->createMock(MarkingStoreInterface::class));
2931

3032
$workflow->getMarking($subject);
3133
}
3234

3335
public function testGetMarkingWithEmptyDefinition()
3436
{
35-
$this->expectException(\Symfony\Component\Workflow\Exception\LogicException::class);
37+
$this->expectException(LogicException::class);
3638
$this->expectExceptionMessage('The Marking is empty and there is no initial place for workflow "unnamed".');
3739
$subject = new Subject();
3840
$workflow = new Workflow(new Definition([], []), new MethodMarkingStore());
@@ -42,7 +44,7 @@ public function testGetMarkingWithEmptyDefinition()
4244

4345
public function testGetMarkingWithImpossiblePlace()
4446
{
45-
$this->expectException(\Symfony\Component\Workflow\Exception\LogicException::class);
47+
$this->expectException(LogicException::class);
4648
$this->expectExceptionMessage('Place "nope" is not valid for workflow "unnamed".');
4749
$subject = new Subject();
4850
$subject->setMarking(['nope' => 1]);
@@ -169,7 +171,7 @@ public function testCanWithSameNameTransition()
169171

170172
public function testBuildTransitionBlockerListReturnsUndefinedTransition()
171173
{
172-
$this->expectException(\Symfony\Component\Workflow\Exception\UndefinedTransitionException::class);
174+
$this->expectException(UndefinedTransitionException::class);
173175
$this->expectExceptionMessage('Transition "404 Not Found" is not defined for workflow "unnamed".');
174176
$definition = $this->createSimpleWorkflowDefinition();
175177
$subject = new Subject();
@@ -249,7 +251,7 @@ public function testBuildTransitionBlockerListReturnsReasonsProvidedInGuards()
249251

250252
public function testApplyWithNotExisingTransition()
251253
{
252-
$this->expectException(\Symfony\Component\Workflow\Exception\UndefinedTransitionException::class);
254+
$this->expectException(UndefinedTransitionException::class);
253255
$this->expectExceptionMessage('Transition "404 Not Found" is not defined for workflow "unnamed".');
254256
$definition = $this->createComplexWorkflowDefinition();
255257
$subject = new Subject();

0 commit comments

Comments
 (0)