Skip to content

Commit ee20cac

Browse files
author
Lucas Michot
authored
Avoid using FQCN in tests. (#36656)
1 parent 371e7c4 commit ee20cac

12 files changed

+37
-24
lines changed

tests/Cache/CacheArrayStoreTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Cache\ArrayStore;
66
use Illuminate\Support\Carbon;
77
use PHPUnit\Framework\TestCase;
8+
use stdClass;
89

910
class CacheArrayStoreTest extends TestCase
1011
{
@@ -198,7 +199,7 @@ public function testAnotherOwnerCanForceReleaseALock()
198199
public function testValuesAreNotStoredByReference()
199200
{
200201
$store = new ArrayStore($serialize = true);
201-
$object = new \stdClass;
202+
$object = new stdClass;
202203
$object->foo = true;
203204

204205
$store->put('object', $object, 10);
@@ -210,7 +211,7 @@ public function testValuesAreNotStoredByReference()
210211
public function testValuesAreStoredByReferenceIfSerializationIsDisabled()
211212
{
212213
$store = new ArrayStore;
213-
$object = new \stdClass;
214+
$object = new stdClass;
214215
$object->foo = true;
215216

216217
$store->put('object', $object, 10);

tests/Container/ContainerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPUnit\Framework\TestCase;
1010
use Psr\Container\ContainerExceptionInterface;
1111
use stdClass;
12+
use TypeError;
1213

1314
class ContainerTest extends TestCase
1415
{
@@ -123,7 +124,7 @@ public function testSharedConcreteResolution()
123124

124125
public function testBindFailsLoudlyWithInvalidArgument()
125126
{
126-
$this->expectException(\TypeError::class);
127+
$this->expectException(TypeError::class);
127128
$container = new Container;
128129

129130
$concrete = new ContainerConcreteStub();

tests/Database/DatabaseEloquentFactoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Tests\Database;
44

5+
use Faker\Generator;
56
use Illuminate\Container\Container;
67
use Illuminate\Contracts\Foundation\Application;
78
use Illuminate\Database\Capsule\Manager as DB;
@@ -18,7 +19,7 @@ class DatabaseEloquentFactoryTest extends TestCase
1819
protected function setUp(): void
1920
{
2021
$container = Container::getInstance();
21-
$container->singleton(\Faker\Generator::class, function ($app, $parameters) {
22+
$container->singleton(Generator::class, function ($app, $parameters) {
2223
return \Faker\Factory::create('en_US');
2324
});
2425
$container->instance(Application::class, $app = Mockery::mock(Application::class));

tests/Database/DatabaseTransactionsTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Illuminate\Tests\Database;
44

5+
use Exception;
56
use Illuminate\Database\Capsule\Manager as DB;
67
use Illuminate\Database\DatabaseTransactionsManager;
78
use Mockery as m;
89
use PHPUnit\Framework\TestCase;
10+
use Throwable;
911

1012
class DatabaseTransactionsTest extends TestCase
1113
{
@@ -176,9 +178,9 @@ public function testTransactionIsRolledBack()
176178
'value' => 2,
177179
]);
178180

179-
throw new \Exception;
181+
throw new Exception;
180182
});
181-
} catch (\Throwable $e) {
183+
} catch (Throwable $e) {
182184
}
183185
}
184186

@@ -230,10 +232,10 @@ public function testNestedTransactionsAreRolledBack()
230232
'value' => 2,
231233
]);
232234

233-
throw new \Exception;
235+
throw new Exception;
234236
});
235237
});
236-
} catch (\Throwable $e) {
238+
} catch (Throwable $e) {
237239
}
238240
}
239241

tests/Foundation/Testing/Concerns/InteractsWithContainerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Foundation\Mix;
66
use Orchestra\Testbench\TestCase;
7+
use stdClass;
78

89
class InteractsWithContainerTest extends TestCase
910
{
@@ -17,7 +18,7 @@ public function testWithoutMixBindsEmptyHandlerAndReturnsInstance()
1718

1819
public function testWithMixRestoresOriginalHandlerAndReturnsInstance()
1920
{
20-
$handler = new \stdClass();
21+
$handler = new stdClass();
2122
$this->app->instance(Mix::class, $handler);
2223

2324
$this->withoutMix();

tests/Http/HttpClientTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Support\Collection;
1111
use Illuminate\Support\Str;
1212
use OutOfBoundsException;
13+
use PHPUnit\Framework\AssertionFailedError;
1314
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\VarDumper\VarDumper;
1516

@@ -659,7 +660,7 @@ public function testAssertionsSentOutOfOrderThrowAssertionFailed()
659660
$this->factory->get($exampleUrls[2]);
660661
$this->factory->get($exampleUrls[1]);
661662

662-
$this->expectException(\PHPUnit\Framework\AssertionFailedError::class);
663+
$this->expectException(AssertionFailedError::class);
663664

664665
$this->factory->assertSentInOrder($exampleUrls);
665666
}
@@ -677,7 +678,7 @@ public function testWrongNumberOfRequestsThrowAssertionFailed()
677678
$this->factory->get($exampleUrls[0]);
678679
$this->factory->get($exampleUrls[1]);
679680

680-
$this->expectException(\PHPUnit\Framework\AssertionFailedError::class);
681+
$this->expectException(AssertionFailedError::class);
681682

682683
$this->factory->assertSentInOrder($exampleUrls);
683684
}
@@ -778,7 +779,7 @@ function (Request $request) {
778779
'name' => 'Taylor',
779780
]);
780781

781-
$this->expectException(\PHPUnit\Framework\AssertionFailedError::class);
782+
$this->expectException(AssertionFailedError::class);
782783

783784
$this->factory->assertSentInOrder($executionOrder);
784785
}

tests/Integration/Database/EloquentModelEncryptedCastingTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Support\Collection;
99
use Illuminate\Support\Facades\Crypt;
1010
use Illuminate\Support\Facades\Schema;
11+
use stdClass;
1112

1213
/**
1314
* @group integration
@@ -130,7 +131,7 @@ public function testJsonAttributeIsCastable()
130131

131132
public function testObjectIsCastable()
132133
{
133-
$object = new \stdClass();
134+
$object = new stdClass();
134135
$object->key1 = 'value1';
135136

136137
$this->encrypter->expects('encrypt')
@@ -146,7 +147,7 @@ public function testObjectIsCastable()
146147
'secret_object' => $object,
147148
]);
148149

149-
$this->assertInstanceOf(\stdClass::class, $object->secret_object);
150+
$this->assertInstanceOf(stdClass::class, $object->secret_object);
150151
$this->assertSame('value1', $object->secret_object->key1);
151152
$this->assertDatabaseHas('encrypted_casts', [
152153
'id' => $object->id,

tests/Integration/Database/EloquentModelLoadCountTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Tests\Integration\Database\EloquentModelLoadCountTest;
44

5+
use DB;
56
use Illuminate\Database\Eloquent\Model;
67
use Illuminate\Database\Eloquent\SoftDeletes;
78
use Illuminate\Database\Schema\Blueprint;
@@ -49,23 +50,23 @@ public function testLoadCountSingleRelation()
4950
{
5051
$model = BaseModel::first();
5152

52-
\DB::enableQueryLog();
53+
DB::enableQueryLog();
5354

5455
$model->loadCount('related1');
5556

56-
$this->assertCount(1, \DB::getQueryLog());
57+
$this->assertCount(1, DB::getQueryLog());
5758
$this->assertEquals(2, $model->related1_count);
5859
}
5960

6061
public function testLoadCountMultipleRelations()
6162
{
6263
$model = BaseModel::first();
6364

64-
\DB::enableQueryLog();
65+
DB::enableQueryLog();
6566

6667
$model->loadCount(['related1', 'related2']);
6768

68-
$this->assertCount(1, \DB::getQueryLog());
69+
$this->assertCount(1, DB::getQueryLog());
6970
$this->assertEquals(2, $model->related1_count);
7071
$this->assertEquals(1, $model->related2_count);
7172
}

tests/Integration/Queue/QueueConnectionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Support\Facades\Bus;
1010
use Mockery as m;
1111
use Orchestra\Testbench\TestCase;
12+
use Throwable;
1213

1314
/**
1415
* @group integration
@@ -52,7 +53,7 @@ public function testJobWillGetDispatchedInsideATransactionWhenExplicitlyIndicate
5253

5354
try {
5455
Bus::dispatch((new QueueConnectionTestJob)->beforeCommit());
55-
} catch (\Throwable $e) {
56+
} catch (Throwable $e) {
5657
// This job was dispatched
5758
}
5859
}

tests/Integration/Queue/UniqueJobTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Tests\Integration\Queue;
44

5+
use Exception;
56
use Illuminate\Bus\Queueable;
67
use Illuminate\Contracts\Cache\Repository as Cache;
78
use Illuminate\Contracts\Queue\ShouldBeUnique;
@@ -83,7 +84,7 @@ public function testLockIsReleasedForFailedJobs()
8384
{
8485
UniqueTestFailJob::$handled = false;
8586

86-
$this->expectException(\Exception::class);
87+
$this->expectException(Exception::class);
8788

8889
try {
8990
dispatch($job = new UniqueTestFailJob);
@@ -191,7 +192,7 @@ public function handle()
191192
{
192193
static::$handled = true;
193194

194-
throw new \Exception;
195+
throw new Exception;
195196
}
196197
}
197198

0 commit comments

Comments
 (0)