Skip to content

[10.x] Fix Process::fake() never matching multi-line commands - #50164

Merged
taylorotwell merged 1 commit into
laravel:10.xfrom
SjorsO:10.x
Feb 20, 2024
Merged

taylorotwell merged 1 commit into
laravel:10.xfrom
SjorsO:10.x

Conversation

@SjorsO

@SjorsO SjorsO commented Feb 20, 2024 •

Copy link
Copy Markdown
Contributor

It is currently impossible to use patterns with Process::fake() to match a multi-line command. For example:

$result = Process::run(<<<BASH
git clone --depth 1 \
      --single-branch \
      --branch main \
      git://some-url .
BASH);
Process::preventStrayProcesses();

Process::fake(['*' => 'faked output']);

The test above will always throw an "Attempted process without a matching fake" exception. This is because the pattern is matched using Str::is(), and Str::is() always returns false for multi-line strings (the regex it uses doesn't have the m option).

This PR is only a partial fix, using any pattern that isn't * (like git clone* for example) still won't work if the command has multiple lines.

I'm not sure what the best approach for a proper fix is. I assume modifying Str::is() isn't an option.

I know it isn't ideal that this PR isn't a proper fix, but this change at least makes it possible to test multi-line commands. I'm currently resorting to monkey patching the PendingProcess file in the vendor directory. I could re-write my commands to not be multi-line, but some of them are pretty long so I'd rather not do that.

Related issue: #50158

@taylorotwell
taylorotwell merged commit 08bf276 into laravel:10.x Feb 20, 2024
itinerare pushed a commit to itinerare/Alcyone that referenced this pull request Feb 26, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [laravel/framework](https://laravel.com) ([source](https://github.com/laravel/framework)) | require | minor | `10.44.0` -> `10.45.1` |

---

### Release Notes

<details>
<summary>laravel/framework (laravel/framework)</summary>

### [`v10.45.1`](https://github.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10451---2024-02-21)

[Compare Source](laravel/framework@v10.45.0...v10.45.1)

-   Fix typehint for ResetPassword::toMailUsing() by [@&#8203;KKSzymanowski](https://github.com/KKSzymanowski) in laravel/framework#50163
-   \[10.x] Fix Process::fake() never matching multi-line commands by [@&#8203;SjorsO](https://github.com/SjorsO) in laravel/framework#50164

### [`v10.45.0`](https://github.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10450---2024-02-20)

[Compare Source](laravel/framework@v10.44.0...v10.45.0)

-   \[10.x] Update `Stringable` phpdoc by [@&#8203;milwad-dev](https://github.com/milwad-dev) in laravel/framework#50075
-   \[10.x] Allow `Collection::select()` to work on `ArrayAccess` by [@&#8203;axlon](https://github.com/axlon) in laravel/framework#50072
-   \[10.x] Add `before` to the `PendingBatch` by [@&#8203;xiCO2k](https://github.com/xiCO2k) in laravel/framework#50058
-   \[10.x] Adjust rules call sequence by [@&#8203;driesvints](https://github.com/driesvints) in laravel/framework#50084
-   \[10.x] Fixes `Illuminate\Support\Str::fromBase64()` return type by [@&#8203;SamAsEnd](https://github.com/SamAsEnd) in laravel/framework#50108
-   \[10.x] Actually fix fromBase64 return type by [@&#8203;GrahamCampbell](https://github.com/GrahamCampbell) in laravel/framework#50113
-   \[10.x] Fix warning and deprecation for Str::api by [@&#8203;driesvints](https://github.com/driesvints) in laravel/framework#50114
-   \[10.x] Mark model instanse as not exists on deleting MorphPivot relation. by [@&#8203;dkulyk](https://github.com/dkulyk) in laravel/framework#50135
-   \[10.x] Adds Tappable and Conditionable to Relation class by [@&#8203;DarkGhostHunter](https://github.com/DarkGhostHunter) in laravel/framework#50124
-   \[10.x] Added getQualifiedMorphTypeName to MorphToMany by [@&#8203;dkulyk](https://github.com/dkulyk) in laravel/framework#50153

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMTQuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIxNC4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCJ9-->

Reviewed-on: https://code.itinerare.net/itinerare/Alcyone/pulls/5
Co-authored-by: Amadeus[bot] <amadeus@itinerare.net>
Co-committed-by: Amadeus[bot] <amadeus@itinerare.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants