Skip to content

Commit d76b510

Browse files
committed
set github configuration
1 parent f8103ed commit d76b510

File tree

6 files changed

+40
-24
lines changed

6 files changed

+40
-24
lines changed

.github/workflows/php.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: slack test
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
env:
10+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Install dependencies
18+
run: composer install --prefer-dist --no-progress
19+
- name: Check code standard
20+
run: composer cs-fix
21+
- name: Run test suite
22+
run: composer test

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ $message = (new SlackMessage)
219219
$slack->send($message);
220220
```
221221

222+
# Testing
223+
224+
Set the `SLACK_WEBHOOK_URL` variable before
225+
226+
```bash
227+
composer test
228+
```
229+
222230
# Warning
223231

224232
Each message initiates a new HTTPS request, which takes some time. Don't send too much messages at once if you are not

composer.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,9 @@
4343
"Bow\\Slack\\": "src/"
4444
}
4545
},
46-
"autoload-dev": {
47-
"psr-4": {
48-
"Bow\\Slack\\Tests\\": "tests/"
49-
}
50-
},
5146
"scripts": {
5247
"test": "phpunit",
53-
"test-coverage": "phpunit --coverage-html coverage",
48+
"test-coverage": "phpunit --coverage-html coverage --configuration phpunit.disk.xml",
5449
"cs-fix": "phpcbf --standard=PSR12 src tests",
5550
"cs-check": "phpcs --standard=PSR12 src tests"
5651
},

phpunit.dist.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
2+
<phpunit bootstrap="vendor/autoload.php"
53
colors="true"
64
verbose="true"
75
failOnRisky="true"

tests/SlackMessageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function it_can_set_unfurl_links()
9595

9696
$data = $message->toArray();
9797

98-
$this->assertTrue($data['unfurl_links']);
98+
$this->assertTrue((bool) $data['unfurl_links']);
9999
}
100100

101101
/**

tests/SlackTest.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
class SlackTest extends TestCase
1111
{
12-
private string $webhook_url = 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX';
12+
private string $webhook_url;
13+
14+
protected function setUp(): void
15+
{
16+
$this->webhook_url = getenv('SLACK_WEBHOOK_URL');
17+
}
1318

1419
/**
1520
* @test
@@ -36,8 +41,6 @@ public function it_can_set_webhook_url()
3641
*/
3742
public function it_can_send_simple_message()
3843
{
39-
$this->markTestSkipped('This test requires a valid Slack webhook URL');
40-
4144
$slack = new Slack($this->webhook_url);
4245
$message = new SlackMessage('Test message');
4346

@@ -50,8 +53,6 @@ public function it_can_send_simple_message()
5053
*/
5154
public function it_can_send_message_with_attachments()
5255
{
53-
$this->markTestSkipped('This test requires a valid Slack webhook URL');
54-
5556
$slack = new Slack($this->webhook_url);
5657
$message = new SlackMessage('Test message with attachment');
5758

@@ -73,8 +74,6 @@ public function it_can_send_message_with_attachments()
7374
*/
7475
public function it_can_send_formatted_message()
7576
{
76-
$this->markTestSkipped('This test requires a valid Slack webhook URL');
77-
7877
$slack = new Slack($this->webhook_url);
7978
$message = (new SlackMessage('Test formatted message'))
8079
->assignTo('test-bot')
@@ -91,7 +90,7 @@ public function it_can_send_formatted_message()
9190
*/
9291
public function it_handles_invalid_webhook_url()
9392
{
94-
$slack = new Slack('https://hooks.slack.com/services/INVALID/URL');
93+
$slack = new Slack('https://hooks.slack.com/services/NEW/URL/HERE');
9594
$message = new SlackMessage('Test message');
9695

9796
$result = $slack->send($message);
@@ -103,8 +102,6 @@ public function it_handles_invalid_webhook_url()
103102
*/
104103
public function it_can_send_message_with_custom_channel()
105104
{
106-
$this->markTestSkipped('This test requires a valid Slack webhook URL');
107-
108105
$slack = new Slack($this->webhook_url);
109106
$message = new SlackMessage('Test message');
110107
$message->on('#random');
@@ -118,8 +115,6 @@ public function it_can_send_message_with_custom_channel()
118115
*/
119116
public function it_can_send_message_with_custom_username()
120117
{
121-
$this->markTestSkipped('This test requires a valid Slack webhook URL');
122-
123118
$slack = new Slack($this->webhook_url);
124119
$message = new SlackMessage('Test message');
125120
$message->assignTo('custom-bot');
@@ -133,8 +128,6 @@ public function it_can_send_message_with_custom_username()
133128
*/
134129
public function it_can_send_message_with_emoji()
135130
{
136-
$this->markTestSkipped('This test requires a valid Slack webhook URL');
137-
138131
$slack = new Slack($this->webhook_url);
139132
$message = new SlackMessage('Test message');
140133
$message->withEmoji(':tada:');

0 commit comments

Comments
 (0)