Skip to content

Commit e15d6fb

Browse files
authoredMar 11, 2025··
Merge pull request #1264 from abraham/phpunit
Fix Phpunit deprecations
2 parents d3aba69 + 84d37ca commit e15d6fb

5 files changed

+62
-44
lines changed
 

‎tests/TwitterOAuthLastTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testLastResult()
3636
$this->twitter->get('search/tweets', ['q' => 'twitter']);
3737
$this->assertEquals('search/tweets', $this->twitter->getLastApiPath());
3838
$this->assertEquals(200, $this->twitter->getLastHttpCode());
39-
$this->assertObjectHasAttribute(
39+
$this->assertObjectHasProperty(
4040
'statuses',
4141
$this->twitter->getLastBody(),
4242
);

‎tests/TwitterOAuthMediaTest.php

+19-13
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testPostStatusesUpdateWithMedia()
4040
'media' => $file_path,
4141
]);
4242
$this->assertEquals(200, $this->twitter->getLastHttpCode());
43-
$this->assertObjectHasAttribute('media_id_string', $result);
43+
$this->assertObjectHasProperty('media_id_string', $result);
4444
$parameters = [
4545
'status' => 'Hello World ' . MOCK_TIME,
4646
'media_ids' => $result->media_id_string,
@@ -78,7 +78,7 @@ public function testPostStatusesUpdateWithMediaChunked()
7878
['chunkedUpload' => true],
7979
);
8080
$this->assertEquals(201, $this->twitter->getLastHttpCode());
81-
$this->assertObjectHasAttribute('media_id_string', $result);
81+
$this->assertObjectHasProperty('media_id_string', $result);
8282
$parameters = [
8383
'status' => 'Hello World ' . MOCK_TIME,
8484
'media_ids' => $result->media_id_string,
@@ -94,16 +94,22 @@ public function testPostStatusesUpdateWithMediaChunked()
9494
*/
9595
public function testPostStatusesUpdateWithMediaChunkedException()
9696
{
97-
$this->expectException(
98-
\Abraham\TwitterOAuth\TwitterOAuthException::class,
99-
);
100-
$this->expectErrorMessage('Missing "media_id_string"');
101-
// Video source http://www.sample-videos.com/
102-
$file_path = __DIR__ . '/video.mp4';
103-
$result = $this->twitter->upload(
104-
'media/upload',
105-
['media' => $file_path, 'media_type' => 'video/mp4'],
106-
['chunkedUpload' => true],
107-
);
97+
$caught = false;
98+
try {
99+
// Video source http://www.sample-videos.com/
100+
$file_path = __DIR__ . '/video.mp4';
101+
$result = $this->twitter->upload(
102+
'media/upload',
103+
['media' => $file_path, 'media_type' => 'video/mp4'],
104+
['chunkedUpload' => true],
105+
);
106+
} catch (\Abraham\TwitterOAuth\TwitterOAuthException $e) {
107+
$this->assertStringContainsString(
108+
'Missing "media_id_string"',
109+
$e->getMessage(),
110+
);
111+
$caught = true;
112+
}
113+
assert($caught);
108114
}
109115
}

‎tests/TwitterOAuthOAuthTest.php

+40-28
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ protected function setUp(): void
3030

3131
public function testBuildClient()
3232
{
33-
$this->assertObjectHasAttribute('consumer', $this->twitter);
34-
$this->assertObjectHasAttribute('token', $this->twitter);
33+
$this->assertObjectHasProperty('consumer', $this->twitter);
34+
$this->assertObjectHasProperty('token', $this->twitter);
3535
}
3636

3737
/**
@@ -42,8 +42,8 @@ public function testSetOauthToken()
4242
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
4343
$twitter->setApiVersion('1.1');
4444
$twitter->setOauthToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
45-
$this->assertObjectHasAttribute('consumer', $twitter);
46-
$this->assertObjectHasAttribute('token', $twitter);
45+
$this->assertObjectHasProperty('consumer', $twitter);
46+
$this->assertObjectHasProperty('token', $twitter);
4747
$twitter->get('friendships/show', [
4848
'target_screen_name' => 'twitterapi',
4949
]);
@@ -60,8 +60,8 @@ public function testOauth2Token()
6060
'grant_type' => 'client_credentials',
6161
]);
6262
$this->assertEquals(200, $twitter->getLastHttpCode());
63-
$this->assertObjectHasAttribute('token_type', $result);
64-
$this->assertObjectHasAttribute('access_token', $result);
63+
$this->assertObjectHasProperty('token_type', $result);
64+
$this->assertObjectHasProperty('access_token', $result);
6565
$this->assertEquals('bearer', $result->token_type);
6666
return $result;
6767
}
@@ -98,7 +98,7 @@ public function testOauth2TokenInvalidate($accessToken)
9898
'access_token' => urldecode($accessToken->access_token),
9999
]);
100100
$this->assertEquals(200, $twitter->getLastHttpCode());
101-
$this->assertObjectHasAttribute('access_token', $result);
101+
$this->assertObjectHasProperty('access_token', $result);
102102
}
103103

104104
/**
@@ -123,14 +123,20 @@ public function testOauthRequestToken()
123123
*/
124124
public function testOauthRequestTokenException()
125125
{
126-
$this->expectException(
127-
\Abraham\TwitterOAuth\TwitterOAuthException::class,
128-
);
129-
$this->expectErrorMessage('Could not authenticate you');
130-
$twitter = new TwitterOAuth('CONSUMER_KEY', 'CONSUMER_SECRET');
131-
$result = $twitter->oauth('oauth/request_token', [
132-
'oauth_callback' => OAUTH_CALLBACK,
133-
]);
126+
$caught = false;
127+
try {
128+
$twitter = new TwitterOAuth('CONSUMER_KEY', 'CONSUMER_SECRET');
129+
$result = $twitter->oauth('oauth/request_token', [
130+
'oauth_callback' => OAUTH_CALLBACK,
131+
]);
132+
} catch (\Abraham\TwitterOAuth\TwitterOAuthException $e) {
133+
$this->assertStringContainsString(
134+
'Could not authenticate you',
135+
$e->getMessage(),
136+
);
137+
$caught = true;
138+
}
139+
assert($caught);
134140
}
135141

136142
/**
@@ -140,19 +146,25 @@ public function testOauthRequestTokenException()
140146
public function testOauthAccessTokenTokenException(array $requestToken)
141147
{
142148
// Can't test this without a browser logging into Twitter so check for the correct error instead.
143-
$this->expectException(
144-
\Abraham\TwitterOAuth\TwitterOAuthException::class,
145-
);
146-
$this->expectErrorMessage('Invalid oauth_verifier parameter');
147-
$twitter = new TwitterOAuth(
148-
CONSUMER_KEY,
149-
CONSUMER_SECRET,
150-
$requestToken['oauth_token'],
151-
$requestToken['oauth_token_secret'],
152-
);
153-
$twitter->oauth('oauth/access_token', [
154-
'oauth_verifier' => 'fake_oauth_verifier',
155-
]);
149+
$caught = false;
150+
try {
151+
$twitter = new TwitterOAuth(
152+
CONSUMER_KEY,
153+
CONSUMER_SECRET,
154+
$requestToken['oauth_token'],
155+
$requestToken['oauth_token_secret'],
156+
);
157+
$twitter->oauth('oauth/access_token', [
158+
'oauth_verifier' => 'fake_oauth_verifier',
159+
]);
160+
} catch (\Abraham\TwitterOAuth\TwitterOAuthException $e) {
161+
$this->assertStringContainsString(
162+
'Invalid oauth_verifier parameter',
163+
$e->getMessage(),
164+
);
165+
$caught = true;
166+
}
167+
assert($caught);
156168
}
157169

158170
public function testUrl()

‎tests/TwitterOAuthProxyTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public function testSetProxy()
4141
$this->twitter->setTimeouts(60, 60);
4242
$result = $this->twitter->get('account/verify_credentials');
4343
$this->assertEquals(200, $this->twitter->getLastHttpCode());
44-
$this->assertObjectHasAttribute('id', $result);
44+
$this->assertObjectHasProperty('id', $result);
4545
}
4646
}

‎tests/TwitterOAuthTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public function testGetAccountVerifyCredentials()
3838
'include_email' => true,
3939
]);
4040
$this->assertEquals(200, $this->twitter->getLastHttpCode());
41-
$this->assertObjectHasAttribute('email', $user);
41+
$this->assertObjectHasProperty('email', $user);
4242
}
4343
}

0 commit comments

Comments
 (0)
Please sign in to comment.