Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enable recording of identical requests#161

Closed
esbenp wants to merge 5 commits intophp-vcr:masterfrom
esbenp:fix-132
Closed

Enable recording of identical requests#161
esbenp wants to merge 5 commits intophp-vcr:masterfrom
esbenp:fix-132

Conversation

@esbenp
Copy link

@esbenp esbenp commented Jul 13, 2016

This PR will introduce the tracking of identical requests, thus enabling PHP-VCR to record different responses of the same request within the same cassette. This closes issue #132

Right now PHP-VCR only tracks one occurrence of a given request
per cassette. An example of why this is troublesome is given below.

  • (1) Request a resource from an external endpoint (GET /resource)
  • (2) Request an update to that resource (PUT /resource)
  • (3) Re-request the resource to confirm it was persisted remotely (GET /resource)

Requests (1) and (3) are identical, however the responses are expected
to be different. PHP-VCR will only record (1) and use the saved version
on (3).

This commit keeps track of the order of occurrence of requests, meaning
(1) is the 1st occurrence of (GET /resource) and (3) is the 2nd. When
the test is re-run, when running (3) PHP-VCR will now look for a
saved request which is the 2nd (GET /resource).

Ref #132

esbenp added 2 commits July 8, 2016 10:02
Right now PHP-VCR only tracks one occurrence of a given request
per cassette. An example of why this is troublesome is given below.

* (1) Request a resource from an external endpoint (GET /resource)
* (2) Request an update to that resource (PUT /resource)
* (3) Re-request the resource to confirm it was persisted remotely (GET /resource)

Requests (1) and (3) are identical, however the responses are expected
to be different. PHP-VCR will only record (1) and use the saved version
on (3).

This commit keeps track of the order of occurrence of requests, meaning
(1) is the 1st occurrence of (GET /resource) and (3) is the 2nd. When
the test is re-run, when running (3) PHP-VCR will now look for a
saved request which is the 2nd (GET /resource).

See php-vcr#132
tests were failing because between recording responses and testing
playback the index table was not reset. Since introducing the index
table we keep recording responses. Next time the test case is run,
the index will have reset and then the cassette will look for recordings
instead of recording new entries. This commit will simulate the
"end" of test cases and the "closing" of a cassette.
@castarco
Copy link

castarco commented Sep 9, 2016

For me this is a +1, It would be great if someone else reviews this merge request to ensure that we won't break anything (I'm a maintainer but I'm relatively new to this codebase).

@esbenp
Copy link
Author

esbenp commented Sep 18, 2016

Okay @castarco, I agree. However, I am neither completely fluent in the codebase and it seems that @adri has gone AWOL

@renatomefi renatomefi added this to the 1.5 milestone Oct 17, 2017
@fmasa
Copy link

fmasa commented Jul 13, 2018

What is current status of this PR, could I help somehow?

bwood added a commit to bwood/php-vcr that referenced this pull request Feb 13, 2019
…le Cassette to playback and record request/responses at a given index. Do not require Cassette to manage index state.
@higidi higidi added the Feature New feature or request label Dec 19, 2022
@higidi higidi self-assigned this Dec 19, 2022
higidi pushed a commit that referenced this pull request Dec 19, 2022
…ette to playback and record request/responses at a given index. Do not require Cassette to manage index state.
@higidi higidi mentioned this pull request Dec 19, 2022
@higidi
Copy link
Contributor

higidi commented Dec 19, 2022

Closed, see #270

@higidi higidi closed this Dec 19, 2022
higidi pushed a commit that referenced this pull request Dec 19, 2022
…ette to playback and record request/responses at a given index. Do not require Cassette to manage index state.

(cherry picked from commit 7590bbc)
specialtactics added a commit to CoverGenius/php-vcr that referenced this pull request Jan 6, 2025
* Support for Symfony 6

* TASK: Cleanup GitHub workflows

* FIX: Allow phpstan/extension-install composer plugin

* Cleanup .gitattributes with export-ignore

* TASK: Use composer-install action for workflows

* TASK: Apply codestyle fixes

* FIX: Fix scrutinizer workflow action uploading

* TASK: Added php-xdebug ext to workspace docker container

* FEATURE: Allow lower versions of symfony/event-dispatcher

* TASK: Ignore phpstan error

* FEATURE: Upgrade phpstan

* TASK: Refactor GitHub workflow

* FEATURE: Workspace docker image for php 8.1 added

* FEATURE: Test against php 8.1 with GitHub workflows

* FIX: Fixed several issues with occurred with php >= 8.1

* TASK: Disable failing fast while running phpunit tests

* FIX: Fix phpstan issues and invalid BlackholeTest

* FIX: Raise minimum version of phpunit

* FEATURE: Restructure GitHub Workflow

* FEATURE: Added editorconfig checker

* FIX: Fix editorconfig violations

* TASK: Added .editorconfig to export-ignore via .gitattributes

* FEATURE: Install editorconfig-checker wrapper for php

* TASK: Fix export-ignore for phpstan in .gitattributes

* TASK: Do not exclude defaults for editorconfig checker

* Rework php-vcr#161. Manage request index state in Videorecorder. Enable Cassette to playback and record request/responses at a given index. Do not require Cassette to manage index state.

* $index should not be a required parameter on record(). Avoid unecessary API changes.

* Ensure that the cassette indexes are reset when the cassette is ejected or inserted.

* Use equals not identical operator when comparing the request index to the recording index.

* Spport legacy cassettes. Create a recording index of 0 if no index key exists in the cassette.

* Add comment punctuation.

* Add testPlaybackLegacyCassette() to ensure that legacy cassettes with no index keys playback.

* Add tests ensuring that both legacy (non-indexed) cassettes and indexed cassettes playback multiple identical requests correctly.

* Modify testInsertCassetteEjectExisting() to ensure that resetIndex() is called as part of eject() and insertCassette().

* Remove redundant testPlaybackLegacyCassette().

* Fix indents.

* FEATURE: Added testcase for mixed cassettes

(with and without legacy entries)

* FIX: Fixed remaining phpstan errors

* FIX: Indentions

* FIX: Videorecorder always raised index for identical requests, Cassette have to handle legacy entries

Because the Videorecorder increments the index for each identical requests it also passes it to the cassette,
so the cassette have to handle legacy stored entries. So if no index is present while loading recorded requests
we have to set the index to searched one (instead of zero) to always match (disabled the feature), when all
other matchers match.

* Revert "FEATURE: Added testcase for mixed cassettes"

This reverts commit ce1471b.

* FIX: Fixed remaining phpstan errors

* FIX: README.md badge

* Add CURLINFO_APPCONNECT_TIME to CurlHelper

Fixes php-vcr#309

* Fix CurlHookTest.php

* FIX: Read the whole stream and perform code transformations

First read the whole stream and afterwards perform code transformations.
This will ensure to also replace code, which is divided into chunks while
reading a file.

Fixes php-vcr#268

* FIX: Codestyle

* FIX: Codestyle

* TASK: Update README.md

* TASK: Drop support for php 8.2

Currently, the php-vcr library does not work well with php 8.2
so we drop the support for now until it is fixed.

* TASK: Apply codestyle

* FEATURE: Fix/review phpstan errors

* FEATURE: Custom workspace docker file for php 8.2 added

* FEATURE: Added php 8.2 to GitHub workflow

* TASK: Add support for php 8.2

* TASK: Added support for php greater than 8.2.9

* FIX: Initialized typed property

* Add SOAP extension requirement for running tests

* (tech) add PHP 8.3 support

* FIX: Fixed nullable types

* TASK: Fix phpstan error (by generating new baseline)

* FEATURE: Added php 8.3 workspace docker image

* Add support Symfony 7

* Remove trailing semicolon in Content-Type header

* Adjust SOAP v1.1 header expectation in test

* Fix PHPUnit deprecations

* Fix set_stream_options arguments

* TASK: Apply code style fixes

* FIX: Added new baseline

* FIX: Removed phpstan ignore (there is no error to ignore)

* FIX: Gnerated phpstan baseline

* add PHP 8.4 support

* add support

* fix cs

* skip soap tests due to problem with them

* phpstan, cs

* remove scruitinizer reports

---------

Co-authored-by: nicodemuz <[email protected]>
Co-authored-by: Daniel Hürtgen <[email protected]>
Co-authored-by: Daniel Hürtgen <[email protected]>
Co-authored-by: Brian Wood <[email protected]>
Co-authored-by: oranges13 <[email protected]>
Co-authored-by: Peter <[email protected]>
Co-authored-by: ecourtial <[email protected]>
Co-authored-by: yethee <[email protected]>
Co-authored-by: alexzabolotny <[email protected]>
Co-authored-by: Lars Strojny <[email protected]>
Co-authored-by: Masaki Kawaguchi <[email protected]>
bomas13 added a commit to easybell-gmbh/php-vcr that referenced this pull request Oct 13, 2025
* Adding PHPStan to CI build

* Fixing PHPStan level 0 issues

* Adding failing integration test for wrong URL with SoapClient

* Adding failing integration test with ConnectException.

cURL error is not forwarded correctly.

* Forwarding cURL errors from HttpClient to SoapClient and CurlHook

* Stepping up minimum PHP version to 7.2

* Upgrading to PHPUnit 7

* Removing non existent constant.

* Fixing PHP-Doc annotation syntax (and reaching PHPStan level 2)

* Fixing StreamProcessor returns (true on success, false on failure)

* Adding nullable type hints in PHPDoc for explicitly nullable properties / return types.
PHPStan level 3 reached.

* Adding nullable type hints on nullable properties

* More robust headers implementation.
Headers now MUST be strings (no null value allowed in header).
Added HOST check in Request.

* Upgrading to PHPStan level 4.

* Adding casts for parameters (int to bool...)
Reaching PHPStan level 5.

* Adding additional check to be sure the cassette was successfully opened.

* Asserting that curl_init did succeed

* Reaching PHPStan level 6

Tweaked some PHPDoc statements.
Added some ignore in PHPStan where assertions are already ensuring safety.

* Adding beberlei assertion PHPStan plugin (needed to improve the impact of Assertions on types)

* Removing invalid XML from PHPUnit file

* Allowing beberlei/assert to go up to v3.
Increasing minimum version to have support for Assertion::isResource.

* Fixing PHPUnit test

It was not migrated to PHPUnit 7 yet because it was merged after the migration.

* Reaching PHPStan level 7 \o/

* Adding PHP 7.1+ types

* Fixed AbstractCodeTransform registration.

AbstractCodeTransform was actually misbehaving if several instances of the same XxxCodeTransform were to be created.
Indeed, a wrapper can be registered, but not unregistered. If 2 instances of CurlCodeTransform were to be created, the registration of the wrapper would be attempted twice. The second one would fail and try again but the wrapper is already registered. This PR registers only if the stream is indeed not already registered.

* Added SoapOperation request matcher + unit tests

* Fixing type hinting on createStorage

Was typehinted on the AbstractStorage class instead of the Storage interface.

* Using "finally" statement now that PHP-VCR has a PHP 7+ requirement

* Update tests/VCR/RequestMatcherTest.php

Co-Authored-By: ValdoTR <[email protected]>

* Adding PHP7.4snapshot to Travis (with allowed failure)

* Applying CS fix with newest version of PHP-CS-Fixer

* Fixing PHPStan new issues following dependencies upgrade

* Fixing event listener breaking change in Symfony 4.3

* Storage: Yaml: prevent PHP 7.4 deprecation notice

* Cassette: drop unused use statement

* Request: drop unused use statement

* Response: drop unused use statement

* Storage: AbstractStorage: drop unused use statement

* Storage: Json: drop unused use statement

* LibraryHooks: StreamWrapperHook: drop unused use statements

* U-Tests: LibraryHooks: CurlHookTest: pass second param to curl_multi_exec

* U-Tests: LibraryHooks: CurlHookTest: make sure we pass Closure

* U-Tests: LibraryHooks: SoapHookTest: make sure we pass Closure

* Fixing Beberlei/assert signature change

beberlei/assert changed the signature of Assertion::isCallable (in a patch release!) and we extend this method.
This commit updates "assert" to the latest version and updates our signature accordingly.

* Updating composer.lock

* Update src/VCR/Util/Assertion.php

Co-Authored-By: David Négrier <[email protected]>

* Fixing issue with Guzzle 3 and symfony event dispatcher

* Fixed php-cs in CI

* Fix typo in README and remove warning

Rationale: It's pretty battle-tested now, as we tidy this up we want to encourage new users.

* Fixed vfsstream reference

* Adding PHPStan to CI build

* Fixing PHPStan level 0 issues

* Updated phpstan to ^0.12

* Fix the parse error on PHP 7.4

Do not return the stat since we don't know the resulting the size that the file will have after having all transformations applied. When including files, PHP 7.4 and newer are sensitive to file size reported by stat.

* Test php 7.3 and 7.4

* Use 7.4 snapshot for now

* Don't force precise

* Don't force precise

* Use 7.4, not 7.4snapshot

* Fixed array offset error

* Temporarily ignore deprecation messages for PHP 7.4

* Fixed PHPStan errors

* Updated symfony/event-dispatcher to Symfony 5

* Fixed broken references

* Removed header folding

* Refactor header parsing logic

* Added null check to request header accessor

* Header formatting

* Header formatting

* Refactor header parsing logic

* Symfony LTS backwards compatibility

* Dispatcher style fix

* Fixed broken references

* Style fix

* Merge branch 'master' of github.com:php-vcr/php-vcr into 1.5

* Bump package versions

* Fixed the uncareful merge of PR311

* Configure php-cs-fixer as dev dependency

* Updated php-cs-fixer config

* Changes by php-cs-fixer

* Implemented stream_stat

* Allow using symfony/yaml ^5.0

* Add Failing test

* Add word boundary to regex

* Updated vfsstream

* Updated readme and composer.json

* Removed Guzzle 4 test as Guzzle 4 is not compatible with PHP >= 7.1

* fix: phpstan ignore error failure on PHP >= 7.2

* fix: ensure stream_wrapper_restore does not throw

* chore: Ignore composer.lock

* call_user_func doesn't work in this context with private or protected functions. This should solve an issue encountered when using php-vcr with the PayPal SDK (paypal/PayPal-PHP-SDK#1057).

* Support for ssl requests in some edge cases like paypal php sdk

* CS rule

* Update phpstan config

* Adding docker-compose environment

* Ran composer fix

* Upgraded PHPUnit from 7 to 8

* Updated php-cs-fixer config

* Added .editorconfig

* Level 0

* Level 1

* Level 2

* Level 3

* Level 5

* Level 6

* Level 7

* add support for curl_multi_getcontent

s

* Dropped support for PHP 7.2

* Converted travis to github actions

* Adding support for PHP8, dropping support for PHP7

* Workaround for broken ocular

* Major update and cleanup

* Reorganised tests

* Support for Symfony 6

* TASK: Cleanup GitHub workflows

* FIX: Allow phpstan/extension-install composer plugin

* Cleanup .gitattributes with export-ignore

* TASK: Use composer-install action for workflows

* TASK: Apply codestyle fixes

* FIX: Fix scrutinizer workflow action uploading

* TASK: Added php-xdebug ext to workspace docker container

* FEATURE: Allow lower versions of symfony/event-dispatcher

* TASK: Ignore phpstan error

* FEATURE: Upgrade phpstan

* TASK: Refactor GitHub workflow

* FEATURE: Workspace docker image for php 8.1 added

* FEATURE: Test against php 8.1 with GitHub workflows

* FIX: Fixed several issues with occurred with php >= 8.1

* TASK: Disable failing fast while running phpunit tests

* FIX: Fix phpstan issues and invalid BlackholeTest

* FIX: Raise minimum version of phpunit

* FEATURE: Restructure GitHub Workflow

* FEATURE: Added editorconfig checker

* FIX: Fix editorconfig violations

* TASK: Added .editorconfig to export-ignore via .gitattributes

* FEATURE: Install editorconfig-checker wrapper for php

* TASK: Fix export-ignore for phpstan in .gitattributes

* TASK: Do not exclude defaults for editorconfig checker

* Rework php-vcr#161. Manage request index state in Videorecorder. Enable Cassette to playback and record request/responses at a given index. Do not require Cassette to manage index state.

* $index should not be a required parameter on record(). Avoid unecessary API changes.

* Ensure that the cassette indexes are reset when the cassette is ejected or inserted.

* Use equals not identical operator when comparing the request index to the recording index.

* Spport legacy cassettes. Create a recording index of 0 if no index key exists in the cassette.

* Add comment punctuation.

* Add testPlaybackLegacyCassette() to ensure that legacy cassettes with no index keys playback.

* Add tests ensuring that both legacy (non-indexed) cassettes and indexed cassettes playback multiple identical requests correctly.

* Modify testInsertCassetteEjectExisting() to ensure that resetIndex() is called as part of eject() and insertCassette().

* Remove redundant testPlaybackLegacyCassette().

* Fix indents.

* FEATURE: Added testcase for mixed cassettes

(with and without legacy entries)

* FIX: Fixed remaining phpstan errors

* FIX: Indentions

* FIX: Videorecorder always raised index for identical requests, Cassette have to handle legacy entries

Because the Videorecorder increments the index for each identical requests it also passes it to the cassette,
so the cassette have to handle legacy stored entries. So if no index is present while loading recorded requests
we have to set the index to searched one (instead of zero) to always match (disabled the feature), when all
other matchers match.

* Revert "FEATURE: Added testcase for mixed cassettes"

This reverts commit ce1471b.

* FIX: Fixed remaining phpstan errors

* FIX: README.md badge

* Add CURLINFO_APPCONNECT_TIME to CurlHelper

Fixes php-vcr#309

* Fix CurlHookTest.php

* FIX: Read the whole stream and perform code transformations

First read the whole stream and afterwards perform code transformations.
This will ensure to also replace code, which is divided into chunks while
reading a file.

Fixes php-vcr#268

* FIX: Codestyle

* FIX: Codestyle

* TASK: Update README.md

* TASK: Drop support for php 8.2

Currently, the php-vcr library does not work well with php 8.2
so we drop the support for now until it is fixed.

* TASK: Apply codestyle

* FEATURE: Fix/review phpstan errors

* FEATURE: Custom workspace docker file for php 8.2 added

* FEATURE: Added php 8.2 to GitHub workflow

* TASK: Add support for php 8.2

* TASK: Added support for php greater than 8.2.9

* FIX: Initialized typed property

* Add SOAP extension requirement for running tests

* (tech) add PHP 8.3 support

* FIX: Fixed nullable types

* TASK: Fix phpstan error (by generating new baseline)

* FEATURE: Added php 8.3 workspace docker image

* Add support Symfony 7

* Remove trailing semicolon in Content-Type header

* Adjust SOAP v1.1 header expectation in test

* Fix PHPUnit deprecations

* Fix set_stream_options arguments

* TASK: Apply code style fixes

* FIX: Added new baseline

* FIX: Removed phpstan ignore (there is no error to ignore)

* FIX: Gnerated phpstan baseline

* add PHP 8.4 support

* add support

---------

Co-authored-by: David Négrier <[email protected]>
Co-authored-by: Valdo Romao <[email protected]>
Co-authored-by: ValdoTR <[email protected]>
Co-authored-by: Boris Momčilović <[email protected]>
Co-authored-by: AYB <[email protected]>
Co-authored-by: AymanBenmada <[email protected]>
Co-authored-by: Jeroen van Oort <[email protected]>
Co-authored-by: James Hall <[email protected]>
Co-authored-by: Sergei Morozov <[email protected]>
Co-authored-by: Jan Vernieuwe <[email protected]>
Co-authored-by: Paul Adams <[email protected]>
Co-authored-by: pvgnd <[email protected]>
Co-authored-by: Alasdair North <[email protected]>
Co-authored-by: Max <[email protected]>
Co-authored-by: Thomas Gnandt <[email protected]>
Co-authored-by: nicodemuz <[email protected]>
Co-authored-by: Daniel Hürtgen <[email protected]>
Co-authored-by: Daniel Hürtgen <[email protected]>
Co-authored-by: Brian Wood <[email protected]>
Co-authored-by: oranges13 <[email protected]>
Co-authored-by: Peter <[email protected]>
Co-authored-by: ecourtial <[email protected]>
Co-authored-by: yethee <[email protected]>
Co-authored-by: alexzabolotny <[email protected]>
Co-authored-by: Lars Strojny <[email protected]>
Co-authored-by: Masaki Kawaguchi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants