Skip to content

Commit

Permalink
refactor: added code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoFerrazfs committed Oct 9, 2024
1 parent 0ecbd71 commit 6f16c75
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/Model/Casts/CastResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CastResolver
private const IMMUTABLE_DATE_TIME = 'immutable_datetime';

/**
* @var array|string[]
* @var string[]
*/
public static array $validCasts = [
self::DATE_TIME,
Expand Down
2 changes: 1 addition & 1 deletion src/Query/BulkWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BulkWrite
{
/**
* Hold bulk write operations to run.
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification
* @var array<array<string,ObjectId|string|array>>
*/
private array $operations = [];

Expand Down
2 changes: 0 additions & 2 deletions src/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public function sequence(?int $value = null): int

/**
* Prepares the field to be the datetime that the document has been created.
*
* @param mixed $value value that will be evaluated
*/
public function createdAtTimestamp(mixed $value): UTCDateTime
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/DateTimeCastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testShouldSaveAndReadLegacyRecordWithCastedAttibutes(): void
// Set
$entity = new class extends LegacyRecordUser {
/**
* @var array|string[]
* @var string[]
*/
protected array $casts = [
'expires_at' => 'datetime',
Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/ExpirablePrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class ExpirablePrice extends Price
{
/**
* @var array|string[]
* @var array<string,string>
*/
protected array $casts = [
'expires_at' => 'datetime',
Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/Legacy/LegacyRecordUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LegacyRecordUser extends LegacyRecord
protected bool $timestamps = true;

/**
* @var array|string[]
* @var string[]
*/
protected array $fillable = [
'name',
Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/Legacy/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Product extends LegacyRecord
{
/**
* @var array<string,object>
* @var array<string,array<string,string>>
*/
public array $with = [
'price' => [
Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/PolymorphedReferencedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class PolymorphedReferencedUser extends ReferencedUser
{
/**
* @var array|string[]
* @var string[]
*/
protected array $fillable = [
'type',
Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/ReferencedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ReferencedUser extends AbstractModel implements PolymorphableModelInterfac
protected bool $timestamps = false;

/**
* @var array|string[]
* @var string[]
*/
protected array $fillable = [
'type',
Expand Down
49 changes: 16 additions & 33 deletions tests/Unit/DataMapper/SchemaMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Mongolid\DataMapper;

use Mockery as m;
use Mockery\MockInterface;
use Mongolid\Container\Container;
use Mongolid\Schema\Schema;
use Mongolid\TestCase;
use Mockery\LegacyMockInterface;

class SchemaMapperTest extends TestCase
{
Expand Down Expand Up @@ -182,49 +182,32 @@ public function testShouldMapAnArrayValueToAnotherSchema(): void
$schema = m::mock(Schema::class);
$mySchema = m::mock(Schema::class);
$schemaMapper = new SchemaMapper($schema);
$anotherSchemaMapper = m::mock(SchemaMapper::class);
$value = ['foo' => 'bar'];
$test = $this;

// Act
Container::instance('Xd\MySchema', $mySchema);

// When instantiating the SchemaMapper with the specified $param as dependency
Container::bind(
SchemaMapper::class,
/**
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
*/
function ($container, $params) use ($value, $mySchema, $test): LegacyMockInterface {
// Check if mySchema has been injected correctly
$test->assertSame($mySchema, $params['schema']);

// Instantiate a SchemaMapper with mySchema
$anotherSchemaMapper = m::mock(
SchemaMapper::class,
[$params['schema']]
);

// Set expectation to receive a map call
$anotherSchemaMapper->shouldReceive('map')
->once()
->with($value)
->andReturn(['foo' => 'PARSED']);

return $anotherSchemaMapper;
}
fn (): MockInterface => $anotherSchemaMapper
);

// Assert
$this->assertEquals(
[
['foo' => 'PARSED'],
],
$this->callProtected(
$schemaMapper,
'mapToSchema',
[$value, 'Xd\MySchema']
)
// Set expectation to receive a map call
$anotherSchemaMapper->expects()
->map($value)
->andReturn(['foo' => 'PARSED']);

// Actions
$result = $this->callProtected(
$schemaMapper,
'mapToSchema',
[$value, 'Xd\MySchema']
);

// Assert
$this->assertEquals([['foo' => 'PARSED']], $result);
}

public function testShouldParseToArrayGettingObjectAttributes(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Model/HasAttributesTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public function testShouldCastAttributeToUTCDateTimeWhenSettingAttributes(): voi
$model = new class () extends AbstractModel
{
/**
* @var array|string[]
* @var array<string, string>
*/
protected array $casts = [
'expires_at' => 'datetime',
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function testShouldUpdateUnsettingFields(): void
$model = new class () extends ReplaceCollectionModel
{
/**
* @var array|string[]
* @var string[]
*/
public array $fillable = [
'name',
Expand Down

0 comments on commit 6f16c75

Please sign in to comment.