generated from spatie/package-skeleton-laravel
-
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
1 parent
5522e61
commit de5b305
Showing
3 changed files
with
53 additions
and
165 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 |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"pest_2.34.4","defects":[],"times":{"P\\Tests\\LaravelActionTest::__pest_evaluable_it_can_make_a_menu_action":0.001,"P\\Tests\\LaravelActionTest::__pest_evaluable_it_can_make_an_API_action":0.001,"P\\Tests\\LaravelActionTest::__pest_evaluable_it_can_make_an_action_without_model_option":0.003,"P\\Tests\\LaravelActionTest::__pest_evaluable_it_has_make_action_command":0.004,"P\\Tests\\LaravelActionTest::__pest_evaluable_it_can_make_an_action_with_model_option":0.002,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_creates_a_user_with_valid_data":0.136,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_applies_hashing_to_password_field":0.141,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_uses_transactions_during_execution":0.099,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_removes_confirmation_fields_from_inputs":0.003,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_validates_required_fields":0.001,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_throws_exception_if_model_is_not_set":0.066,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_applies_encryption_to_specified_fields":0.069,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_creates_a_user_with_valid_data":0.129,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_applies_encryption_to_specified_fields":0.065,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_uses_transactions_during_execution":0.094,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_validates_required_fields":0.001,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_throws_exception_if_model_is_not_set":0.062,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_applies_hashing_to_password_field":0.124,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_removes_confirmation_fields_from_inputs":0.001}} | ||
{"version":"pest_2.34.4","defects":[],"times":{"P\\Tests\\LaravelActionTest::__pest_evaluable_it_can_make_a_menu_action":0.002,"P\\Tests\\LaravelActionTest::__pest_evaluable_it_can_make_an_API_action":0.001,"P\\Tests\\LaravelActionTest::__pest_evaluable_it_can_make_an_action_without_model_option":0.002,"P\\Tests\\LaravelActionTest::__pest_evaluable_it_has_make_action_command":0.004,"P\\Tests\\LaravelActionTest::__pest_evaluable_it_can_make_an_action_with_model_option":0.001,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_creates_a_user_with_valid_data":0.136,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_applies_hashing_to_password_field":0.141,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_uses_transactions_during_execution":0.099,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_removes_confirmation_fields_from_inputs":0.003,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_validates_required_fields":0.001,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_throws_exception_if_model_is_not_set":0.066,"P\\Tests\\AbstractActionTest::__pest_evaluable_it_applies_encryption_to_specified_fields":0.069,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_creates_a_user_with_valid_data":0.124,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_applies_encryption_to_specified_fields":0.063,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_uses_transactions_during_execution":0.093,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_validates_required_fields":0.001,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_throws_exception_if_model_is_not_set":0.062,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_applies_hashing_to_password_field":0.122,"P\\Tests\\ResourceActionTest::__pest_evaluable_it_removes_confirmation_fields_from_inputs":0.001}} |
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 |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
expect($record)->toBeInstanceOf(User::class) | ||
->and($record->name)->toBe('John Doe') | ||
->and($record->email)->toBe('[email protected]') | ||
->and(Hash::check('secretpassword', $record->password))->toBeTrue(); // Check if the password is hashed | ||
->and(Hash::check('secretpassword', $record->password))->toBeTrue(); | ||
}); | ||
|
||
// it validates required fields | ||
|
@@ -54,9 +54,8 @@ | |
]; | ||
|
||
// Stub a class without a model definition | ||
$stubAction = new class($inputs) extends CreateUserAction | ||
{ | ||
protected string $model = ''; // Not setting the model on purpose | ||
$stubAction = new class($inputs) extends CreateUserAction { | ||
protected string $model = ''; // Intentionally leave model empty | ||
}; | ||
|
||
// Act & Assert | ||
|
@@ -73,13 +72,13 @@ | |
]; | ||
|
||
$action = new CreateUserAction($inputs); | ||
$action->setHashFields(['password']); | ||
$action->setProperty('hashFields', ['password']); // Use setProperty to define hash fields | ||
|
||
// Act | ||
$record = $action->execute(); | ||
|
||
// Assert | ||
expect(Hash::check('secretpassword', $record->password))->toBeTrue(); // Verify password hash | ||
expect(Hash::check('secretpassword', $record->password))->toBeTrue(); | ||
}); | ||
|
||
// it removes confirmation fields from inputs | ||
|
@@ -113,16 +112,16 @@ | |
|
||
$action = new CreateUserAction($inputs); | ||
|
||
// // Mock the database connection and query builder | ||
// Mock the database connection and query builder | ||
$mockConnection = Mockery::mock(); | ||
$mockQueryBuilder = Mockery::mock(); | ||
|
||
// Mock the chain of methods on the query builder | ||
$mockConnection->shouldReceive('table')->andReturn($mockQueryBuilder); | ||
$mockQueryBuilder->shouldReceive('useWritePdo')->andReturn($mockQueryBuilder); | ||
$mockQueryBuilder->shouldReceive('where')->andReturn($mockQueryBuilder); | ||
$mockQueryBuilder->shouldReceive('count')->andReturn(0); // Return a count of 0 for the test | ||
$mockQueryBuilder->shouldReceive('updateOrCreate')->andReturn(Mockery::mock(User::class)); // Mock the final result | ||
$mockQueryBuilder->shouldReceive('count')->andReturn(0); | ||
$mockQueryBuilder->shouldReceive('updateOrCreate')->andReturn(Mockery::mock(User::class)); | ||
|
||
// Mock the transaction flow | ||
DB::shouldReceive('connection')->andReturn($mockConnection); | ||
|
@@ -139,6 +138,7 @@ | |
|
||
// it applies encryption to specified fields | ||
it('applies encryption to specified fields', function () { | ||
// Arrange | ||
$inputs = [ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
|
@@ -147,9 +147,7 @@ | |
]; | ||
|
||
$action = new CreateUserAction($inputs); | ||
|
||
// Assuming we want to encrypt the 'ssn' field | ||
$action->setEncryptFields(['ssn']); | ||
$action->setProperty('encryptFields', ['ssn']); // Use setProperty to define encryption fields | ||
|
||
// Act | ||
$record = $action->execute(); | ||
|
@@ -159,6 +157,5 @@ | |
|
||
// Ensure 'ssn' field was encrypted | ||
$decryptedSSN = decrypt($record->ssn); | ||
|
||
expect($decryptedSSN)->toBe('123-45-6789'); | ||
}); |