Skip to content

Commit 371dacb

Browse files
committed
use class constants
1 parent 3a05322 commit 371dacb

9 files changed

+44
-28
lines changed

spec/Request/HandlerSpec.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
use PhpSpec\ObjectBehavior;
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\ResponseInterface;
10+
use Xabbuh\XApi\Common\Exception\AccessDeniedException;
11+
use Xabbuh\XApi\Common\Exception\ConflictException;
12+
use Xabbuh\XApi\Common\Exception\NotFoundException;
13+
use Xabbuh\XApi\Common\Exception\XApiException;
1014

1115
class HandlerSpec extends ObjectBehavior
1216
{
@@ -70,7 +74,7 @@ function it_throws_an_access_denied_exception_when_a_401_status_code_is_returned
7074
$response->getStatusCode()->willReturn(401);
7175
$response->getBody()->willReturn('body');
7276

73-
$this->shouldThrow('Xabbuh\XApi\Common\Exception\AccessDeniedException')->during('executeRequest', array($request, array(200)));
77+
$this->shouldThrow(AccessDeniedException::class)->during('executeRequest', array($request, array(200)));
7478
}
7579

7680
function it_throws_an_access_denied_exception_when_a_403_status_code_is_returned(HttpClient $client, RequestInterface $request, ResponseInterface $response)
@@ -79,7 +83,7 @@ function it_throws_an_access_denied_exception_when_a_403_status_code_is_returned
7983
$response->getStatusCode()->willReturn(403);
8084
$response->getBody()->willReturn('body');
8185

82-
$this->shouldThrow('Xabbuh\XApi\Common\Exception\AccessDeniedException')->during('executeRequest', array($request, array(200)));
86+
$this->shouldThrow(AccessDeniedException::class)->during('executeRequest', array($request, array(200)));
8387
}
8488

8589
function it_throws_a_not_found_exception_when_a_404_status_code_is_returned(HttpClient $client, RequestInterface $request, ResponseInterface $response)
@@ -88,7 +92,7 @@ function it_throws_a_not_found_exception_when_a_404_status_code_is_returned(Http
8892
$response->getStatusCode()->willReturn(404);
8993
$response->getBody()->willReturn('body');
9094

91-
$this->shouldThrow('Xabbuh\XApi\Common\Exception\NotFoundException')->during('executeRequest', array($request, array(200)));
95+
$this->shouldThrow(NotFoundException::class)->during('executeRequest', array($request, array(200)));
9296
}
9397

9498
function it_throws_a_conflict_exception_when_a_409_status_code_is_returned(HttpClient $client, RequestInterface $request, ResponseInterface $response)
@@ -97,7 +101,7 @@ function it_throws_a_conflict_exception_when_a_409_status_code_is_returned(HttpC
97101
$response->getStatusCode()->willReturn(409);
98102
$response->getBody()->willReturn('body');
99103

100-
$this->shouldThrow('Xabbuh\XApi\Common\Exception\ConflictException')->during('executeRequest', array($request, array(200)));
104+
$this->shouldThrow(ConflictException::class)->during('executeRequest', array($request, array(200)));
101105
}
102106

103107
function it_throws_an_xapi_exception_when_an_unexpected_status_code_is_returned(HttpClient $client, RequestInterface $request, ResponseInterface $response)
@@ -106,7 +110,7 @@ function it_throws_an_xapi_exception_when_an_unexpected_status_code_is_returned(
106110
$response->getStatusCode()->willReturn(204);
107111
$response->getBody()->willReturn('body');
108112

109-
$this->shouldThrow('Xabbuh\XApi\Common\Exception\XApiException')->during('executeRequest', array($request, array(200)));
113+
$this->shouldThrow(XApiException::class)->during('executeRequest', array($request, array(200)));
110114
}
111115

112116
function it_returns_the_response_on_success(HttpClient $client, RequestInterface $request, ResponseInterface $response)

spec/XApiClientBuilderSpec.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88
use Http\Message\RequestFactory;
99
use PhpSpec\Exception\Example\SkippingException;
1010
use PhpSpec\ObjectBehavior;
11+
use Xabbuh\Http\Authentication\OAuth1;
12+
use Xabbuh\XApi\Client\XApiClientBuilderInterface;
13+
use Xabbuh\XApi\Client\XApiClientInterface;
1114

1215
class XApiClientBuilderSpec extends ObjectBehavior
1316
{
1417
function it_is_an_xapi_client_builder()
1518
{
16-
$this->shouldHaveType('Xabbuh\XApi\Client\XApiClientBuilderInterface');
19+
$this->shouldHaveType(XApiClientBuilderInterface::class);
1720
}
1821

1922
function it_creates_an_xapi_client(HttpClient $httpClient, RequestFactory $requestFactory)
2023
{
2124
$this->setHttpClient($httpClient);
2225
$this->setRequestFactory($requestFactory);
2326
$this->setBaseUrl('http://example.com/xapi/');
24-
$this->build()->shouldHaveType('Xabbuh\XApi\Client\XApiClientInterface');
27+
$this->build()->shouldHaveType(XApiClientInterface::class);
2528
}
2629

2730
function its_methods_can_be_chained(HttpClient $httpClient, RequestFactory $requestFactory)
@@ -60,8 +63,8 @@ function it_throws_an_exception_if_the_request_factory_is_not_configured(HttpCli
6063

6164
function it_can_build_the_client_when_it_is_able_to_discover_the_http_client_and_the_request_factory_without_configuring_them_explicitly()
6265
{
63-
if (!class_exists('\Http\Discovery\HttpClientDiscovery')) {
64-
throw new SkippingException('The "\Http\Discovery\HttpClientDiscovery" class is required to let the builder auto discover the HTTP client and request factory.');
66+
if (!class_exists(HttpClientDiscovery::class)) {
67+
throw new SkippingException(sprintf('The "%s" class is required to let the builder auto discover the HTTP client and request factory.', HttpClientDiscovery::class));
6568
}
6669

6770
if (!$this->isAbleToDiscoverHttpClient()) {
@@ -74,7 +77,7 @@ function it_can_build_the_client_when_it_is_able_to_discover_the_http_client_and
7477

7578
$this->setBaseUrl('http://example.com/xapi/');
7679

77-
$this->build()->shouldReturnAnInstanceOf('\Xabbuh\XApi\Client\XApiClientInterface');
80+
$this->build()->shouldReturnAnInstanceOf(XApiClientInterface::class);
7881
}
7982

8083
function it_throws_an_exception_if_the_base_uri_is_not_configured(HttpClient $httpClient, RequestFactory $requestFactory)
@@ -87,7 +90,7 @@ function it_throws_an_exception_if_the_base_uri_is_not_configured(HttpClient $ht
8790

8891
function it_throws_an_exception_when_oauth_credentials_are_configured_but_the_auth_package_is_missing(HttpClient $httpClient, RequestFactory $requestFactory)
8992
{
90-
if (class_exists('Xabbuh\Http\Authentication\OAuth1')) {
93+
if (class_exists(OAuth1::class)) {
9194
throw new SkippingException('OAuth1 credentials can be used when the "xabbuh/oauth1-authentication" package is present.');
9295
}
9396

@@ -101,7 +104,7 @@ function it_throws_an_exception_when_oauth_credentials_are_configured_but_the_au
101104

102105
function it_accepts_oauth_credentials_when_the_auth_package_is_present(HttpClient $httpClient, RequestFactory $requestFactory)
103106
{
104-
if (!class_exists('Xabbuh\Http\Authentication\OAuth1')) {
107+
if (!class_exists(OAuth1::class)) {
105108
throw new SkippingException('OAuth1 credentials cannot be used when the "xabbuh/oauth1-authentication" package is missing.');
106109
}
107110

spec/XApiClientSpec.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
namespace spec\Xabbuh\XApi\Client;
44

55
use PhpSpec\ObjectBehavior;
6+
use Xabbuh\XApi\Client\Api\ActivityProfileApiClientInterface;
7+
use Xabbuh\XApi\Client\Api\AgentProfileApiClientInterface;
8+
use Xabbuh\XApi\Client\Api\StateApiClientInterface;
9+
use Xabbuh\XApi\Client\Api\StatementsApiClientInterface;
610
use Xabbuh\XApi\Client\Request\HandlerInterface;
711
use Xabbuh\XApi\Serializer\ActorSerializerInterface;
812
use Xabbuh\XApi\Serializer\DocumentDataSerializerInterface;
@@ -30,21 +34,21 @@ function let(
3034

3135
function it_returns_a_statements_api_client_instance()
3236
{
33-
$this->getStatementsApiClient()->shouldBeAnInstanceOf('\Xabbuh\XApi\Client\Api\StatementsApiClientInterface');
37+
$this->getStatementsApiClient()->shouldBeAnInstanceOf(StatementsApiClientInterface::class);
3438
}
3539

3640
function it_returns_an_activity_profile_api_client_instance()
3741
{
38-
$this->getActivityProfileApiClient()->shouldBeAnInstanceOf('\Xabbuh\XApi\Client\Api\ActivityProfileApiClientInterface');
42+
$this->getActivityProfileApiClient()->shouldBeAnInstanceOf(ActivityProfileApiClientInterface::class);
3943
}
4044

4145
function it_returns_an_agent_profile_api_client_instance()
4246
{
43-
$this->getAgentProfileApiClient()->shouldBeAnInstanceOf('\Xabbuh\XApi\Client\Api\AgentProfileApiClientInterface');
47+
$this->getAgentProfileApiClient()->shouldBeAnInstanceOf(AgentProfileApiClientInterface::class);
4448
}
4549

4650
function it_returns_a_state_api_client_instance()
4751
{
48-
$this->getStateApiClient()->shouldBeAnInstanceOf('\Xabbuh\XApi\Client\Api\StateApiClientInterface');
52+
$this->getStateApiClient()->shouldBeAnInstanceOf(StateApiClientInterface::class);
4953
}
5054
}

src/XApiClientBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function setOAuthCredentials($consumerKey, $consumerSecret, $token, $toke
131131
*/
132132
public function build()
133133
{
134-
if (null === $this->httpClient && class_exists('\Http\Discovery\HttpClientDiscovery')) {
134+
if (null === $this->httpClient && class_exists(HttpClientDiscovery::class)) {
135135
try {
136136
$this->httpClient = HttpClientDiscovery::find();
137137
} catch (\Exception $e) {
@@ -142,7 +142,7 @@ public function build()
142142
throw new \LogicException('No HTTP client was configured.');
143143
}
144144

145-
if (null === $this->requestFactory && class_exists('\Http\Discovery\MessageFactoryDiscovery')) {
145+
if (null === $this->requestFactory && class_exists(MessageFactoryDiscovery::class)) {
146146
try {
147147
$this->requestFactory = MessageFactoryDiscovery::find();
148148
} catch (\Exception $e) {
@@ -170,7 +170,7 @@ public function build()
170170
}
171171

172172
if (null !== $this->consumerKey && null !== $this->consumerSecret && null !== $this->accessToken && null !== $this->tokenSecret) {
173-
if (!class_exists('Xabbuh\Http\Authentication\OAuth1')) {
173+
if (!class_exists(OAuth1::class)) {
174174
throw new \LogicException('The "xabbuh/oauth1-authentication package is needed to use OAuth1 authorization.');
175175
}
176176

tests/Api/ActivityProfileApiClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Xabbuh\XApi\DataFixtures\DocumentFixtures;
1616
use Xabbuh\XApi\Model\Activity;
1717
use Xabbuh\XApi\Model\ActivityProfile;
18+
use Xabbuh\XApi\Model\ActivityProfileDocument;
1819
use Xabbuh\XApi\Model\IRI;
1920
use Xabbuh\XApi\Serializer\Symfony\DocumentDataSerializer;
2021

@@ -113,7 +114,7 @@ public function testGetDocument()
113114

114115
$document = $this->client->getDocument($activityProfile);
115116

116-
$this->assertInstanceOf('Xabbuh\XApi\Model\ActivityProfileDocument', $document);
117+
$this->assertInstanceOf(ActivityProfileDocument::class, $document);
117118
$this->assertEquals($activityProfile, $document->getActivityProfile());
118119
}
119120

tests/Api/AgentProfileApiClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Xabbuh\XApi\DataFixtures\DocumentFixtures;
1616
use Xabbuh\XApi\Model\Agent;
1717
use Xabbuh\XApi\Model\AgentProfile;
18+
use Xabbuh\XApi\Model\AgentProfileDocument;
1819
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
1920
use Xabbuh\XApi\Model\IRI;
2021
use Xabbuh\XApi\Serializer\Symfony\ActorSerializer;
@@ -123,7 +124,7 @@ public function testGetDocument()
123124

124125
$document = $this->client->getDocument($profile);
125126

126-
$this->assertInstanceOf('Xabbuh\XApi\Model\AgentProfileDocument', $document);
127+
$this->assertInstanceOf(AgentProfileDocument::class, $document);
127128
$this->assertEquals($profile, $document->getAgentProfile());
128129
}
129130

tests/Api/ApiClientTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Xabbuh\XApi\Client\Tests\Api;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Psr\Http\Message\RequestInterface;
16+
use Psr\Http\Message\ResponseInterface;
1517
use Symfony\Component\Serializer\SerializerInterface;
1618
use Xabbuh\XApi\Client\Request\HandlerInterface;
1719
use Xabbuh\XApi\Common\Exception\NotFoundException;
@@ -43,8 +45,8 @@ abstract class ApiClientTest extends TestCase
4345

4446
protected function setUp()
4547
{
46-
$this->requestHandler = $this->getMockBuilder('\Xabbuh\XApi\Client\Request\HandlerInterface')->getMock();
47-
$this->serializer = $this->getMockBuilder('\Symfony\Component\Serializer\SerializerInterface')->getMock();
48+
$this->requestHandler = $this->getMockBuilder(HandlerInterface::class)->getMock();
49+
$this->serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
4850
$this->serializerRegistry = $this->createSerializerRegistry();
4951
}
5052

@@ -78,7 +80,7 @@ protected function validateSerializer(array $serializerMap)
7880

7981
protected function validateRequest($method, $uri, array $urlParameters, $body = null)
8082
{
81-
$request = $this->getMockBuilder('\Psr\Http\Message\RequestInterface')->getMock();
83+
$request = $this->getMockBuilder(RequestInterface::class)->getMock();
8284
$this
8385
->requestHandler
8486
->expects($this->once())
@@ -92,7 +94,7 @@ protected function validateRequest($method, $uri, array $urlParameters, $body =
9294
protected function validateRetrieveApiCall($method, $uri, array $urlParameters, $statusCode, $type, $transformedResult, array $serializerMap = array())
9395
{
9496
$rawResponse = 'the-server-response';
95-
$response = $this->getMockBuilder('\Psr\Http\Message\ResponseInterface')->getMock();
97+
$response = $this->getMockBuilder(ResponseInterface::class)->getMock();
9698
$response->expects($this->any())->method('getStatusCode')->willReturn($statusCode);
9799
$response->expects($this->any())->method('getHeader')->with('Content-Type')->willReturn(array('application/json'));
98100
$response->expects($this->any())->method('getBody')->willReturn($rawResponse);
@@ -128,7 +130,7 @@ protected function validateRetrieveApiCall($method, $uri, array $urlParameters,
128130
protected function validateStoreApiCall($method, $uri, array $urlParameters, $statusCode, $rawResponse, $object, array $serializerMap = array())
129131
{
130132
$rawRequest = 'the-request-body';
131-
$response = $this->getMockBuilder('\Psr\Http\Message\ResponseInterface')->getMock();
133+
$response = $this->getMockBuilder(ResponseInterface::class)->getMock();
132134
$response->expects($this->any())->method('getStatusCode')->willReturn($statusCode);
133135
$response->expects($this->any())->method('getBody')->willReturn($rawResponse);
134136
$request = $this->validateRequest($method, $uri, $urlParameters, $rawRequest);

tests/Api/StateApiClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
1919
use Xabbuh\XApi\Model\IRI;
2020
use Xabbuh\XApi\Model\State;
21+
use Xabbuh\XApi\Model\StateDocument;
2122
use Xabbuh\XApi\Serializer\Symfony\ActorSerializer;
2223
use Xabbuh\XApi\Serializer\Symfony\DocumentDataSerializer;
2324

@@ -124,7 +125,7 @@ public function testGetDocument()
124125

125126
$document = $this->client->getDocument($state);
126127

127-
$this->assertInstanceOf('Xabbuh\XApi\Model\StateDocument', $document);
128+
$this->assertInstanceOf(StateDocument::class, $document);
128129
$this->assertEquals($state, $document->getState());
129130
}
130131

tests/Api/StatementsApiClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public function testGetNextStatements()
344344

345345
$statementResult = $this->client->getNextStatements($previousStatementResult);
346346

347-
$this->assertInstanceOf('\Xabbuh\XApi\Model\StatementResult', $statementResult);
347+
$this->assertInstanceOf(StatementResult::class, $statementResult);
348348
}
349349

350350
/**

0 commit comments

Comments
 (0)