generated from pestphp/pest-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
1 parent
34d9416
commit 9b6d275
Showing
12 changed files
with
195 additions
and
10 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
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
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 |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
|
||
namespace DefStudio\PestLaravelExpectations; | ||
|
||
|
||
require_once 'Expectations.php'; |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DefStudio\PestLaravelExpectations; | ||
|
||
/* | ||
* Asserts the given model exists in the database. | ||
*/ | ||
|
||
use Pest\Expectation; | ||
use function Pest\Laravel\assertDatabaseHas; | ||
|
||
expect()->extend('toExist', function (): Expectation { | ||
assertDatabaseHas( | ||
$this->value->getTable(), | ||
[$this->value->getKeyName() => $this->value->getKey()], | ||
$this->value->getConnectionName() | ||
); | ||
|
||
return $this; | ||
}); | ||
|
||
/* | ||
* Asserts that the given where condition exists in the database | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model|string $table | ||
* @param string|null $connection | ||
*/ | ||
expect()->extend('toBeInDatabase', function ($table, $connection = null): Expectation { | ||
assertDatabaseHas($table, $this->value, $connection); | ||
|
||
return $this; | ||
}); |
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\ExpectationFailedException; | ||
use Tests\Models\User; | ||
|
||
test('pass', function () { | ||
$user = User::create([ | ||
'name' => 'test user', | ||
'email' => 'email@test.xx', | ||
'password' => Hash::make('password'), | ||
]); | ||
|
||
expect(['id' => $user->id])->toBeInDatabase('users'); | ||
expect(['name' => 'test user'])->toBeInDatabase('users'); | ||
expect(['email' => 'email@test.xx'])->toBeInDatabase('users'); | ||
}); | ||
|
||
test('failures', function () { | ||
expect(['id' => 1])->toBeInDatabase('users'); | ||
})->throws(ExpectationFailedException::class); | ||
|
||
test('not failures', function () { | ||
$user = User::create([ | ||
'name' => 'test user', | ||
'email' => 'email@test.xx', | ||
'password' => Hash::make('password'), | ||
]); | ||
|
||
expect(['id' => 1])->not->toBeInDatabase('users'); | ||
})->throws(ExpectationFailedException::class); |
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,36 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\ExpectationFailedException; | ||
use Tests\Models\User; | ||
|
||
test('pass', function () { | ||
$user = User::create([ | ||
'name' => 'test user', | ||
'email' => 'email@test.xx', | ||
'password' => 'password', | ||
]); | ||
|
||
expect($user)->toExist(); | ||
}); | ||
|
||
test('failures', function () { | ||
$user = User::create([ | ||
'name' => 'test user', | ||
'email' => 'email@test.xx', | ||
'password' => 'password', | ||
]); | ||
|
||
$user->delete(); | ||
|
||
expect($user)->toExist(); | ||
})->throws(ExpectationFailedException::class); | ||
|
||
test('not failures', function () { | ||
$user = User::create([ | ||
'name' => 'test user', | ||
'email' => 'email@test.xx', | ||
'password' => 'password', | ||
]); | ||
|
||
expect($user)->not->toExist(); | ||
})->throws(ExpectationFailedException::class); |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
<?php | ||
|
||
namespace Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class User extends Model | ||
{ | ||
protected $fillable = [ | ||
'name', | ||
'email', | ||
'password', | ||
]; | ||
} |
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,5 @@ | ||
<?php | ||
|
||
use Tests\TestCase; | ||
|
||
uses(TestCase::class)->in('Expect'); |
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 Tests; | ||
|
||
class TestCase extends \Orchestra\Testbench\TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->loadMigrationsFrom(__DIR__ . '/resources/database/migrations'); | ||
$this->artisan('migrate', ['--database' => 'testbench'])->run(); | ||
} | ||
|
||
protected function getEnvironmentSetUp($app): void | ||
{ | ||
$app['config']->set('view.paths', [ | ||
__DIR__ . '/resources/views', | ||
]); | ||
$app['config']->set('app.key', 'base64:Hupx3yAySikrM2/edkZQNQHslgDWYfiBfCuSThJ5SK8='); | ||
$app['config']->set('database.default', 'testbench'); | ||
$app['config']->set('database.connections.testbench', [ | ||
'driver' => 'sqlite', | ||
'database' => ':memory:', | ||
'prefix' => '', | ||
]); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/resources/database/migrations/2014_10_12_000000_create_users_table.php
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,36 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateUsersTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('users', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name'); | ||
$table->string('email')->unique(); | ||
$table->timestamp('email_verified_at')->nullable(); | ||
$table->string('password'); | ||
$table->rememberToken(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('users'); | ||
} | ||
} |