Skip to content

Commit 5d661ba

Browse files
author
Pe Ell
authored
Merge pull request #2 from cybercog/hotfix/missing-tests
Add missing unit tests. Fix tests methods naming
2 parents 2de8d1e + 16e9048 commit 5d661ba

File tree

4 files changed

+76
-31
lines changed

4 files changed

+76
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Eloquent flagged attributes behavior. Add commonly used flags to models very qui
1313

1414
Eloquent Flag is an easy way to add flagged attributes to eloquent models. All flags has their own trait which adds global scopes to desired entity.
1515

16-
The main logic of the flags: If flag is `false` - entity should be hidden from the query results. Omitted entities could be retrieved by using a global scope methods.
16+
The main logic of the flags: If flag is `false` - entity should be hidden from the query results. Omitted entities could be retrieved by using special global scope methods.
1717

1818
## Available flags list
1919

tests/unit/Scopes/ActiveFlagScopeTest.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ public function it_can_get_without_inactive()
5151
$this->assertCount(3, $entities);
5252
}
5353

54+
/** @test */
55+
public function it_can_get_with_inactive()
56+
{
57+
factory(EntityWithActiveFlag::class, 3)->create([
58+
'is_active' => true,
59+
]);
60+
factory(EntityWithActiveFlag::class, 2)->create([
61+
'is_active' => false,
62+
]);
63+
64+
$entities = EntityWithActiveFlag::withInactive()->get();
65+
66+
$this->assertCount(5, $entities);
67+
}
68+
5469
/** @test */
5570
public function it_can_get_only_inactive()
5671
{
@@ -69,28 +84,28 @@ public function it_can_get_only_inactive()
6984
/** @test */
7085
public function it_can_activate_model()
7186
{
72-
$method = factory(EntityWithActiveFlag::class)->create([
87+
$model = factory(EntityWithActiveFlag::class)->create([
7388
'is_active' => false,
7489
]);
7590

76-
EntityWithActiveFlag::where('id', $method->id)->activate();
91+
EntityWithActiveFlag::where('id', $model->id)->activate();
7792

78-
$method = EntityWithActiveFlag::where('id', $method->id)->first();
93+
$model = EntityWithActiveFlag::where('id', $model->id)->first();
7994

80-
$this->assertTrue($method->is_active);
95+
$this->assertTrue($model->is_active);
8196
}
8297

8398
/** @test */
8499
public function it_can_deactivate_model()
85100
{
86-
$method = factory(EntityWithActiveFlag::class)->create([
101+
$model = factory(EntityWithActiveFlag::class)->create([
87102
'is_active' => true,
88103
]);
89104

90-
EntityWithActiveFlag::where('id', $method->id)->deactivate();
105+
EntityWithActiveFlag::where('id', $model->id)->deactivate();
91106

92-
$method = EntityWithActiveFlag::withInactive()->where('id', $method->id)->first();
107+
$model = EntityWithActiveFlag::withInactive()->where('id', $model->id)->first();
93108

94-
$this->assertFalse($method->is_active);
109+
$this->assertFalse($model->is_active);
95110
}
96111
}

tests/unit/Scopes/KeptFlagScopeTest.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ public function it_can_get_without_unkept()
5151
$this->assertCount(3, $entities);
5252
}
5353

54+
/** @test */
55+
public function it_can_get_with_unkept()
56+
{
57+
factory(EntityWithKeptFlag::class, 3)->create([
58+
'is_kept' => true,
59+
]);
60+
factory(EntityWithKeptFlag::class, 2)->create([
61+
'is_kept' => false,
62+
]);
63+
64+
$entities = EntityWithKeptFlag::withUnkept()->get();
65+
66+
$this->assertCount(5, $entities);
67+
}
68+
5469
/** @test */
5570
public function it_can_get_only_unkept()
5671
{
@@ -69,28 +84,28 @@ public function it_can_get_only_unkept()
6984
/** @test */
7085
public function it_can_keep_model()
7186
{
72-
$method = factory(EntityWithKeptFlag::class)->create([
87+
$model = factory(EntityWithKeptFlag::class)->create([
7388
'is_kept' => false,
7489
]);
7590

76-
EntityWithKeptFlag::where('id', $method->id)->keep();
91+
EntityWithKeptFlag::where('id', $model->id)->keep();
7792

78-
$method = EntityWithKeptFlag::where('id', $method->id)->first();
93+
$model = EntityWithKeptFlag::where('id', $model->id)->first();
7994

80-
$this->assertTrue($method->is_kept);
95+
$this->assertTrue($model->is_kept);
8196
}
8297

8398
/** @test */
84-
public function it_can_deactivate_model()
99+
public function it_can_unkeep_model()
85100
{
86-
$method = factory(EntityWithKeptFlag::class)->create([
101+
$model = factory(EntityWithKeptFlag::class)->create([
87102
'is_kept' => true,
88103
]);
89104

90-
EntityWithKeptFlag::where('id', $method->id)->unkeep();
105+
EntityWithKeptFlag::where('id', $model->id)->unkeep();
91106

92-
$method = EntityWithKeptFlag::withUnkept()->where('id', $method->id)->first();
107+
$model = EntityWithKeptFlag::withUnkept()->where('id', $model->id)->first();
93108

94-
$this->assertFalse($method->is_kept);
109+
$this->assertFalse($model->is_kept);
95110
}
96111
}

tests/unit/Scopes/PublishedFlagScopeTest.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class PublishedFlagScopeTest extends TestCase
2323
{
2424
/** @test */
25-
public function it_can_get_only_active()
25+
public function it_can_get_only_published()
2626
{
2727
factory(EntityWithPublishedFlag::class, 3)->create([
2828
'is_published' => true,
@@ -37,7 +37,7 @@ public function it_can_get_only_active()
3737
}
3838

3939
/** @test */
40-
public function it_can_get_without_inactive()
40+
public function it_can_get_without_unpublished()
4141
{
4242
factory(EntityWithPublishedFlag::class, 3)->create([
4343
'is_published' => true,
@@ -52,7 +52,22 @@ public function it_can_get_without_inactive()
5252
}
5353

5454
/** @test */
55-
public function it_can_get_only_inactive()
55+
public function it_can_get_with_unpublished()
56+
{
57+
factory(EntityWithPublishedFlag::class, 3)->create([
58+
'is_published' => true,
59+
]);
60+
factory(EntityWithPublishedFlag::class, 2)->create([
61+
'is_published' => false,
62+
]);
63+
64+
$entities = EntityWithPublishedFlag::withUnpublished()->get();
65+
66+
$this->assertCount(5, $entities);
67+
}
68+
69+
/** @test */
70+
public function it_can_get_only_unpublished()
5671
{
5772
factory(EntityWithPublishedFlag::class, 3)->create([
5873
'is_published' => true,
@@ -67,30 +82,30 @@ public function it_can_get_only_inactive()
6782
}
6883

6984
/** @test */
70-
public function it_can_activate_model()
85+
public function it_can_publish_model()
7186
{
72-
$method = factory(EntityWithPublishedFlag::class)->create([
87+
$model = factory(EntityWithPublishedFlag::class)->create([
7388
'is_published' => false,
7489
]);
7590

76-
EntityWithPublishedFlag::where('id', $method->id)->publish();
91+
EntityWithPublishedFlag::where('id', $model->id)->publish();
7792

78-
$method = EntityWithPublishedFlag::where('id', $method->id)->first();
93+
$model = EntityWithPublishedFlag::where('id', $model->id)->first();
7994

80-
$this->assertTrue($method->is_published);
95+
$this->assertTrue($model->is_published);
8196
}
8297

8398
/** @test */
84-
public function it_can_deactivate_model()
99+
public function it_can_unpublish_model()
85100
{
86-
$method = factory(EntityWithPublishedFlag::class)->create([
101+
$model = factory(EntityWithPublishedFlag::class)->create([
87102
'is_published' => true,
88103
]);
89104

90-
EntityWithPublishedFlag::where('id', $method->id)->unpublish();
105+
EntityWithPublishedFlag::where('id', $model->id)->unpublish();
91106

92-
$method = EntityWithPublishedFlag::withUnpublished()->where('id', $method->id)->first();
107+
$model = EntityWithPublishedFlag::withUnpublished()->where('id', $model->id)->first();
93108

94-
$this->assertFalse($method->is_published);
109+
$this->assertFalse($model->is_published);
95110
}
96111
}

0 commit comments

Comments
 (0)