Skip to content

Commit 58b7d87

Browse files
localheinzsebastianbergmann
authored andcommitted
Fix: Do not declare test classes in global namespace
1 parent 30bb652 commit 58b7d87

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

tests/unit/Framework/ExecutionOrderDependencyTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
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\ExecutionOrderDependency;
11-
use PHPUnit\Framework\TestCase;
10+
namespace PHPUnit\Framework;
1211

1312
/**
1413
* @covers \PHPUnit\Framework\ExecutionOrderDependency

tests/unit/Framework/MockObject/MockBuilderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
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\CannotUseAddMethodsException;
11-
use PHPUnit\Framework\MockObject\CannotUseOnlyMethodsException;
12-
use PHPUnit\Framework\MockObject\MockBuilder;
10+
namespace PHPUnit\Framework\MockObject;
11+
12+
use ACustomClassName;
1313
use PHPUnit\Framework\TestCase;
1414
use PHPUnit\TestFixture\Mockable;
1515

tests/unit/Framework/MockObject/MockObjectTest.php

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
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+
12+
use function class_uses;
13+
use function func_get_args;
14+
use function get_class;
15+
use function get_parent_class;
16+
use Exception;
17+
use Foo;
1018
use PHPUnit\Framework\ExpectationFailedException;
11-
use PHPUnit\Framework\MockObject\MockObject;
12-
use PHPUnit\Framework\MockObject\ReturnValueNotConfiguredException;
13-
use PHPUnit\Framework\MockObject\Stub;
1419
use PHPUnit\Framework\TestCase;
1520
use PHPUnit\TestFixture\AbstractTrait;
1621
use PHPUnit\TestFixture\AnInterface;
@@ -31,6 +36,10 @@
3136
use PHPUnit\TestFixture\StringableClass;
3237
use PHPUnit\TestFixture\TraitWithConstructor;
3338
use PHPUnit\TestFixture\TraversableMockTestInterface;
39+
use ReflectionObject;
40+
use RuntimeException;
41+
use stdClass;
42+
use Traversable;
3443

3544
/**
3645
* @small
@@ -192,9 +201,9 @@ public function testStubbedException(): void
192201
->getMock();
193202

194203
$mock->method('doSomething')
195-
->will($this->throwException(new \Exception));
204+
->will($this->throwException(new Exception));
196205

197-
$this->expectException(\Exception::class);
206+
$this->expectException(Exception::class);
198207

199208
$mock->doSomething();
200209
}
@@ -205,9 +214,9 @@ public function testStubbedWillThrowException(): void
205214
->getMock();
206215

207216
$mock->method('doSomething')
208-
->willThrowException(new \Exception);
217+
->willThrowException(new Exception);
209218

210-
$this->expectException(\Exception::class);
219+
$this->expectException(Exception::class);
211220

212221
$mock->doSomething();
213222
}
@@ -377,7 +386,7 @@ public function testMockClassOnlyGeneratedOnce(): void
377386
$mock2 = $this->getMockBuilder(AnInterface::class)
378387
->getMock();
379388

380-
$this->assertEquals(\get_class($mock1), \get_class($mock2));
389+
$this->assertEquals(get_class($mock1), get_class($mock2));
381390
}
382391

383392
public function testMockClassDifferentForPartialMocks(): void
@@ -401,14 +410,14 @@ public function testMockClassDifferentForPartialMocks(): void
401410
->onlyMethods(['doAnotherThing'])
402411
->getMock();
403412

404-
$this->assertNotEquals(\get_class($mock1), \get_class($mock2));
405-
$this->assertNotEquals(\get_class($mock1), \get_class($mock3));
406-
$this->assertNotEquals(\get_class($mock1), \get_class($mock4));
407-
$this->assertNotEquals(\get_class($mock1), \get_class($mock5));
408-
$this->assertEquals(\get_class($mock2), \get_class($mock3));
409-
$this->assertNotEquals(\get_class($mock2), \get_class($mock4));
410-
$this->assertNotEquals(\get_class($mock2), \get_class($mock5));
411-
$this->assertEquals(\get_class($mock4), \get_class($mock5));
413+
$this->assertNotEquals(get_class($mock1), get_class($mock2));
414+
$this->assertNotEquals(get_class($mock1), get_class($mock3));
415+
$this->assertNotEquals(get_class($mock1), get_class($mock4));
416+
$this->assertNotEquals(get_class($mock1), get_class($mock5));
417+
$this->assertEquals(get_class($mock2), get_class($mock3));
418+
$this->assertNotEquals(get_class($mock2), get_class($mock4));
419+
$this->assertNotEquals(get_class($mock2), get_class($mock5));
420+
$this->assertEquals(get_class($mock4), get_class($mock5));
412421
}
413422

414423
public function testMockClassStoreOverrulable(): void
@@ -432,15 +441,15 @@ public function testMockClassStoreOverrulable(): void
432441
->setMockClassName('MyMockClassNameForPartialMockTestClass2')
433442
->getMock();
434443

435-
$this->assertNotEquals(\get_class($mock1), \get_class($mock2));
436-
$this->assertEquals(\get_class($mock1), \get_class($mock3));
437-
$this->assertNotEquals(\get_class($mock1), \get_class($mock4));
438-
$this->assertNotEquals(\get_class($mock2), \get_class($mock3));
439-
$this->assertNotEquals(\get_class($mock2), \get_class($mock4));
440-
$this->assertNotEquals(\get_class($mock2), \get_class($mock5));
441-
$this->assertNotEquals(\get_class($mock3), \get_class($mock4));
442-
$this->assertNotEquals(\get_class($mock3), \get_class($mock5));
443-
$this->assertNotEquals(\get_class($mock4), \get_class($mock5));
444+
$this->assertNotEquals(get_class($mock1), get_class($mock2));
445+
$this->assertEquals(get_class($mock1), get_class($mock3));
446+
$this->assertNotEquals(get_class($mock1), get_class($mock4));
447+
$this->assertNotEquals(get_class($mock2), get_class($mock3));
448+
$this->assertNotEquals(get_class($mock2), get_class($mock4));
449+
$this->assertNotEquals(get_class($mock2), get_class($mock5));
450+
$this->assertNotEquals(get_class($mock3), get_class($mock4));
451+
$this->assertNotEquals(get_class($mock3), get_class($mock5));
452+
$this->assertNotEquals(get_class($mock4), get_class($mock5));
444453
}
445454

446455
public function testGetMockWithFixedClassNameCanProduceTheSameMockTwice(): void
@@ -471,7 +480,7 @@ public function testOriginalCloneSettingConsidered(): void
471480
->disableOriginalClone()
472481
->getMock();
473482

474-
$this->assertNotEquals(\get_class($mock1), \get_class($mock2));
483+
$this->assertNotEquals(get_class($mock1), get_class($mock2));
475484
}
476485

477486
/**
@@ -508,8 +517,8 @@ public function testGetMockForTrait(): void
508517
$mock->expects($this->never())
509518
->method('doSomething');
510519

511-
$parent = \get_parent_class($mock);
512-
$traits = \class_uses($parent, false);
520+
$parent = get_parent_class($mock);
521+
$traits = class_uses($parent, false);
513522

514523
$this->assertContains(AbstractTrait::class, $traits);
515524
}
@@ -598,7 +607,7 @@ public function testObjectMethodCallWithArgumentCloningEnabled(): void
598607
$this->returnCallback(
599608
static function () use (&$actualArguments): void
600609
{
601-
$actualArguments = \func_get_args();
610+
$actualArguments = func_get_args();
602611
}
603612
)
604613
);
@@ -626,7 +635,7 @@ public function testObjectMethodCallWithArgumentCloningDisabled(): void
626635
$this->returnCallback(
627636
static function () use (&$actualArguments): void
628637
{
629-
$actualArguments = \func_get_args();
638+
$actualArguments = func_get_args();
630639
}
631640
)
632641
);
@@ -916,7 +925,7 @@ public function testCreateMockFromWsdl(): void
916925

917926
$this->assertStringStartsWith(
918927
'Mock_WsdlMock_',
919-
\get_class($mock)
928+
get_class($mock)
920929
);
921930
}
922931

@@ -929,7 +938,7 @@ public function testCreateNamespacedMockFromWsdl(): void
929938

930939
$this->assertStringStartsWith(
931940
'Mock_WsdlMock_',
932-
\get_class($mock)
941+
get_class($mock)
933942
);
934943
}
935944

@@ -941,8 +950,8 @@ public function testCreateTwoMocksOfOneWsdlFile(): void
941950
$a = $this->getMockFromWsdl(TEST_FILES_PATH . 'GoogleSearch.wsdl');
942951
$b = $this->getMockFromWsdl(TEST_FILES_PATH . 'GoogleSearch.wsdl');
943952

944-
$this->assertStringStartsWith('Mock_GoogleSearch_', \get_class($a));
945-
$this->assertEquals(\get_class($a), \get_class($b));
953+
$this->assertStringStartsWith('Mock_GoogleSearch_', get_class($a));
954+
$this->assertEquals(get_class($a), get_class($b));
946955
}
947956

948957
/**
@@ -954,7 +963,7 @@ public function testCreateMockOfWsdlFileWithSpecialChars(): void
954963
{
955964
$mock = $this->getMockFromWsdl(TEST_FILES_PATH . 'Go ogle-Sea.rch.wsdl');
956965

957-
$this->assertStringStartsWith('Mock_GoogleSearch_', \get_class($mock));
966+
$this->assertStringStartsWith('Mock_GoogleSearch_', get_class($mock));
958967
}
959968

960969
/**
@@ -1073,7 +1082,7 @@ public function testDisableAutomaticReturnValueGeneration(): void
10731082

10741083
public function testDisableAutomaticReturnValueGenerationWithToString(): void
10751084
{
1076-
/** @var PHPUnit\Framework\MockObject\MockObject|StringableClass $mock */
1085+
/** @var \PHPUnit\Framework\MockObject\MockObject|StringableClass $mock */
10771086
$mock = $this->getMockBuilder(StringableClass::class)
10781087
->disableAutoReturnValueGeneration()
10791088
->getMock();

0 commit comments

Comments
 (0)