sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.68k stars 2.2k forks source link

Broken counting mocked objects when use index $this->at("number") #4022

Closed kretowicz14 closed 4 years ago

kretowicz14 commented 4 years ago
alterphp/easyadmin-extension-bundle v2.1.7     This bundle provides some extensions to javiereguiluz/easyadmin-bundle
behat/transliterator                v1.2.0     String transliterator
doctrine/annotations                v1.8.0     Docblock Annotations Parser
doctrine/cache                      1.10.0     PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections                1.6.4      PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                     v2.11.0    PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, persistence interfaces, proxies, event system and much more.
doctrine/data-fixtures              1.4.0      Data Fixtures for all Doctrine Object Managers
doctrine/dbal                       v2.10.0    Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/doctrine-bundle            1.12.2     Symfony DoctrineBundle
doctrine/doctrine-cache-bundle      1.4.0      Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle   3.3.0      Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle 2.1.2      Symfony DoctrineMigrationsBundle
doctrine/event-manager              1.1.0      The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                  1.3.1      Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator               1.3.0      A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                      1.2.0      PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                 2.2.0      PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.
doctrine/orm                        v2.7.0     Object-Relational-Mapper for PHP
doctrine/persistence                1.3.3      The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/reflection                 v1.0.0     Doctrine Reflection component
easycorp/easyadmin-bundle           v2.1.4     Admin generator for Symfony applications
easycorp/easy-log-handler           v1.0.9     A handler for Monolog that optimizes log messages to be processed by humans instead of software. Improve your productivity with logs that are easy to understand.
egulias/email-validator             2.1.11     A library for validating emails against several RFCs
friendsofsymfony/user-bundle        v2.1.2     Symfony FOSUserBundle
gedmo/doctrine-extensions           v2.4.38    Doctrine2 behavioral extensions
guzzlehttp/guzzle                   6.5.0      Guzzle is a PHP HTTP client library
guzzlehttp/promises                 v1.3.1     Guzzle promises library
guzzlehttp/psr7                     1.6.1      PSR-7 message implementation that also provides common utility methods
hoa/compiler                        3.17.08.08 The Hoa\Compiler library.
hoa/consistency                     1.17.05.02 The Hoa\Consistency library.
hoa/event                           1.17.01.13 The Hoa\Event library.
hoa/exception                       1.17.01.16 The Hoa\Exception library.
hoa/file                            1.17.07.11 The Hoa\File library.
hoa/iterator                        2.17.01.10 The Hoa\Iterator library.
hoa/math                            1.17.05.16 The Hoa\Math library.
hoa/protocol                        1.17.01.14 The Hoa\Protocol library.
hoa/regex                           1.17.01.13 The Hoa\Regex library.
hoa/stream                          1.17.02.21 The Hoa\Stream library.
hoa/ustring                         4.17.01.16 The Hoa\Ustring library.
hoa/visitor                         2.17.01.16 The Hoa\Visitor library.
hoa/zformat                         1.17.01.10 The Hoa\Zformat library.
jdorn/sql-formatter                 v1.2.17    a PHP SQL highlighting library
jmose/command-scheduler-bundle      v2.1.0     This Symfony bundle will allow you to schedule all your commands just like UNIX crontab
jms/metadata                        2.1.0      Class/method/property metadata management in PHP
jms/serializer                      3.4.0      Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML.
jms/serializer-bundle               3.5.0      Allows you to easily serialize, and deserialize data of any complexity
knplabs/knp-components              v2.3.0     Knplabs component library
knplabs/knp-paginator-bundle        v4.1.1     Paginator bundle for Symfony to automate pagination and simplify sorting and other features
knplabs/knp-snappy-bundle           v1.6.0     Easily create PDF and images in Symfony2 by converting Twig/HTML templates.
knplabs/knp-snappy                  v1.2.0     PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.
league/uri-components               1.8.2      URI components manipulation library
league/uri-hostname-parser          1.1.1      ICANN base hostname parsing implemented in PHP.
league/uri-interfaces               1.1.1      Common interface for URI representation
league/uri-manipulations            1.5.0      URI manipulation library
league/uri-parser                   1.4.1      userland URI parser RFC 3986 compliant
league/uri-schemes                  1.2.1      URI manipulation library
monolog/monolog                     1.25.2     Sends your logs to files, sockets, inboxes, databases and various web services
mtdowling/cron-expression           v1.2.1     CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
myclabs/deep-copy                   1.9.3      Create deep copies (clones) of your objects
ocramius/package-versions           1.5.1      Composer plugin that provides efficient querying for installed package versions (no runtime IO)
ocramius/proxy-manager              2.2.3      A library providing utilities to generate, instantiate and generally operate with Object Proxies
pagerfanta/pagerfanta               v2.1.3     Pagination for PHP
phar-io/manifest                    1.0.3      Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                     2.0.1      Library for handling version information and constraints
phpdocumentor/reflection-common     2.0.0      Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock   4.3.2      With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver         1.0.1      A PSR-5 based resolver of Class names, Types and Structural Element Names
php-http/guzzle6-adapter            v2.0.1     Guzzle 6 HTTP Adapter
php-http/httplug                    v2.0.0     HTTPlug, the HTTP client abstraction for PHP
php-http/promise                    v1.0.0     Promise used for asynchronous HTTP requests
phpspec/prophecy                    1.9.0      Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage           7.0.10     Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator           2.0.2      FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template           1.2.1      Simple template engine.
phpunit/php-timer                   2.1.2      Utility class for timing
phpunit/php-token-stream            3.1.1      Wrapper around PHP's tokenizer extension.
phpunit/phpunit                     8.5.2      The PHP Unit Testing framework.
psr/cache                           1.0.1      Common interface for caching libraries
psr/container                       1.0.0      Common Container Interface (PHP FIG PSR-11)
psr/http-client                     1.0.0      Common interface for HTTP clients
psr/http-message                    1.0.1      Common interface for HTTP messages
psr/log                             1.1.2      Common interface for logging libraries
psr/simple-cache                    1.0.1      Common interfaces for simple caching
ralouphie/getallheaders             3.0.3      A polyfill for getallheaders.
sebastian/code-unit-reverse-lookup  1.0.1      Looks up which function or method a line of code belongs to
sebastian/comparator                3.0.2      Provides the functionality to compare PHP values for equality
sebastian/diff                      3.0.2      Diff implementation
sebastian/environment               4.2.3      Provides functionality to handle HHVM/PHP environments
sebastian/exporter                  3.1.2      Provides the functionality to export PHP variables for visualization
sebastian/global-state              3.0.0      Snapshotting of global state
sebastian/object-enumerator         3.0.3      Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector          1.1.1      Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context         3.0.0      Provides functionality to recursively process PHP variables
sebastian/resource-operations       2.0.1      Provides a list of PHP built-in functions that operate on resources
sebastian/type                      1.1.3      Collection of value objects that represent the types of the PHP type system
sebastian/version                   2.0.1      Library that helps with managing the version number of Git-hosted PHP projects
sensio/framework-extra-bundle       v5.5.2     This bundle provides a way to configure your controllers with annotations
spatie/calendar-links               1.2.4      Generate add to calendar links for Google, iCal and other calendar systems
squizlabs/php_codesniffer           3.5.3      PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
stof/doctrine-extensions-bundle     v1.3.0     Integration of the gedmo/doctrine-extensions with Symfony2
swiftmailer/swiftmailer             v6.2.3     Swiftmailer, free feature-rich PHP mailer
symfony/asset                       v4.4.1     Symfony Asset Component
symfony/browser-kit                 v4.4.1     Symfony BrowserKit Component
symfony/cache-contracts             v1.1.7     Generic abstractions related to caching
symfony/cache                       v4.4.1     Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config                      v4.4.1     Symfony Config Component
symfony/console                     v4.4.1     Symfony Console Component
symfony/debug-bundle                v4.4.1     Symfony DebugBundle
symfony/debug-pack                  v1.0.7     A debug pack for Symfony projects
symfony/debug                       v4.4.1     Symfony Debug Component
symfony/dependency-injection        v4.4.1     Symfony DependencyInjection Component
symfony/doctrine-bridge             v4.4.1     Symfony Doctrine Bridge
symfony/dom-crawler                 v4.4.1     Symfony DomCrawler Component
symfony/dotenv                      v4.4.1     Registers environment variables from a .env file
symfony/error-handler               v4.4.1     Symfony ErrorHandler Component
symfony/event-dispatcher-contracts  v1.1.7     Generic abstractions related to dispatching event
symfony/event-dispatcher            v4.4.1     Symfony EventDispatcher Component
symfony/expression-language         v4.4.1     Symfony ExpressionLanguage Component
symfony/filesystem                  v4.4.1     Symfony Filesystem Component
symfony/finder                      v4.4.1     Symfony Finder Component
symfony/flex                        v1.6.0     Composer plugin for Symfony
symfony/form                        v4.4.1     Symfony Form Component
symfony/framework-bundle            v4.4.1     Symfony FrameworkBundle
symfony/http-foundation             v4.4.1     Symfony HttpFoundation Component
symfony/http-kernel                 v4.4.1     Symfony HttpKernel Component
symfony/inflector                   v4.4.1     Symfony Inflector Component
symfony/intl                        v4.4.1     A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/mime                        v4.4.1     A library to manipulate MIME messages
symfony/monolog-bridge              v4.4.1     Symfony Monolog Bridge
symfony/monolog-bundle              v3.5.0     Symfony MonologBundle
symfony/options-resolver            v4.4.1     Symfony OptionsResolver Component
symfony/orm-pack                    v1.0.7     A pack for the Doctrine ORM
symfony/polyfill-intl-icu           v1.13.1    Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn           v1.13.1    Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-mbstring           v1.13.1    Symfony polyfill for the Mbstring extension
symfony/polyfill-php72              v1.13.1    Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73              v1.13.1    Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/process                     v4.4.1     Symfony Process Component
symfony/profiler-pack               v1.0.4     A pack for the Symfony web profiler
symfony/property-access             v4.4.1     Symfony PropertyAccess Component
symfony/property-info               v4.4.1     Symfony Property Info Component
symfony/routing                     v4.4.1     Symfony Routing Component
symfony/security-bundle             v4.4.1     Symfony SecurityBundle
symfony/security-core               v4.4.1     Symfony Security Component - Core Library
symfony/security-csrf               v4.4.1     Symfony Security Component - CSRF Library
symfony/security-guard              v4.4.1     Symfony Security Component - Guard
symfony/security-http               v4.4.1     Symfony Security Component - HTTP Integration
symfony/service-contracts           v2.0.1     Generic abstractions related to writing services
symfony/stopwatch                   v4.4.1     Symfony Stopwatch Component
symfony/swiftmailer-bundle          v3.4.0     Symfony SwiftmailerBundle
symfony/templating                  v4.4.1     Symfony Templating Component
symfony/translation-contracts       v2.0.1     Generic abstractions related to translation
symfony/translation                 v4.4.1     Symfony Translation Component
symfony/twig-bridge                 v4.4.1     Symfony Twig Bridge
symfony/twig-bundle                 v4.4.1     Symfony TwigBundle
symfony/validator                   v4.4.1     Symfony Validator Component
symfony/var-dumper                  v4.4.1     Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter                v4.4.1     A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle         v4.4.1     Symfony WebProfilerBundle
symfony/yaml                        v4.4.1     Symfony Yaml Component
theseer/tokenizer                   1.1.3      A small library for converting tokenized PHP source code into XML and potentially other formats
twig/extensions                     v1.5.4     Common additional features for Twig that do not directly belong in core
twig/twig                           v2.12.2    Twig, the flexible, fast, and secure template language for PHP
twilio/sdk                          5.41.0     A PHP wrapper for Twilio's API
webmozart/assert                    1.6.0      Assertions to validate method input/output with nice error messages.
zendframework/zend-code             3.4.1      Extensions to the PHP Reflection API, static code scanning, and code generation
zendframework/zend-eventmanager     3.2.1      Trigger and listen to events within a PHP application
Q A
PHPUnit version 8.5.2
PHP version 7.2
Installation Method Composer

Summary

When make on mock objects (this is working example):

        $this->customerRepository
            ->expects($this->at(1))
            ->method('save')
            ->with($newTemporaryCustomerFirst)
        ;

        $this->customerRepository
            ->expects($this->at(3))
            ->method('save')
            ->with($newTemporaryCustomerSecond)
        ;

This is error exaple:

        $this->customerRepository
            ->expects($this->at(0))
            ->method('save')
            ->with($newTemporaryCustomerFirst)
        ;
        $this->customerRepository
            ->expects($this->at(1))
            ->method('save')
            ->with($newTemporaryCustomerSecond)
        ;

In this case he expects $newTemporaryCustomerSecond on index 0

Debuger is showing we iterate on object1, object2 (and make save's), but phpunit mock object is counting save method on 1 & 3, not 0 & 1.

In other case i must start counting from 0, and next use at 2, at 4 etc.

Current behavior

Counting index on mock object.

How to reproduce

I think its problem when you got mocked object what iniject other services, and other services made save (he shouldn't count other methods inside iniject services).

Expected behavior

Fix index on mock objects.

sebastianbergmann commented 4 years ago

It is known that at() counts "weird". Changing how it counts would break backward compatibility in an even weirder way.

I consider the use of at() a bad practice. Maybe it is time to deprecate it and completely remove it later?

kretowicz14 commented 4 years ago

You cant well check assertions of same methods when other method expect return collection of elements. So only functional tests can test that properly :/