Skip to content

Commit a76ac25

Browse files
localheinzsebastianbergmann
authored andcommitted
Fix: Do not declare test classes in global namespace
1 parent 0b7a802 commit a76ac25

File tree

8 files changed

+122
-73
lines changed

8 files changed

+122
-73
lines changed

tests/unit/Framework/Constraint/LogicalXorTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
namespace Framework\Constraint;
10+
namespace PHPUnit\Framework\Constraint;
1111

1212
use function array_fill;
1313
use function array_map;
14-
use PHPUnit\Framework\Constraint\Constraint;
15-
use PHPUnit\Framework\Constraint\LogicalXor;
1614
use PHPUnit\Framework\TestCase;
1715

1816
/**

tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
11+
namespace PHPUnit\Framework\MockObject;
12+
13+
use ClassWithAllPossibleReturnTypes;
14+
use Foo;
1115
use PHPUnit\Framework\Constraint\IsEqual;
1216
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
13-
use PHPUnit\Framework\MockObject\IncompatibleReturnValueException;
14-
use PHPUnit\Framework\MockObject\InvocationHandler;
15-
use PHPUnit\Framework\MockObject\Matcher;
1617
use PHPUnit\Framework\MockObject\Stub\ReturnSelf;
1718
use PHPUnit\Framework\MockObject\Stub\ReturnStub;
1819
use PHPUnit\Framework\TestCase;
1920
use PHPUnit\TestFixture\MockObject\ClassWithImplicitProtocol;
21+
use stdClass;
2022

2123
/**
2224
* @covers \PHPUnit\Framework\MockObject\Builder\InvocationMocker

tests/unit/Framework/MockObject/GeneratorTest.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,26 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
use PHPUnit\Framework\MockObject\Generator;
11-
use PHPUnit\Framework\MockObject\MockObject;
10+
namespace PHPUnit\Framework\MockObject;
11+
12+
use function class_exists;
13+
use function md5;
14+
use function method_exists;
15+
use function microtime;
16+
use AbstractMockTestClass;
17+
use AbstractTrait;
18+
use AnInterface;
19+
use AnInterfaceWithReturnType;
20+
use ClassWithVariadicArgumentMethod;
21+
use Countable;
22+
use Exception;
23+
use ExceptionWithThrowable;
24+
use FinalClass;
25+
use InterfaceWithSemiReservedMethodName;
1226
use PHPUnit\Framework\TestCase;
27+
use SingletonClass;
28+
use stdClass;
29+
use Throwable;
1330

1431
/**
1532
* @covers \PHPUnit\Framework\MockObject\Generator
@@ -62,7 +79,7 @@ public function testGetMockThrowsExceptionWithNonExistingClass(): void
6279
{
6380
$this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class);
6481

65-
$this->assertFalse(\class_exists('Tux'));
82+
$this->assertFalse(class_exists('Tux'));
6683

6784
$this->generator->getMock('Tux', [], [], '', true, true, false, true, false, null, false);
6885
}
@@ -71,7 +88,7 @@ public function testGetMockThrowsExceptionWithNonExistingClasses(): void
7188
{
7289
$this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class);
7390

74-
$this->assertFalse(\class_exists('Tux'));
91+
$this->assertFalse(class_exists('Tux'));
7592

7693
$this->generator->getMock(['Tux', false], [], [], '', true, true, false, true, false, null, false);
7794
}
@@ -87,7 +104,7 @@ public function testGetMockCanCreateNonExistingFunctions(): void
87104
{
88105
$mock = $this->generator->getMock(stdClass::class, ['testFunction']);
89106

90-
$this->assertTrue(\method_exists($mock, 'testFunction'));
107+
$this->assertTrue(method_exists($mock, 'testFunction'));
91108
}
92109

93110
public function testGetMockGeneratorThrowsException(): void
@@ -102,22 +119,22 @@ public function testGetMockBlacklistedMethodNamesPhp7(): void
102119
{
103120
$mock = $this->generator->getMock(InterfaceWithSemiReservedMethodName::class);
104121

105-
$this->assertTrue(\method_exists($mock, 'unset'));
122+
$this->assertTrue(method_exists($mock, 'unset'));
106123
$this->assertInstanceOf(InterfaceWithSemiReservedMethodName::class, $mock);
107124
}
108125

109126
public function testGetMockForAbstractClassDoesNotFailWhenFakingInterfaces(): void
110127
{
111128
$mock = $this->generator->getMockForAbstractClass(Countable::class);
112129

113-
$this->assertTrue(\method_exists($mock, 'count'));
130+
$this->assertTrue(method_exists($mock, 'count'));
114131
}
115132

116133
public function testGetMockForAbstractClassStubbingAbstractClass(): void
117134
{
118135
$mock = $this->generator->getMockForAbstractClass(AbstractMockTestClass::class);
119136

120-
$this->assertTrue(\method_exists($mock, 'doSomething'));
137+
$this->assertTrue(method_exists($mock, 'doSomething'));
121138
}
122139

123140
public function testGetMockForAbstractClassWithNonExistentMethods(): void
@@ -132,8 +149,8 @@ public function testGetMockForAbstractClassWithNonExistentMethods(): void
132149
['nonexistentMethod']
133150
);
134151

135-
$this->assertTrue(\method_exists($mock, 'nonexistentMethod'));
136-
$this->assertTrue(\method_exists($mock, 'doSomething'));
152+
$this->assertTrue(method_exists($mock, 'nonexistentMethod'));
153+
$this->assertTrue(method_exists($mock, 'doSomething'));
137154
}
138155

139156
public function testGetMockForAbstractClassShouldCreateStubsOnlyForAbstractMethodWhenNoMethodsWereInformed(): void
@@ -167,8 +184,8 @@ public function testGetMockForTraitWithNonExistentMethodsAndNonAbstractMethods()
167184
['nonexistentMethod']
168185
);
169186

170-
$this->assertTrue(\method_exists($mock, 'nonexistentMethod'));
171-
$this->assertTrue(\method_exists($mock, 'doSomething'));
187+
$this->assertTrue(method_exists($mock, 'nonexistentMethod'));
188+
$this->assertTrue(method_exists($mock, 'doSomething'));
172189
$this->assertTrue($mock->mockableMethod());
173190
$this->assertTrue($mock->anotherMockableMethod());
174191
}
@@ -177,7 +194,7 @@ public function testGetMockForTraitStubbingAbstractMethod(): void
177194
{
178195
$mock = $this->generator->getMockForTrait(AbstractTrait::class);
179196

180-
$this->assertTrue(\method_exists($mock, 'doSomething'));
197+
$this->assertTrue(method_exists($mock, 'doSomething'));
181198
}
182199

183200
public function testGetMockForTraitWithNonExistantTrait(): void
@@ -226,7 +243,7 @@ public function testCanImplementInterfacesThatHaveMethodsWithReturnTypes(): void
226243

227244
public function testCanConfigureMethodsForDoubleOfNonExistentClass(): void
228245
{
229-
$className = 'X' . \md5(\microtime());
246+
$className = 'X' . md5(microtime());
230247

231248
$mock = $this->generator->getMock($className, ['someMethod']);
232249

@@ -235,7 +252,7 @@ public function testCanConfigureMethodsForDoubleOfNonExistentClass(): void
235252

236253
public function testCanInvokeMethodsOfNonExistentClass(): void
237254
{
238-
$className = 'X' . \md5(\microtime());
255+
$className = 'X' . md5(microtime());
239256

240257
$mock = $this->generator->getMock($className, ['someMethod']);
241258

tests/unit/Framework/MockObject/Matcher/ConsecutiveParametersTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10+
namespace PHPUnit\Framework\MockObject;
11+
1012
use PHPUnit\Framework\ExpectationFailedException;
1113
use PHPUnit\Framework\InvalidParameterGroupException;
1214
use PHPUnit\Framework\TestCase;
15+
use stdClass;
1316

1417
/**
1518
* @small

tests/unit/Framework/MockObject/MockBuilderTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
use PHPUnit\Framework\MockObject\MockBuilder;
10+
namespace PHPUnit\Framework\MockObject;
11+
12+
use ACustomClassName;
13+
use Mockable;
1114
use PHPUnit\Framework\TestCase;
1215

1316
/**

0 commit comments

Comments
 (0)