Skip to content

Commit 49b4fa5

Browse files
committed
test: example test with attribute usage
1 parent b0d0c04 commit 49b4fa5

File tree

6 files changed

+43
-42
lines changed

6 files changed

+43
-42
lines changed

LICENSE renamed to LICENSE.md

File renamed without changes.

README.md

+26-32
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<strong>Quality</strong><br>
2525
<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>
2626
<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>
27-
<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>
27+
<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>
2828
</p>
2929
<p align="center">
3030
<strong>Community</strong><br>
@@ -201,62 +201,56 @@ class MyController extends Controller
201201

202202
<br>
203203

204-
## 🧪 Running Tests
204+
## 🔒 Security Policy
205205

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

208-
To run phpunit and pest tests, run the following command:
209-
210-
```bash
211-
make test
212-
```
208+
<br>
213209

214-
### → Static Analysis
210+
## 🙌 Want to Contribute?
215211

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

218-
```bash
219-
make lint-stan
220-
```
214+
- 🤔 [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+)
215+
- 🐛 [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+)
216+
- 📖 [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+)
217+
- 👨‍💻 Contribute to the code
221218

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

224-
Fix code using The PHP Coding Standards Fixer (PHP CS Fixer) to follow our standards:
225-
226-
```bash
227-
make lint-php
228-
```
221+
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=for-the-badge)](https://conventionalcommits.org)
229222

230223
<br>
231224

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

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

238-
## 🙆🏼‍♂️ Author Information
235+
## 🌐 Social Links
239236

240-
Created in **2023** by [lotyp / wayofdev](https://github.com/wayofdev)
237+
- **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).
238+
- **Discord:** Join our community on [Discord](https://discord.gg/CE3TcCC5vr).
241239

242240
<br>
243241

244-
## 🙌 Want to Contribute?
245-
246-
Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:
242+
## ⚖️ License
247243

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

253246
<br>
254247

255248
## 🧱 Credits and Useful Resources
256249

257-
This repository is based on code from following repositories:
250+
This repository is inspired by the following projects:
258251

259252
- [spiral/serializer](https://github.com/spiral/serializer)
260253
- [spiral-packages/symfony-serializer](https://github.com/spiral-packages/symfony-serializer)
261254
- [jeromegamez/ramsey-uuid-normalizer](https://github.com/jeromegamez/ramsey-uuid-normalizer)
262255
- [wayofdev/laravel-jms-serializer](https://github.com/wayofdev/laravel-jms-serializer)
256+
- [symfony/serializer](https://github.com/symfony/serializer)

psalm-baseline.xml

-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
</PossiblyUnusedMethod>
77
</file>
88
<file src="src/Bridge/Laravel/Providers/SerializerServiceProvider.php">
9-
<MixedArgument>
10-
<code><![CDATA[$strategy]]></code>
11-
<code><![CDATA[$strategy]]></code>
12-
</MixedArgument>
139
<MixedArgumentTypeCoercion>
1410
<code><![CDATA[[
1511
'default' => $config->get('serializer.default'),
@@ -19,10 +15,6 @@
1915
'metadataLoader' => $config->get('serializer.metadataLoader'),
2016
]]]></code>
2117
</MixedArgumentTypeCoercion>
22-
<MixedAssignment>
23-
<code><![CDATA[$strategy]]></code>
24-
<code><![CDATA[$strategy]]></code>
25-
</MixedAssignment>
2618
<MixedInferredReturnType>
2719
<code><![CDATA[EncoderRegistrationStrategy]]></code>
2820
<code><![CDATA[NormalizerRegistrationStrategy]]></code>

src/Bridge/Laravel/Providers/SerializerServiceProvider.php

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private function registerNormalizerRegistry(): void
9696
});
9797

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

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

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

119121
return new EncoderRegistry($strategy);

tests/app/Response/Item.php

+10
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
use Ramsey\Uuid\Uuid;
99
use Ramsey\Uuid\UuidInterface;
1010
use Symfony\Component\Serializer\Annotation\Groups;
11+
use Symfony\Component\Serializer\Attribute\SerializedName;
1112

1213
final class Item
1314
{
15+
#[Groups(['default', 'private'])]
16+
#[SerializedName('emailAddress')]
17+
public string $email;
18+
1419
#[Groups(['default', 'private'])]
1520
private readonly UuidInterface $id;
1621

@@ -52,6 +57,11 @@ public function dateTime(): ?DateTimeImmutable
5257
return $this->dateTime;
5358
}
5459

60+
public function emailAddress(): string
61+
{
62+
return $this->email;
63+
}
64+
5565
public function onlyForAdmin(): string
5666
{
5767
return $this->onlyForAdmin;

tests/src/Functional/Bridge/Laravel/Http/ResponseFactoryTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ public function it_uses_given_context(): void
8383

8484
$dateTime = new DateTimeImmutable();
8585

86-
$response = $responseFactory->create(new Item($dateTime));
86+
$item = new Item($dateTime);
87+
$item->email = '[email protected]';
88+
89+
$response = $responseFactory->create($item);
8790

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

0 commit comments

Comments
 (0)