Skip to content

Commit

Permalink
test: example test with attribute usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed Jun 18, 2024
1 parent b0d0c04 commit 49b4fa5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
File renamed without changes.
58 changes: 26 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<strong>Quality</strong><br>
<a href="https://app.codecov.io/gh/wayofdev/laravel-symfony-serializer" target="_blank"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/wayofdev/laravel-symfony-serializer?style=flat-square&logo=codecov"></a>
<a href="https://dashboard.stryker-mutator.io/reports/github.com/wayofdev/laravel-symfony-serializer/master" target="_blank"><img alt="Mutation testing badge" src="https://img.shields.io/endpoint?style=flat-square&label=mutation%20score&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fwayofdev%2Flaravel-symfony-serializer%2Fmaster"></a>
<a href=""><img src="https://img.shields.io/badge/phpstan%20level-6%20of%209-yellowgreen?style=flat-square" alt="PHP Stan Level 6 of 9"></a>
<a href=""><img src="https://img.shields.io/badge/phpstan%20level-8%20of%209-brightgreen?style=flat-square" alt="PHP Stan Level 6 of 9"></a>
</p>
<p align="center">
<strong>Community</strong><br>
Expand Down Expand Up @@ -201,62 +201,56 @@ class MyController extends Controller

<br>

## 🧪 Running Tests
## 🔒 Security Policy

### → PHPUnit tests
This project has a [security policy](.github/SECURITY.md).

To run phpunit and pest tests, run the following command:

```bash
make test
```
<br>

### → Static Analysis
## 🙌 Want to Contribute?

Code quality using PHPStan:
Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:

```bash
make lint-stan
```
- 🤔 [Suggest a feature](https://github.com/wayofdev/laravel-symfony-serializer/issues/new?assignees=&labels=type%3A+enhancement&projects=&template=2-feature-request.yml&title=%5BFeature%5D%3A+)
- 🐛 [Report an issue](https://github.com/wayofdev/laravel-symfony-serializer/issues/new?assignees=&labels=type%3A+documentation%2Ctype%3A+maintenance&projects=&template=1-bug-report.yml&title=%5BBug%5D%3A+)
- 📖 [Improve documentation](https://github.com/wayofdev/laravel-symfony-serializer/issues/new?assignees=&labels=type%3A+documentation%2Ctype%3A+maintenance&projects=&template=4-docs-bug-report.yml&title=%5BDocs%5D%3A+)
- 👨‍💻 Contribute to the code

### → Coding Standards Fixing
You are more than welcome. Before contributing, kindly check our [contribution guidelines](.github/CONTRIBUTING.md).

Fix code using The PHP Coding Standards Fixer (PHP CS Fixer) to follow our standards:

```bash
make lint-php
```
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=for-the-badge)](https://conventionalcommits.org)

<br>

## 🤝 License

[![Licence](https://img.shields.io/github/license/wayofdev/laravel-symfony-serializer?style=for-the-badge&color=blue)](./LICENSE)
## 🫡 Contributors

<p align="left">
<a href="https://github.com/wayofdev/laravel-symfony-serializer/graphs/contributors">
<img align="left" src="https://img.shields.io/github/contributors-anon/wayofdev/laravel-symfony-serializer?style=for-the-badge" alt="Contributors Badge"/>
</a>
<br>
<br>
</p>

## 🙆🏼‍♂️ Author Information
## 🌐 Social Links

Created in **2023** by [lotyp / wayofdev](https://github.com/wayofdev)
- **Twitter:** Follow our organization [@wayofdev](https://twitter.com/intent/follow?screen_name=wayofdev) and the author [@wlotyp](https://twitter.com/intent/follow?screen_name=wlotyp).
- **Discord:** Join our community on [Discord](https://discord.gg/CE3TcCC5vr).

<br>

## 🙌 Want to Contribute?

Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:
## ⚖️ License

- 🤔 Suggest a feature
- 🐛 Report an issue
- 📖 Improve documentation
- 👨‍💻 Contribute to the code
[![Licence](https://img.shields.io/github/license/wayofdev/laravel-symfony-serializer?style=for-the-badge&color=blue)](./LICENSE.md)

<br>

## 🧱 Credits and Useful Resources

This repository is based on code from following repositories:
This repository is inspired by the following projects:

- [spiral/serializer](https://github.com/spiral/serializer)
- [spiral-packages/symfony-serializer](https://github.com/spiral-packages/symfony-serializer)
- [jeromegamez/ramsey-uuid-normalizer](https://github.com/jeromegamez/ramsey-uuid-normalizer)
- [wayofdev/laravel-jms-serializer](https://github.com/wayofdev/laravel-jms-serializer)
- [symfony/serializer](https://github.com/symfony/serializer)
8 changes: 0 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
</PossiblyUnusedMethod>
</file>
<file src="src/Bridge/Laravel/Providers/SerializerServiceProvider.php">
<MixedArgument>
<code><![CDATA[$strategy]]></code>
<code><![CDATA[$strategy]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[[
'default' => $config->get('serializer.default'),
Expand All @@ -19,10 +15,6 @@
'metadataLoader' => $config->get('serializer.metadataLoader'),
]]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$strategy]]></code>
<code><![CDATA[$strategy]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[EncoderRegistrationStrategy]]></code>
<code><![CDATA[NormalizerRegistrationStrategy]]></code>
Expand Down
2 changes: 2 additions & 0 deletions src/Bridge/Laravel/Providers/SerializerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private function registerNormalizerRegistry(): void
});

$this->app->singleton(NormalizerRegistryInterface::class, static function (Application $app): NormalizerRegistryInterface {
/** @var NormalizerRegistrationStrategy $strategy */
$strategy = $app->get(NormalizerRegistrationStrategy::class);

return new NormalizerRegistry($strategy);
Expand All @@ -114,6 +115,7 @@ private function registerEncoderRegistry(): void
});

$this->app->singleton(EncoderRegistryInterface::class, static function (Application $app): EncoderRegistryInterface {
/** @var EncoderRegistrationStrategy $strategy */
$strategy = $app->get(EncoderRegistrationStrategy::class);

return new EncoderRegistry($strategy);
Expand Down
10 changes: 10 additions & 0 deletions tests/app/Response/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Attribute\SerializedName;

final class Item
{
#[Groups(['default', 'private'])]
#[SerializedName('emailAddress')]
public string $email;

#[Groups(['default', 'private'])]
private readonly UuidInterface $id;

Expand Down Expand Up @@ -52,6 +57,11 @@ public function dateTime(): ?DateTimeImmutable
return $this->dateTime;
}

public function emailAddress(): string
{
return $this->email;
}

public function onlyForAdmin(): string
{
return $this->onlyForAdmin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ public function it_uses_given_context(): void

$dateTime = new DateTimeImmutable();

$response = $responseFactory->create(new Item($dateTime));
$item = new Item($dateTime);
$item->email = '[email protected]';

$response = $responseFactory->create($item);

$formattedDateTime = $dateTime->format(DateTimeInterface::ATOM);
$expectedResponse = sprintf(
'{"id":"0cd74c72-8920-4e4e-86c3-19fdd5103514","onlyForAdmin":"secret","dateTime":"%s"}',
'{"emailAddress":"[email protected]","id":"0cd74c72-8920-4e4e-86c3-19fdd5103514","onlyForAdmin":"secret","dateTime":"%s"}',
$formattedDateTime
);

Expand Down

0 comments on commit 49b4fa5

Please sign in to comment.