Skip to content

Commit d215e35

Browse files
Merge branch 'main' into 199
2 parents c12e0dd + d139690 commit d215e35

7 files changed

Lines changed: 87 additions & 3 deletions

File tree

‎.github/ISSUE_TEMPLATE/bug.md‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
name: Bug report
3+
about: Report a task, transformer or engine behaving incorrectly
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
---
8+
9+
## Description
10+
11+
<!-- What is wrong, in one or two sentences. List each symptom when there are several (wrong output, exception, silent failure...) -->
12+
13+
### Reproduction
14+
15+
<!-- A minimal process configuration reproducing the bug, ideally a demo.* process from https://github.com/cleverage/process-bundle-demo -->
16+
17+
```yaml
18+
clever_age_process:
19+
configurations:
20+
demo.<name>:
21+
tasks:
22+
<task>:
23+
service: '@CleverAge\ProcessBundle\Task\...'
24+
options: {}
25+
outputs: [debug]
26+
debug:
27+
service: '@CleverAge\ProcessBundle\Task\Debug\DebugTask'
28+
```
29+
30+
<!-- Input data, command and actual output -->
31+
32+
```
33+
$ bin/console cleverage:process:execute demo.<name>
34+
```
35+
36+
Expected: `<expected output>`
37+
38+
Tested on `main` (`<commit>`), PHP x.y, Symfony x.y.
39+
40+
### Cause
41+
42+
<!-- Optional: where the bug comes from, with links to the relevant lines -->
43+
44+
### Proposed fix
45+
46+
<!-- Optional: how to fix it, and which documentation must be updated -->
47+
48+
## Requirements
49+
50+
* Documentation updates
51+
- [ ] Reference
52+
- [ ] Cookbooks
53+
- [ ] Changelog
54+
* [ ] Unit tests
55+
56+
## Breaking changes
57+
58+
<!-- Behaviour changes introduced by the fix, or "None" with the reason (e.g. every configuration of this task currently fails) -->

‎.github/ISSUE_TEMPLATE/config.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
---
2+
name: Feature request / other
3+
about: Propose an enhancement, a refactoring or any other change
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
---
8+
19
## Description
210

311
<!-- Please describe the issue here -->

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Latest
99
* [#192](https://github.com/cleverage/process-bundle/issues/192) Fix CommandRunnerTask: only pass the `options` option to `Process::setOptions()`, support string `commandline` through `Process::fromShellCommandline()`, validate option types. Update documentation, add tests.
1010
* [#194](https://github.com/cleverage/process-bundle/issues/194) Fix ProcessLauncherTask: the `process_options` normalizer returned an array despite its scalar return type, so the task always failed with a `TypeError`. Update documentation, add tests.
1111
* [#189](https://github.com/cleverage/process-bundle/issues/189) Fix EventDispatcherTask: dispatch the event under the `event_name` option (regression since v4.0). `event_name` is now optional: when `null` (default), the event is dispatched under its class name. Update documentation, add tests.
12+
* [#198](https://github.com/cleverage/process-bundle/issues/198) Fix DateParserTransformer: a `\DateTimeImmutable` input is converted to a `\DateTime` instead of throwing a `TypeError`. Update documentation, add tests.
1213
* [#199](https://github.com/cleverage/process-bundle/issues/199) Fix PregFilterTransformer: an array `replacement` is no longer cast to the string `"Array"`, and requires an array `pattern`. Update documentation, add tests.
1314

1415
## Deprecated

‎docs/reference/transformers/date_parser_transformer.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Accepted inputs
1414

1515
* `string`: a date matching the configured `format`
1616
* `\DateTime`, returned unchanged
17+
* `\DateTimeImmutable`, converted to a `\DateTime` (same date, time and timezone)
1718
* Any falsy value (`null`, `''`, `false`…), returned unchanged
1819

1920
A string that cannot be parsed with the given format throws an `\UnexpectedValueException`.
@@ -55,5 +56,3 @@ Notes
5556

5657
Fields missing from `format` are taken from the current time (e.g. with `Y-m-d`, the time part is the current time). Use
5758
the `!` or `|` format characters to reset them, e.g. `'!Y-m-d'`.
58-
59-
A `\DateTimeImmutable` input is not returned unchanged: it is passed to `createFromFormat()` and throws a `\TypeError`.

‎src/Transformer/Date/DateParserTransformer.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\OptionsResolver\OptionsResolver;
1818

1919
/**
20-
* Transformer aiming to take a date as an input (object or a format defined string) to strictly output aa \DateTime.
20+
* Transformer aiming to take a date as an input (object or a format defined string) to strictly output a \DateTime.
2121
*
2222
* @example in YML config
2323
* transformers:
@@ -32,6 +32,10 @@ public function transform(mixed $value, array $options = []): mixed
3232
return $value;
3333
}
3434

35+
if ($value instanceof \DateTimeImmutable) {
36+
return \DateTime::createFromImmutable($value);
37+
}
38+
3539
$date = \DateTime::createFromFormat($options['format'], $value);
3640

3741
if (!$date) {

‎tests/Transformer/Date/DateParserTransformerTest.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ public function testTransformDateTimeObject(): void
6969
$this->assertSame($value, $transformedValue);
7070
}
7171

72+
public function testTransformDateTimeImmutableObject(): void
73+
{
74+
$transformer = new DateParserTransformer();
75+
$value = new \DateTimeImmutable('2023-09-28 12:34:56', new \DateTimeZone('Europe/Paris'));
76+
$options = ['format' => 'Y-m-d'];
77+
78+
$transformedValue = $transformer->transform($value, $options);
79+
80+
$this->assertInstanceOf(\DateTime::class, $transformedValue);
81+
$this->assertEquals($value, \DateTimeImmutable::createFromMutable($transformedValue));
82+
$this->assertSame('Europe/Paris', $transformedValue->getTimezone()->getName());
83+
}
84+
7285
public function testGetCode(): void
7386
{
7487
$transformer = new DateParserTransformer();

0 commit comments

Comments
 (0)