Skip to content

Commit

Permalink
fix: mapPrivatePropertiesAndMethod should not be mandatory (#9)
Browse files Browse the repository at this point in the history
fix: mapPrivatePropertiesAndMethod should not be mandatory
  • Loading branch information
nikophil authored Oct 23, 2023
1 parent 4029858 commit e1dba93
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- [GH#11](https://github.com/jolicode/automapper/pull/11) Added phpstan level 5 in CI

### Fixed
- [GH#9](https://github.com/jolicode/automapper/pull/9) fix: `mapPrivatePropertiesAndMethod` should not be mandatory

## [8.0.1] - 2023-10-04
### Changed
- [GH#6](https://github.com/jolicode/automapper/pull/6) Document all AST code by explaining what it generates
Expand Down
2 changes: 1 addition & 1 deletion src/Extractor/FromSourceMappingExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getPropertiesMapping(MapperMetadataInterface $mapperMetadata): a
$this->getMaxDepth($mapperMetadata->getSource(), $property),
$this->isIgnoredProperty($mapperMetadata->getSource(), $property),
$this->isIgnoredProperty($mapperMetadata->getTarget(), $property),
PropertyReadInfo::VISIBILITY_PUBLIC === ($this->readInfoExtractor->getReadInfo($mapperMetadata->getSource(), $property)?->getVisibility() ?? true)
PropertyReadInfo::VISIBILITY_PUBLIC === ($this->readInfoExtractor->getReadInfo($mapperMetadata->getSource(), $property)?->getVisibility() ?? PropertyReadInfo::VISIBILITY_PUBLIC),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Extractor/FromTargetMappingExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getPropertiesMapping(MapperMetadataInterface $mapperMetadata): a
$this->getMaxDepth($mapperMetadata->getTarget(), $property),
$this->isIgnoredProperty($mapperMetadata->getSource(), $property),
$this->isIgnoredProperty($mapperMetadata->getTarget(), $property),
PropertyReadInfo::VISIBILITY_PUBLIC === ($this->readInfoExtractor->getReadInfo($mapperMetadata->getSource(), $property)?->getVisibility() ?? true),
PropertyReadInfo::VISIBILITY_PUBLIC === ($this->readInfoExtractor->getReadInfo($mapperMetadata->getSource(), $property)?->getVisibility() ?? PropertyReadInfo::VISIBILITY_PUBLIC),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Extractor/SourceTargetMappingExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getPropertiesMapping(MapperMetadataInterface $mapperMetadata): a
$maxDepth,
$this->isIgnoredProperty($mapperMetadata->getSource(), $property),
$this->isIgnoredProperty($mapperMetadata->getTarget(), $property),
PropertyReadInfo::VISIBILITY_PUBLIC === ($this->readInfoExtractor->getReadInfo($mapperMetadata->getSource(), $property)?->getVisibility() ?? true),
PropertyReadInfo::VISIBILITY_PUBLIC === ($this->readInfoExtractor->getReadInfo($mapperMetadata->getSource(), $property)?->getVisibility() ?? PropertyReadInfo::VISIBILITY_PUBLIC),
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/MapperMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ private function buildPropertyMapping(): void
null,
new CallbackTransformer($property),
$property,
false
false,
isPublic: true,
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion tests/AutoMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testAutoMapperFromArray(): void

public function testAutoMapperFromArrayCustomDateTime(): void
{
$this->buildAutoMapper(mapPrivatePropertiesAndMethod: true, classPrefix: 'CustomDateTime_');
$this->buildAutoMapper(classPrefix: 'CustomDateTime_');

$dateTime = \DateTime::createFromFormat(\DateTime::RFC3339, '1987-04-30T06:00:00Z');
$customFormat = 'U';
Expand Down Expand Up @@ -581,6 +581,8 @@ public function testAllowedAttributes(): void
$address->setCity('some city');
$user->setAddress($address);

$this->buildAutoMapper(mapPrivatePropertiesAndMethod: true);

/** @var Fixtures\UserDTO $userDto */
$userDto = $this->autoMapper->map($user, Fixtures\UserDTO::class, [MapperContext::ALLOWED_ATTRIBUTES => ['id', 'age', 'address']]);

Expand Down Expand Up @@ -615,6 +617,7 @@ public function testMappingWithTargetObjectWithNoObjectToPopulate(): void
});

$user = new Fixtures\User(1, 'yolo', '13');

$userDto = $this->autoMapper->map($user, Fixtures\UserDTOMerged::class);

self::assertArrayHasKey('name', $userDto->getProperties());
Expand Down

0 comments on commit e1dba93

Please sign in to comment.