Skip to content

Commit

Permalink
[10.x] Test Improvements for hashed password (#47904)
Browse files Browse the repository at this point in the history
* [10.x] Test Improvements for `hashed` password

Verify reported issue: laravel/fortify#479

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone authored Jul 31, 2023
1 parent 4fbf481 commit a99d74a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/Integration/Database/DatabaseCustomCastsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Casts\AsStringable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;

Expand All @@ -20,6 +21,7 @@ protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
$table->json('array_object_json');
$table->text('collection');
$table->string('stringable');
$table->string('password');
$table->timestamps();
});

Expand All @@ -41,6 +43,7 @@ public function test_custom_casting()
$model->array_object_json = ['name' => 'Taylor'];
$model->collection = collect(['name' => 'Taylor']);
$model->stringable = Str::of('Taylor');
$model->password = Hash::make('secret');

$model->save();

Expand All @@ -50,6 +53,7 @@ public function test_custom_casting()
$this->assertEquals(['name' => 'Taylor'], $model->array_object_json->toArray());
$this->assertEquals(['name' => 'Taylor'], $model->collection->toArray());
$this->assertSame('Taylor', (string) $model->stringable);
$this->assertTrue(Hash::check('secret', $model->password));

$model->array_object['age'] = 34;
$model->array_object['meta']['title'] = 'Developer';
Expand Down Expand Up @@ -80,6 +84,27 @@ public function test_custom_casting()
);
}

public function test_custom_casting_using_create()
{
$model = TestEloquentModelWithCustomCasts::create([
'array_object' => ['name' => 'Taylor'],
'array_object_json' => ['name' => 'Taylor'],
'collection' => collect(['name' => 'Taylor']),
'stringable' => Str::of('Taylor'),
'password' => Hash::make('secret'),
]);

$model->save();

$model = $model->fresh();

$this->assertEquals(['name' => 'Taylor'], $model->array_object->toArray());
$this->assertEquals(['name' => 'Taylor'], $model->array_object_json->toArray());
$this->assertEquals(['name' => 'Taylor'], $model->collection->toArray());
$this->assertSame('Taylor', (string) $model->stringable);
$this->assertTrue(Hash::check('secret', $model->password));
}

public function test_custom_casting_nullable_values()
{
$model = new TestEloquentModelWithCustomCastsNullable();
Expand Down Expand Up @@ -147,6 +172,7 @@ class TestEloquentModelWithCustomCasts extends Model
'array_object_json' => AsArrayObject::class,
'collection' => AsCollection::class,
'stringable' => AsStringable::class,
'password' => 'hashed',
];
}

Expand Down

0 comments on commit a99d74a

Please sign in to comment.