Skip to content

Commit daefff0

Browse files
committed
Make classes final, one line declare, PHPUnit test methods
1 parent eea8902 commit daefff0

14 files changed

+37
-74
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Add the `CanComment` trait to your User model:
2424
```php
2525
use Actuallymab\LaravelComment\CanComment;
2626

27-
class User extends Model
27+
final class User extends Model
2828
{
2929
use CanComment;
3030
```
@@ -35,7 +35,7 @@ Add the `Commentable` interface and the `HasComments` trait to your commentable
3535
use Actuallymab\LaravelComment\Contracts\Commentable;
3636
use Actuallymab\LaravelComment\HasComments;
3737

38-
class Product extends Model implements Commentable
38+
final class Product extends Model implements Commentable
3939
{
4040
use HasComments;
4141
```
@@ -45,15 +45,15 @@ If you want to have your own `Comment` Model create a new one and extend `Actual
4545
```php
4646
use Actuallymab\LaravelComment\Models\Comment as LaravelComment;
4747

48-
class Comment extends LaravelComment
48+
final class Comment extends LaravelComment
4949
```
5050

5151
> Don't forget to update the model class in `config/comment.php`.
5252
5353
### Allow rating
5454

5555
```php
56-
class Product extends Model implements Commentable
56+
final class Product extends Model implements Commentable
5757
{
5858
use HasComments;
5959

@@ -66,7 +66,7 @@ class Product extends Model implements Commentable
6666
### Require comments to be approved
6767

6868
```php
69-
class Product extends Model implements Commentable
69+
final class Product extends Model implements Commentable
7070
{
7171
use HasComments;
7272

@@ -79,7 +79,7 @@ class Product extends Model implements Commentable
7979
### Allow some users to comment without approval
8080

8181
```php
82-
class User extends Model
82+
final class User extends Model
8383
{
8484
use CanComment;
8585

src/CanComment.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Actuallymab\LaravelComment;
64

src/Contracts/Commentable.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Actuallymab\LaravelComment\Contracts;
64

src/HasComments.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Actuallymab\LaravelComment;
64

src/LaravelCommentServiceProvider.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Actuallymab\LaravelComment;
64

src/Models/Comment.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Actuallymab\LaravelComment\Models;
64

src/comment.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
return [
64
/*

src/create_comments_table.php.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55

6-
class CreateCommentsTable extends Migration
6+
final class CreateCommentsTable extends Migration
77
{
88
public function up(): void
99
{

tests/CommentTest.php

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Actuallymab\LaravelComment\Tests;
64

@@ -9,12 +7,11 @@
97
use Actuallymab\LaravelComment\Tests\Models\User;
108
use Illuminate\Foundation\Testing\WithFaker;
119

12-
class CommentTest extends TestCase
10+
final class CommentTest extends TestCase
1311
{
1412
use WithFaker;
1513

16-
/** @test */
17-
public function it_belongs_to_a_can_comment_object()
14+
public function test_belongs_to_a_can_comment_object()
1815
{
1916
$user = $this->createUser();
2017
$product = $this->createProduct();
@@ -29,17 +26,15 @@ public function it_belongs_to_a_can_comment_object()
2926
$this->assertTrue($product->comments()->first()->commented->is($user));
3027
}
3128

32-
/** @test */
33-
public function comment_object_is_returned_after_comment_operation()
29+
public function test_comment_object_is_returned_after_comment_operation()
3430
{
3531
$user = $this->createUser();
3632
$product = $this->createProduct();
3733

3834
$this->assertInstanceOf(Comment::class, $user->comment($product, $this->faker->sentence));
3935
}
4036

41-
/** @test */
42-
public function comment_can_be_checked()
37+
public function test_comment_can_be_checked()
4338
{
4439
$user = $this->createUser();
4540
$product = $this->createProduct();
@@ -49,8 +44,7 @@ public function comment_can_be_checked()
4944
$this->assertTrue($user->hasCommentsOn($product));
5045
}
5146

52-
/** @test */
53-
public function it_must_be_unapproved_as_default_if_must_be_approved_method_returns_true()
47+
public function test_must_be_unapproved_as_default_if_must_be_approved_method_returns_true()
5448
{
5549
$user = $this->createUser();
5650
$product = $this->createProductWithCommentsMustBeApproved();
@@ -59,8 +53,7 @@ public function it_must_be_unapproved_as_default_if_must_be_approved_method_retu
5953
$this->assertFalse($user->comments[0]->approved);
6054
}
6155

62-
/** @test */
63-
public function it_must_be_approved_as_default_if_a_product_was_commented_by_an_admin()
56+
public function test_must_be_approved_as_default_if_a_product_was_commented_by_an_admin()
6457
{
6558
$admin = $this->createAdmin();
6659
$product = $this->createProductWithCommentsMustBeApproved();
@@ -69,8 +62,7 @@ public function it_must_be_approved_as_default_if_a_product_was_commented_by_an_
6962
$this->assertTrue($admin->comments[0]->approved);
7063
}
7164

72-
/** @test */
73-
public function it_can_be_approved()
65+
public function test_can_be_approved()
7466
{
7567
$user = $this->createUser();
7668
$product = $this->createProductWithCommentsMustBeApproved();
@@ -81,8 +73,7 @@ public function it_can_be_approved()
8173
$this->assertTrue($product->comments[0]->fresh()->approved);
8274
}
8375

84-
/** @test */
85-
public function it_can_be_rated()
76+
public function test_can_be_rated()
8677
{
8778
$user = $this->createUser();
8879
$product = $this->createRateableProduct();
@@ -91,8 +82,7 @@ public function it_can_be_rated()
9182
$this->assertEquals(3, $user->comments[0]->rate);
9283
}
9384

94-
/** @test */
95-
public function rate_does_not_make_sense_when_its_not_rateable_product()
85+
public function test_rate_does_not_make_sense_when_its_not_rateable_product()
9686
{
9787
$user = $this->createUser();
9888
$product = $this->createProduct();
@@ -101,8 +91,7 @@ public function rate_does_not_make_sense_when_its_not_rateable_product()
10191
$this->assertEquals(0, $product->averageRate());
10292
}
10393

104-
/** @test */
105-
public function it_can_calculate_average_rating_of_all_comments()
94+
public function test_can_calculate_average_rating_of_all_comments()
10695
{
10796
$user = $this->createUser();
10897
$product = $this->createRateableProduct();
@@ -119,8 +108,7 @@ public function it_can_calculate_average_rating_of_all_comments()
119108
$this->assertEquals(3.67, $product->averageRate());
120109
}
121110

122-
/** @test */
123-
public function it_must_calculate_average_rating_only_from_approved_comments_if_approve_option_enabled()
111+
public function test_must_calculate_average_rating_only_from_approved_comments_if_approve_option_enabled()
124112
{
125113
$admin = $this->createUser();
126114
$product = $this->createRateableProductWithCommentsMustBeApproved();
@@ -144,8 +132,7 @@ public function it_must_calculate_average_rating_only_from_approved_comments_if_
144132
$this->assertEquals(3, $product->averageRate());
145133
}
146134

147-
/** @test */
148-
public function it_can_calculate_total_comments_count()
135+
public function test_can_calculate_total_comments_count()
149136
{
150137
$user = $this->createUser();
151138
$product = $this->createProduct();
@@ -156,8 +143,7 @@ public function it_can_calculate_total_comments_count()
156143
$this->assertEquals(2, $product->totalCommentsCount());
157144
}
158145

159-
/** @test */
160-
public function it_must_calculate_only_approved_comments_as_total_comment_if_approve_option_enabled()
146+
public function test_must_calculate_only_approved_comments_as_total_comment_if_approve_option_enabled()
161147
{
162148
$user = $this->createUser();
163149
$product = $this->createProductWithCommentsMustBeApproved();
@@ -178,8 +164,7 @@ public function it_must_calculate_only_approved_comments_as_total_comment_if_app
178164
$this->assertEquals(3, $product->totalCommentsCount());
179165
}
180166

181-
/** @test */
182-
public function comments_also_can_be_commentable()
167+
public function test_comments_also_can_be_commentable()
183168
{
184169
$user = $this->createUser();
185170
$product = $this->createProduct();

tests/Models/Product.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Actuallymab\LaravelComment\Tests\Models;
64

@@ -13,7 +11,7 @@
1311
* @property bool $can_be_rated
1412
* @property bool $must_be_approved
1513
*/
16-
class Product extends Model implements Commentable
14+
final class Product extends Model implements Commentable
1715
{
1816
use HasComments;
1917

tests/Models/User.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Actuallymab\LaravelComment\Tests\Models;
64

@@ -11,7 +9,7 @@
119
* @property string $name
1210
* @property bool $is_admin
1311
*/
14-
class User extends Model
12+
final class User extends Model
1513
{
1614
use CanComment;
1715

tests/TestCase.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
namespace Actuallymab\LaravelComment\Tests;
64

tests/migrations/0000_00_00_000000_products.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
use Illuminate\Database\Migrations\Migration;
64
use Illuminate\Database\Schema\Blueprint;
75
use Illuminate\Support\Facades\Schema;
86

9-
class Products extends Migration
7+
final class Products extends Migration
108
{
119
public function up(): void
1210
{

tests/migrations/0000_00_00_000000_users.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
use Illuminate\Database\Migrations\Migration;
64
use Illuminate\Database\Schema\Blueprint;
75
use Illuminate\Support\Facades\Schema;
86

9-
class Users extends Migration
7+
final class Users extends Migration
108
{
119
public function up(): void
1210
{

0 commit comments

Comments
 (0)