Skip to content

Commit 216d544

Browse files
Merge pull request #113 from dwightwatson/l12-standalone
Cleanup release for breaking Twitteroauth
2 parents 4569046 + 7867117 commit 216d544

15 files changed

+82
-120
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,12 @@ jobs:
1111
fail-fast: true
1212
matrix:
1313
os: [ubuntu-latest]
14-
php: [8.1, '8.2']
15-
laravel: ['10.*', '11.*', '12.*']
14+
php: [8.2, 8.3, 8.4]
15+
laravel: [12.*']
1616
stability: [prefer-lowest, prefer-stable]
1717
include:
18-
- laravel: 10.*
19-
testbench: 8.*
20-
- laravel: 11.*
21-
testbench: 9.*
2218
- laravel: 12.*
2319
testbench: 10.*
24-
exclude:
25-
- laravel: 11.*
26-
php: 8.1
27-
- laravel: 12.*
28-
php: 8.1
2920

3021
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}
3122

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^8.1",
16-
"abraham/twitteroauth": "^5.0|^6.0|^7.0",
17-
"illuminate/notifications": "^10.0|^11.0|^12.0",
18-
"illuminate/support": "^10.0|^11.0|^12.0",
15+
"php": "^8.4",
16+
"abraham/twitteroauth": "^7.0",
17+
"illuminate/notifications": "^12.0",
18+
"illuminate/support": "^12.0",
1919
"kylewm/brevity": "^0.2.9",
2020
"ext-fileinfo": "*"
2121
},
2222
"require-dev": {
2323
"laravel/pint": "^1.10",
2424
"mockery/mockery": "^1.3.1",
25-
"orchestra/testbench": "^8.0|^9.0|^10.0",
26-
"phpunit/phpunit": "^9.3|^10.5|^11.5.3"
25+
"orchestra/testbench": "^10.0",
26+
"phpunit/phpunit": "^11.5.3"
2727
},
2828
"autoload": {
2929
"psr-4": {

phpunit.xml.dist

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">src/</directory>
6-
</include>
7-
<report>
8-
<clover outputFile="build/logs/clover.xml"/>
9-
<html outputDirectory="build/coverage"/>
10-
<text outputFile="build/coverage.txt"/>
11-
</report>
12-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage/>
134
<testsuites>
14-
<testsuite name="Twitter Test Suite">
5+
<testsuite name="Test Suite">
156
<directory>tests</directory>
167
</testsuite>
178
</testsuites>
18-
<logging>
19-
<junit outputFile="build/report.junit.xml"/>
20-
</logging>
21-
</phpunit>
9+
<source>
10+
<include>
11+
<directory suffix=".php">src/</directory>
12+
</include>
13+
</source>
14+
</phpunit>

src/TwitterChannel.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ class TwitterChannel
1010
{
1111
public function __construct(protected TwitterOAuth $twitter)
1212
{
13+
//
1314
}
1415

1516
/**
1617
* Send the given notification.
1718
*
18-
* @param mixed $notifiable Should be an object that uses the Illuminate\Notifications\Notifiable trait.
19+
* @param mixed $notifiable Should be an object that uses the Illuminate\Notifications\Notifiable trait.
1920
*
2021
* @throws CouldNotSendNotification
2122
*/
@@ -39,7 +40,7 @@ public function send($notifiable, Notification $notification): array|object
3940
$twitterApiResponse = $this->twitter->post(
4041
$twitterMessage->getApiEndpoint(),
4142
$requestBody,
42-
$twitterMessage->isJsonRequest,
43+
['jsonPayload' => $twitterMessage->isJsonRequest],
4344
);
4445

4546
if ($this->twitter->getLastHttpCode() !== 201) {
@@ -52,7 +53,7 @@ public function send($notifiable, Notification $notification): array|object
5253
/**
5354
* Use per user settings instead of default ones.
5455
*
55-
* @param object $notifiable Provide an object that uses the Illuminate\Notifications\Notifiable trait.
56+
* @param object $notifiable Provide an object that uses the Illuminate\Notifications\Notifiable trait.
5657
*/
5758
private function changeTwitterSettingsIfNeeded(object $notifiable)
5859
{
@@ -96,11 +97,15 @@ private function addVideosIfGiven(TwitterMessage $twitterMessage): object
9697
$this->twitter->setTimeouts(10, 15);
9798

9899
$twitterMessage->videoIds = collect($twitterMessage->getVideos())->map(function (TwitterVideo $video) {
99-
$media = $this->twitter->upload('media/upload', [
100-
'media' => $video->getPath(),
101-
'media_category' => 'tweet_video',
102-
'media_type' => $video->getMimeType(),
103-
], true);
100+
$media = $this->twitter->upload(
101+
'media/upload',
102+
[
103+
'media' => $video->getPath(),
104+
'media_category' => 'tweet_video',
105+
'media_type' => $video->getMimeType(),
106+
], [
107+
'chunkedUpload' => true,
108+
]);
104109

105110
$status = $this->twitter->mediaStatus($media->media_id_string);
106111

src/TwitterImage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class TwitterImage
66
{
77
public function __construct(private string $imagePath)
88
{
9+
//
910
}
1011

1112
public function getPath(): string

src/TwitterMessage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ abstract class TwitterMessage
88

99
public function __construct(protected string $content)
1010
{
11+
//
1112
}
1213

1314
public function getContent(): string

src/TwitterStatusUpdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(string $content)
2525
{
2626
parent::__construct($content);
2727

28-
if ($exceededLength = $this->messageIsTooLong(new Brevity())) {
28+
if ($exceededLength = $this->messageIsTooLong(new Brevity)) {
2929
throw CouldNotSendNotification::statusUpdateTooLong($exceededLength);
3030
}
3131
}

src/TwitterVideo.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class TwitterVideo
66
{
77
public function __construct(private string $videoPath)
88
{
9+
//
910
}
1011

1112
public function getPath(): string

tests/TestCase.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
<?php
22

3+
namespace NotificationChannels\Twitter;
4+
5+
function mime_content_type($path)
6+
{
7+
return 'video/mp4';
8+
}
9+
310
namespace NotificationChannels\Twitter\Test;
411

512
use Mockery as m;
613

714
abstract class TestCase extends \Orchestra\Testbench\TestCase
815
{
9-
public function tearDown(): void
16+
protected function tearDown(): void
1017
{
1118
parent::tearDown();
1219

tests/TwitterChannelTest.php

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ class TwitterChannelTest extends TestCase
2121

2222
protected TwitterChannel $channel;
2323

24-
public function setUp(): void
24+
protected function setUp(): void
2525
{
2626
parent::setUp();
2727
$this->twitter = m::mock(TwitterOAuth::class, function ($mock) {
28-
$mock->shouldReceive('setApiVersion')
29-
->with('2');
28+
$mock->shouldReceive('setApiVersion')->with('1.1');
29+
$mock->shouldReceive('setApiVersion')->with('2');
3030
});
3131
$this->channel = new TwitterChannel($this->twitter);
3232
}
3333

34-
/** @test */
35-
public function it_can_send_a_status_update_notification()
34+
public function test_it_can_send_a_status_update_notification()
3635
{
3736
$this->twitter->shouldReceive('post')
3837
->once()
@@ -43,11 +42,10 @@ public function it_can_send_a_status_update_notification()
4342
->once()
4443
->andReturn(201);
4544

46-
$this->channel->send(new TestNotifiable(), new TestNotification());
45+
$this->channel->send(new TestNotifiable, new TestNotification);
4746
}
4847

49-
/** @test */
50-
public function it_can_send_a_status_update_notification_with_images()
48+
public function test_it_can_send_a_status_update_notification_with_images()
5149
{
5250
$media = new stdClass;
5351
$media->media_id_string = '2';
@@ -74,11 +72,10 @@ public function it_can_send_a_status_update_notification_with_images()
7472
->once()
7573
->andReturn(201);
7674

77-
$this->channel->send(new TestNotifiable(), new TestNotificationWithImage());
75+
$this->channel->send(new TestNotifiable, new TestNotificationWithImage);
7876
}
7977

80-
/** @test */
81-
public function it_can_send_a_status_update_notification_with_videos()
78+
public function test_it_can_send_a_status_update_notification_with_videos()
8279
{
8380
$media = new stdClass;
8481
$media->media_id_string = '2';
@@ -97,7 +94,7 @@ public function it_can_send_a_status_update_notification_with_videos()
9794
->with(
9895
'tweets',
9996
['text' => 'Laravel Notification Channels are awesome!', 'media' => ['media_ids' => [2]]],
100-
true
97+
['jsonPayload' => true]
10198
)
10299
->andReturn([]);
103100

@@ -119,11 +116,10 @@ public function it_can_send_a_status_update_notification_with_videos()
119116
->once()
120117
->andReturn(201);
121118

122-
$this->channel->send(new TestNotifiable(), new TestNotificationWithVideo());
119+
$this->channel->send(new TestNotifiable, new TestNotificationWithVideo);
123120
}
124121

125-
/** @test */
126-
public function it_can_send_a_status_update_notification_with_reply_to_tweet_id(): void
122+
public function test_it_can_send_a_status_update_notification_with_reply_to_tweet_id(): void
127123
{
128124
$postParams = [
129125
'text' => 'Laravel Notification Channels are awesome!',
@@ -139,11 +135,10 @@ public function it_can_send_a_status_update_notification_with_reply_to_tweet_id(
139135
->once()
140136
->andReturn(201);
141137

142-
$this->channel->send(new TestNotifiable(), new TestNotificationWithReplyToStatusId($replyToStatusId));
138+
$this->channel->send(new TestNotifiable, new TestNotificationWithReplyToStatusId($replyToStatusId));
143139
}
144140

145-
/** @test */
146-
public function it_throws_an_exception_when_it_could_not_send_the_notification()
141+
public function test_it_throws_an_exception_when_it_could_not_send_the_notification()
147142
{
148143
$twitterResponse = new stdClass;
149144
$twitterResponse->detail = 'Error Message';
@@ -162,11 +157,10 @@ public function it_throws_an_exception_when_it_could_not_send_the_notification()
162157

163158
$this->expectException(CouldNotSendNotification::class);
164159

165-
$this->channel->send(new TestNotifiable(), new TestNotification());
160+
$this->channel->send(new TestNotifiable, new TestNotification);
166161
}
167162

168-
/** @test */
169-
public function it_throws_an_exception_when_it_could_not_send_the_notification_with_videos()
163+
public function test_it_throws_an_exception_when_it_could_not_send_the_notification_with_videos()
170164
{
171165
$media = new stdClass;
172166
$media->media_id_string = '2';
@@ -198,7 +192,7 @@ public function it_throws_an_exception_when_it_could_not_send_the_notification_w
198192

199193
$this->expectException(CouldNotSendNotification::class);
200194

201-
$this->channel->send(new TestNotifiable(), new TestNotificationWithVideo());
195+
$this->channel->send(new TestNotifiable, new TestNotificationWithVideo);
202196
}
203197
}
204198

0 commit comments

Comments
 (0)