-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace AchyutN\LaravelHelpers\Tests; | ||
|
||
|
||
use AchyutN\LaravelHelpers\Tests\Models\ApproveActive; | ||
|
||
class ApproveActiveTest extends BaseTestCase | ||
{ | ||
|
||
public function test_change_to_approved() | ||
{ | ||
$approve_active = ApproveActive::factory()->create(); | ||
$approve_active->setApproved(); | ||
$this->assertFalse($approve_active->approved_at == null); | ||
$this->assertTrue($approve_active->rejected_at == null); | ||
} | ||
|
||
public function test_active_count() | ||
{ | ||
ApproveActive::factory(10)->create(['rejected_at' => now()]); | ||
$this->assertEquals(0, ApproveActive::count()); | ||
} | ||
|
||
public function test_active_and_approved_count() | ||
{ | ||
ApproveActive::factory(10)->create(['approved_at' => now()]); | ||
$this->assertEquals(10, ApproveActive::count()); | ||
} | ||
|
||
public function test_active_and_pending_count() | ||
{ | ||
ApproveActive::factory(10)->create(); | ||
$this->assertEquals(0, ApproveActive::count()); | ||
} | ||
|
||
public function test_active_and_rejected_count() | ||
{ | ||
ApproveActive::factory(10)->create(['rejected_at' => now()]); | ||
$this->assertEquals(0, ApproveActive::count()); | ||
} | ||
|
||
public function test_inactive_and_approved_count() | ||
{ | ||
ApproveActive::factory(10)->create(['approved_at' => now(), 'inactive_at' => now()]); | ||
$this->assertEquals(0, ApproveActive::count()); | ||
} | ||
|
||
public function test_active_and_change_to_approved() | ||
{ | ||
$approve_active = ApproveActive::factory()->create(); | ||
$approve_active->setApproved(); | ||
$this->assertEquals(1, ApproveActive::count()); | ||
} | ||
|
||
public function test_inactive_and_change_to_approved() | ||
{ | ||
$approve_active = ApproveActive::factory()->create(['inactive_at'=>now()]); | ||
$approve_active->setApproved(); | ||
$this->assertEquals(0, ApproveActive::count()); | ||
} | ||
|
||
public function test_approved_and_change_to_active() | ||
{ | ||
$approve_active = ApproveActive::factory()->create(['approved_at'=>now(),'inactive_at'=>now()]); | ||
$approve_active->setActive(); | ||
$this->assertEquals(1, ApproveActive::count()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace AchyutN\LaravelHelpers\Tests\Factories; | ||
|
||
use AchyutN\LaravelHelpers\Tests\Models\ApproveActive; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class ApproveActiveFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var class-string<\Illuminate\Database\Eloquent\Model> | ||
*/ | ||
protected $model = ApproveActive::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'title' => $this->faker->sentence, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace AchyutN\LaravelHelpers\Tests\Models; | ||
|
||
use AchyutN\LaravelHelpers\Tests\Factories\ApproveActiveFactory; | ||
use AchyutN\LaravelHelpers\Traits\CanBeApproved; | ||
use AchyutN\LaravelHelpers\Traits\CanBeInactive; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ApproveActive extends Model | ||
{ | ||
use CanBeInactive, CanBeApproved; | ||
|
||
protected $table = 'approve_active'; | ||
|
||
protected $guarded = []; | ||
|
||
protected static function factory(int $count = 1): Factory | ||
{ | ||
if ($count && $count > 1) { | ||
return ApproveActiveFactory::times($count); | ||
} else { | ||
return ApproveActiveFactory::new(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create("approve_active", function (Blueprint $table) { | ||
$table->id(); | ||
$table->text('title'); | ||
$table->dateTime('inactive_at')->nullable(); | ||
$table->dateTime('approved_at')->nullable(); | ||
$table->dateTime('rejected_at')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists("approve_active"); | ||
} | ||
}; |