Skip to content

Commit

Permalink
Use ::class keyword when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 11, 2021
1 parent 8c5e45d commit 0da0af2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Tests/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testInstantiationThrowsExceptionIfRawCookieNameContainsSpecialCh
*/
public function testWithRawThrowsExceptionIfCookieNameContainsSpecialCharacters($name)
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
Cookie::create($name)->withRaw();
}

Expand Down
26 changes: 13 additions & 13 deletions Tests/JsonResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testCreate()
{
$response = JsonResponse::create(['foo' => 'bar'], 204);

$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertEquals('{"foo":"bar"}', $response->getContent());
$this->assertEquals(204, $response->getStatusCode());
}
Expand All @@ -108,7 +108,7 @@ public function testCreate()
public function testStaticCreateEmptyJsonObject()
{
$response = JsonResponse::create();
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertSame('{}', $response->getContent());
}

Expand All @@ -118,7 +118,7 @@ public function testStaticCreateEmptyJsonObject()
public function testStaticCreateJsonArray()
{
$response = JsonResponse::create([0, 1, 2, 3]);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertSame('[0,1,2,3]', $response->getContent());
}

Expand All @@ -128,7 +128,7 @@ public function testStaticCreateJsonArray()
public function testStaticCreateJsonObject()
{
$response = JsonResponse::create(['foo' => 'bar']);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertSame('{"foo":"bar"}', $response->getContent());
}

Expand All @@ -138,20 +138,20 @@ public function testStaticCreateJsonObject()
public function testStaticCreateWithSimpleTypes()
{
$response = JsonResponse::create('foo');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertSame('"foo"', $response->getContent());

$response = JsonResponse::create(0);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertSame('0', $response->getContent());

$response = JsonResponse::create(0.1);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertEquals(0.1, $response->getContent());
$this->assertIsString($response->getContent());

$response = JsonResponse::create(true);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertSame('true', $response->getContent());
}

Expand Down Expand Up @@ -236,22 +236,22 @@ public function testItAcceptsJsonAsString()

public function testSetCallbackInvalidIdentifier()
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$response = new JsonResponse('foo');
$response->setCallback('+invalid');
}

public function testSetContent()
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
new JsonResponse("\xB1\x31");
}

public function testSetContentJsonSerializeError()
{
$this->expectException('Exception');
$this->expectException(\Exception::class);
$this->expectExceptionMessage('This error is expected');
if (!interface_exists('JsonSerializable', false)) {
if (!interface_exists(\JsonSerializable::class, false)) {
$this->markTestSkipped('JsonSerializable is required.');
}

Expand Down Expand Up @@ -299,7 +299,7 @@ public function testConstructorWithObjectWithoutToStringMethodThrowsAnException(
}
}

if (interface_exists('JsonSerializable', false)) {
if (interface_exists(\JsonSerializable::class, false)) {
class JsonSerializableObject implements \JsonSerializable
{
public function jsonSerialize()
Expand Down
6 changes: 3 additions & 3 deletions Tests/RedirectResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function testGenerateMetaRedirect()

public function testRedirectResponseConstructorEmptyUrl()
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot redirect to an empty URL.');
new RedirectResponse('');
}

public function testRedirectResponseConstructorWrongStatusCode()
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
new RedirectResponse('foo.bar', 404);
}

Expand Down Expand Up @@ -66,7 +66,7 @@ public function testCreate()
{
$response = RedirectResponse::create('foo', 301);

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertEquals(301, $response->getStatusCode());
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testCreate()
{
$response = Response::create('foo', 301, ['Foo' => 'bar']);

$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(301, $response->getStatusCode());
$this->assertEquals('bar', $response->headers->get('foo'));
}
Expand Down Expand Up @@ -614,7 +614,7 @@ public function testSetCache()
$response->setCache(['wrong option' => 'value']);
$this->fail('->setCache() throws an InvalidArgumentException if an option is not supported');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '->setCache() throws an InvalidArgumentException if an option is not supported');
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->setCache() throws an InvalidArgumentException if an option is not supported');
$this->assertStringContainsString('"wrong option"', $e->getMessage());
}

Expand Down
18 changes: 9 additions & 9 deletions Tests/Session/Storage/NativeSessionStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public function testBag()

public function testRegisterBagException()
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$storage = $this->getStorage();
$storage->getBag('non_existing');
}

public function testRegisterBagForAStartedSessionThrowsException()
{
$this->expectException('LogicException');
$this->expectException(\LogicException::class);
$storage = $this->getStorage();
$storage->start();
$storage->registerBag(new AttributeBag());
Expand Down Expand Up @@ -210,22 +210,22 @@ public function testSetSaveHandler()
$this->iniSet('session.save_handler', 'files');
$storage = $this->getStorage();
$storage->setSaveHandler();
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(null);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new SessionHandlerProxy(new NativeFileSessionHandler()));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new NativeFileSessionHandler());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new SessionHandlerProxy(new NullSessionHandler()));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
$storage->setSaveHandler(new NullSessionHandler());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy', $storage->getSaveHandler());
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
}

public function testStarted()
{
$this->expectException('RuntimeException');
$this->expectException(\RuntimeException::class);
$storage = $this->getStorage();

$this->assertFalse($storage->getSaveHandler()->isActive());
Expand Down

0 comments on commit 0da0af2

Please sign in to comment.