Skip to content

Commit 7272f50

Browse files
committed
Merge branch 'master' into v2
2 parents 2131acf + cfd3f5a commit 7272f50

File tree

13 files changed

+106
-76
lines changed

13 files changed

+106
-76
lines changed

.github/stale.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Configuration for probot-stale - https://github.com/probot/stale
2+
3+
# Number of days of inactivity before an Issue or Pull Request becomes stale
4+
daysUntilStale: 60
5+
6+
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
7+
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
8+
daysUntilClose: 7
9+
10+
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
11+
exemptLabels:
12+
- bug
13+
- feedback
14+
- "in progress"
15+
16+
# Label to use when marking as stale
17+
staleLabel: stale
18+
19+
# Comment to post when marking as stale. Set to `false` to disable
20+
markComment: >
21+
This issue has been automatically marked as stale because it has not had
22+
recent activity. It will be closed if no further activity occurs. Thank you
23+
for your contributions.
24+
25+
# Limit to only `issues` or `pulls`
26+
only: issues

.scrutinizer.yml

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1+
build:
2+
nodes:
3+
analysis:
4+
tests:
5+
override:
6+
- php-scrutinizer-run
7+
18
filter:
2-
excluded_paths:
3-
- 'tests/*'
4-
- 'examples/*'
5-
- 'config/*'
6-
- 'migrations/*'
9+
excluded_paths:
10+
- 'tests/*'
11+
- 'examples/*'
12+
- 'config/*'
13+
- 'migrations/*'
714

815
checks:
9-
php:
10-
remove_extra_empty_lines: true
11-
remove_php_closing_tag: true
12-
remove_trailing_whitespace: true
13-
fix_use_statements:
14-
remove_unused: true
15-
preserve_multiple: false
16-
preserve_blanklines: true
17-
order_alphabetically: true
18-
fix_php_opening_tag: true
19-
fix_linefeed: true
20-
fix_line_ending: true
21-
fix_identation_4spaces: true
22-
fix_doc_comments: true
16+
php:
17+
remove_extra_empty_lines: true
18+
remove_php_closing_tag: true
19+
remove_trailing_whitespace: true
20+
fix_use_statements:
21+
remove_unused: true
22+
preserve_multiple: false
23+
preserve_blanklines: true
24+
order_alphabetically: true
25+
fix_php_opening_tag: true
26+
fix_linefeed: true
27+
fix_line_ending: true
28+
fix_identation_4spaces: true
29+
fix_doc_comments: true
2330

2431
tools:
25-
external_code_coverage:
26-
timeout: 1800
27-
runs: 3
32+
external_code_coverage:
33+
timeout: 1800
34+
runs: 3

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ php:
44
- 7.1
55
- 7.2
66
- 7.3
7-
- nightly
87

98
matrix:
9+
include:
10+
- php: 7.1
11+
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
1012
allow_failures:
1113
- php: nightly
1214

13-
## Cache composer
1415
cache:
1516
directories:
1617
- $HOME/.composer/cache
1718

1819
before_script:
1920
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
20-
- composer dumpautoload -o
2121

2222
script:
2323
- vendor/bin/php-cs-fixer fix .

composer.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"adamwathan/faktory": "0.3.*",
2222
"friendsofphp/php-cs-fixer": "^2.5",
2323
"orchestra/testbench": "~3.0",
24-
"phpunit/phpunit": "^7.0|^8.0"
24+
"phpunit/phpunit": "^7.0"
2525
},
2626
"autoload": {
2727
"psr-4": {
@@ -30,18 +30,22 @@
3030
},
3131
"autoload-dev": {
3232
"psr-4": {
33-
"Cmgmyr\\Messenger\\Test\\": "tests/"
33+
"Cmgmyr\\Messenger\\Tests\\": "tests/"
3434
}
3535
},
36+
"scripts": {
37+
"test": "vendor/bin/phpunit",
38+
"test-coverage": "vendor/bin/phpunit --coverage-html build/coverage",
39+
"format": "vendor/bin/php-cs-fixer fix"
40+
},
41+
"config": {
42+
"sort-packages": true
43+
},
3644
"extra": {
3745
"laravel": {
3846
"providers": [
3947
"Cmgmyr\\Messenger\\MessengerServiceProvider"
4048
]
4149
}
42-
},
43-
"config": {
44-
"sort-packages": true
45-
},
46-
"minimum-stability": "stable"
50+
}
4751
}

phpunit.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
</testsuite>
1616
</testsuites>
1717
<php>
18-
<env name="APP_ENV" value="testing"/>
19-
<env name="CACHE_DRIVER" value="array"/>
20-
<env name="SESSION_DRIVER" value="array"/>
21-
<env name="QUEUE_DRIVER" value="sync"/>
2218
<server name="APP_ENV" value="testing"/>
19+
<server name="BCRYPT_ROUNDS" value="4"/>
2320
<server name="CACHE_DRIVER" value="array"/>
21+
<server name="MAIL_DRIVER" value="array"/>
22+
<server name="QUEUE_CONNECTION" value="sync"/>
2423
<server name="SESSION_DRIVER" value="array"/>
25-
<server name="QUEUE_DRIVER" value="sync"/>
2624
</php>
2725
<filter>
2826
<whitelist>
@@ -35,7 +33,7 @@
3533
<logging>
3634
<log type="tap" target="build/report.tap"/>
3735
<log type="junit" target="build/report.junit.xml"/>
38-
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
36+
<log type="coverage-html" target="build/coverage"/>
3937
<log type="coverage-text" target="build/coverage.txt"/>
4038
<log type="coverage-clover" target="build/logs/clover.xml"/>
4139
</logging>

src/Models/Models.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ public static function setTables(array $map)
8383
*/
8484
public static function table($table)
8585
{
86-
if (isset(static::$tables[$table])) {
87-
return static::$tables[$table];
88-
}
89-
90-
return $table;
86+
return static::$tables[$table] ?? $table;
9187
}
9288

9389
/**
@@ -98,11 +94,7 @@ public static function table($table)
9894
*/
9995
public static function classname($model)
10096
{
101-
if (isset(static::$models[$model])) {
102-
return static::$models[$model];
103-
}
104-
105-
return $model;
97+
return static::$models[$model] ?? $model;
10698
}
10799

108100
/**

src/Models/Thread.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class Thread extends Eloquent
3636
/**
3737
* Internal cache for creator.
3838
*
39-
* @var null|Models::user()
39+
* @var null|Models::user()|\Illuminate\Database\Eloquent\Model
4040
*/
41-
protected $creatorCache = null;
41+
protected $creatorCache;
4242

4343
/**
4444
* {@inheritDoc}
@@ -99,11 +99,11 @@ public function users()
9999
/**
100100
* Returns the user object that created the thread.
101101
*
102-
* @return Models::user()
102+
* @return null|Models::user()|\Illuminate\Database\Eloquent\Model
103103
*/
104104
public function creator()
105105
{
106-
if (is_null($this->creatorCache)) {
106+
if ($this->creatorCache === null) {
107107
$firstMessage = $this->messages()->withTrashed()->oldest()->first();
108108
$this->creatorCache = $firstMessage ? $firstMessage->user : Models::user();
109109
}
@@ -136,7 +136,7 @@ public static function getBySubject($subject)
136136
/**
137137
* Returns an array of user ids that are associated with the thread.
138138
*
139-
* @param null $userId
139+
* @param null|int $userId
140140
*
141141
* @return array
142142
*/
@@ -146,7 +146,7 @@ public function participantsUserIds($userId = null)
146146
return $participant->user_id;
147147
});
148148

149-
if ($userId) {
149+
if ($userId !== null) {
150150
$users->push($userId);
151151
}
152152

@@ -168,7 +168,7 @@ public function scopeForUser(Builder $query, $userId)
168168

169169
return $query->join($participantsTable, $this->getQualifiedKeyName(), '=', $participantsTable . '.thread_id')
170170
->where($participantsTable . '.user_id', $userId)
171-
->where($participantsTable . '.deleted_at', null)
171+
->whereNull($participantsTable . '.deleted_at')
172172
->select($threadsTable . '.*');
173173
}
174174

@@ -351,11 +351,8 @@ public function participantsString($userId = null, $columns = ['name'])
351351
public function hasParticipant($userId)
352352
{
353353
$participants = $this->participants()->where('user_id', '=', $userId);
354-
if ($participants->count() > 0) {
355-
return true;
356-
}
357354

358-
return false;
355+
return $participants->count() > 0;
359356
}
360357

361358
/**
@@ -398,7 +395,7 @@ protected function createSelectString($columns)
398395
*/
399396
public function userUnreadMessages($userId)
400397
{
401-
$messages = $this->messages()->get();
398+
$messages = $this->messages()->where('user_id', '!=', $userId)->get();
402399

403400
try {
404401
$participant = $this->getParticipantFromUser($userId);

tests/CustomModelsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
use Cmgmyr\Messenger\Models\Models;
77
use Cmgmyr\Messenger\Models\Participant;
88
use Cmgmyr\Messenger\Models\Thread;
9-
use Cmgmyr\Messenger\Test\Stubs\Models\CustomMessage;
10-
use Cmgmyr\Messenger\Test\Stubs\Models\CustomParticipant;
11-
use Cmgmyr\Messenger\Test\Stubs\Models\CustomThread;
9+
use Cmgmyr\Messenger\Tests\Stubs\Models\CustomMessage;
10+
use Cmgmyr\Messenger\Tests\Stubs\Models\CustomParticipant;
11+
use Cmgmyr\Messenger\Tests\Stubs\Models\CustomThread;
1212

1313
class CustomModelsTest extends TestCase
1414
{

tests/EloquentThreadTest.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ public function it_should_get_all_unread_messages_for_user()
413413
$message_1 = $this->faktory->build('message', [
414414
'created_at' => Carbon::now(),
415415
'body' => 'Message 1',
416+
'user_id' => $participant_1->user_id,
416417
]);
417418

418419
$thread->participants()->saveMany([$participant_1, $participant_2]);
@@ -426,28 +427,30 @@ public function it_should_get_all_unread_messages_for_user()
426427
$message_2 = $this->faktory->build('message', [
427428
'created_at' => Carbon::now(),
428429
'body' => 'Message 2',
430+
'user_id' => $participant_1->user_id,
429431
]);
430432

431433
$thread->messages()->saveMany([$message_2]);
432434

433-
$this->assertEquals('Message 1', $thread->userUnreadMessages(1)->first()->body);
434-
$this->assertCount(2, $thread->userUnreadMessages(1));
435+
$this->assertCount(0, $thread->userUnreadMessages($participant_1->user_id));
435436

436-
$this->assertEquals('Message 2', $thread->userUnreadMessages(2)->first()->body);
437-
$this->assertCount(1, $thread->userUnreadMessages(2));
437+
$secondParticipantUnreadMessages = $thread->userUnreadMessages($participant_2->user_id);
438+
$this->assertCount(1, $secondParticipantUnreadMessages);
439+
$this->assertEquals('Message 2', $secondParticipantUnreadMessages->first()->body);
438440
}
439441

440442
/** @test */
441-
public function it_should_get_count_of_all_unread_messages_for_user()
443+
public function it_should_get_all_unread_messages_for_user_when_dates_not_set()
442444
{
443445
$thread = $this->faktory->create('thread');
444446

445447
$participant_1 = $this->faktory->build('participant');
446448
$participant_2 = $this->faktory->build('participant', ['user_id' => 2]);
447449

448450
$message_1 = $this->faktory->build('message', [
449-
'created_at' => Carbon::now(),
451+
// 'created_at' => Carbon::now(),
450452
'body' => 'Message 1',
453+
'user_id' => $participant_1->user_id,
451454
]);
452455

453456
$thread->participants()->saveMany([$participant_1, $participant_2]);
@@ -459,15 +462,18 @@ public function it_should_get_count_of_all_unread_messages_for_user()
459462
sleep(1);
460463

461464
$message_2 = $this->faktory->build('message', [
462-
'created_at' => Carbon::now(),
465+
// 'created_at' => Carbon::now(),
463466
'body' => 'Message 2',
467+
'user_id' => $participant_1->user_id,
464468
]);
465469

466470
$thread->messages()->saveMany([$message_2]);
467471

468-
$this->assertEquals(2, $thread->userUnreadMessagesCount(1));
472+
$this->assertCount(0, $thread->userUnreadMessages($participant_1->user_id));
469473

470-
$this->assertEquals(1, $thread->userUnreadMessagesCount(2));
474+
$secondParticipantUnreadMessages = $thread->userUnreadMessages($participant_2->user_id);
475+
$this->assertCount(1, $secondParticipantUnreadMessages);
476+
$this->assertEquals('Message 2', $secondParticipantUnreadMessages->first()->body);
471477
}
472478

473479
/** @test */

tests/Stubs/Models/CustomMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Cmgmyr\Messenger\Test\Stubs\Models;
3+
namespace Cmgmyr\Messenger\Tests\Stubs\Models;
44

55
use Cmgmyr\Messenger\Models\Message;
66

0 commit comments

Comments
 (0)