assertStringNotContainsString doesn't behave as expected and the result is confusing since it changes the actual compared strings in the case where certain keywords exist.
Current behavior
If you use assertStringNotContainsString in a test case to try to assert that a needle is not contained within a haystack and that needle (and the haystack) contains the word 'contains' (and possibly other words in the negate method of the LogicalNot class) then the assertion fails AND the failure message is confusing.
In the test scenario shown below, the result is:
Expected the message to exist
Failed asserting that 'XXXXX We sent you an email. It does not contain a link XXXXXX' does not contain "We sent you an email. It does not contain a link".
The failure message contains the original string with contains replaced by does not contain which makes debugging what's wrong rather confusing.
How to reproduce
public function testStupidComparisonBug(): void
{
$stringToTest = 'XXXXX We sent you an email. It contains a link XXXXXX';
$stringToCheck = 'We sent you an email. It contains a link';
$this->assertStringNotContainsString(
$stringToCheck,
$stringToTest,
"Expected the message to exist"
);
}
Run this test and see the current behaviour above.
Expected behavior
Test passes (because the assertion should return true).
In a failure case, the error response should contain the ACTUAL content - not content which has had specific words modified.
Composer output:
composer info | sort
aequasi/memcached-bundle dev-master 51d817b Memcached Bundle
amphp/amp v2.6.0 A non-blocking concurrency framework for PHP applications.
amphp/byte-stream v1.8.1 A stream abstraction to make working with non-blocking I/O simple.
aws/aws-crt-php v1.0.2 AWS Common Runtime for PHP
aws/aws-sdk-php 3.194.2 AWS SDK for PHP - Use Amazon Web Services in your PHP project
babdev/pagerfanta-bundle v2.11.0 Bundle integrating Pagerfanta with Symfony
bacon/bacon-qr-code 2.0.4 BaconQrCode is a QR code generator for PHP.
behat/transliterator v1.3.0 String transliterator
blackfire/php-sdk v1.26.0 Blackfire.io PHP SDK
brick/math 0.9.3 Arbitrary-precision arithmetic library
calcinai/xero-php v1.9.1 A client implementation of the Xero API, with a cleaner OAuth interface and ORM-like abstraction.
clue/stream-filter v1.5.0 A simple and modern approach to stream filtering in PHP
codeconsortium/ccdn-user-security-bundle dev-master 4a948be CCDN User Security Bundle
composer/ca-bundle 1.2.10 Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.
composer/package-versions-deprecated 1.11.99.4 Composer plugin that provides efficient querying for installed package versions (no runtime IO)
composer/semver 3.2.5 Semver library that offers utilities, version constraint parsing and validation.
composer/xdebug-handler 2.0.2 Restarts a process without Xdebug.
dasprid/enum 1.0.3 PHP 7.1 enum implementation
dnoegel/php-xdg-base-dir v0.1.1 implementation of xdg base directory specification for php
doctrine/annotations 1.13.2 Docblock Annotations Parser
doctrine/cache 1.12.1 PHP Doctrine Cache library is a popular cache implementation that supports many different drivers ...
doctrine/collections 1.6.8 PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common 2.13.3 PHP Doctrine Common project is a library that provides additional functionality that other Doctrin...
doctrine/data-fixtures 1.5.0 Data Fixtures for all Doctrine Object Managers
doctrine/dbal 2.13.2 Powerful PHP database abstraction layer (DBAL) with many features for database schema introspectio...
doctrine/deprecations v0.5.3 A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable ...
doctrine/doctrine-bundle 1.12.13 Symfony DoctrineBundle
doctrine/doctrine-cache-bundle 1.4.0 Symfony Bundle for Doctrine Cache
doctrine/doctrine-fixtures-bundle 3.4.0 Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle 3.0.3 Symfony DoctrineMigrationsBundle
doctrine/event-manager 1.1.1 The Doctrine Event Manager is a simple PHP event system that was built to be used with the various...
doctrine/inflector 1.4.4 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upp...
doctrine/instantiator 1.4.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer 1.2.1 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations 3.0.1 PHP Doctrine Migrations project offer additional functionality on top of the database abstraction ...
doctrine/orm 2.7.5 Object-Relational-Mapper for PHP
doctrine/persistence 1.3.8 The Doctrine Persistence project is a set of shared interfaces and functionality that the differen...
doctrine/reflection 1.2.2 The Doctrine Reflection project is a simple library used by the various Doctrine projects which ad...
egulias/email-validator 3.1.1 A library for validating emails against several RFCs
eightpoints/guzzle-bundle v7.6.2 Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony 2/3/4. Comes with easy and powerful configu...
endroid/installer 1.3.3 Composer plugin for installing configuration files
endroid/qr-code 4.3.0 Endroid QR Code
endroid/qr-code-bundle 4.0.5 Endroid QR Code Bundle
enshrined/svg-sanitize 0.14.1 An SVG sanitizer for PHP
ergebnis/clock 2.2.0 Provides a simple abstraction of a clock.
excelwebzone/recaptcha-bundle v1.5.29 This bundle provides easy reCAPTCHA form field integration
exercise/htmlpurifier-bundle v3.1.0 HTMLPurifier integration for your Symfony project
exsyst/swagger v0.4.2 A php library to manipulate Swagger specifications
ezyang/htmlpurifier v4.13.0 Standards compliant HTML filter written in PHP
fakerphp/faker v1.15.0 Faker is a PHP library that generates fake data for you.
felixfbecker/advanced-json-rpc v3.2.1 A more advanced JSONRPC implementation
felixfbecker/language-server-protocol 1.5.1 PHP classes for the Language Server Protocol
fig/link-util 1.1.2 Common utility implementations for HTTP links
firebase/php-jwt v5.4.0 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current ...
flagception/flagception 1.7.0 Feature toggle on steroids.
flagception/flagception-bundle 3.6.0 Feature toggle bundle on steroids.
fourlabs/xero-bundle dev-master 8abc644 Symfony bundle wrapping the XeroPHP library
friendsofsymfony/elastica-bundle dev-master 26a742b Elasticsearch PHP integration for your Symfony2 project using Elastica
friendsofsymfony/http-cache 2.10.1 Tools to manage HTTP caching proxies with PHP
friendsofsymfony/http-cache-bundle 2.11.1 Set path based HTTP cache headers and send invalidation requests to your HTTP cache
friendsofsymfony/jsrouting-bundle 2.7.0 A pretty nice way to expose your Symfony2 routing to client applications.
friendsofsymfony/rest-bundle 2.8.6 This Bundle provides various tools to rapidly develop RESTful API's with Symfony
friendsofsymfony/user-bundle v2.1.2 Symfony FOSUserBundle
gburtini/distributions dev-master 2e66500 PHP implementation of a number of statistical probability distributions: normal, beta, gamma, etc.
gedmo/doctrine-extensions v2.4.42 Doctrine2 behavioral extensions
giggsey/libphonenumber-for-php 8.12.29 PHP Port of Google's libphonenumber
giggsey/locale 1.9 Locale functions required by libphonenumber-for-php
google/apiclient v2.11.0 Client library for Google APIs
google/apiclient-services v0.213.0 Client library for Google APIs
google/auth v1.18.0 Google Auth Library for PHP
google/cloud-bigquery v1.22.2 BigQuery Client for PHP
google/cloud-core v1.43.0 Google Cloud PHP shared dependency, providing functionality useful to all components.
google/cloud-pubsub v1.34.0 Cloud PubSub Client for PHP
google/common-protos 1.3.1 Google API Common Protos for PHP
google/gax v1.9.0 Google API Core for PHP
google/grpc-gcp 0.1.5 gRPC GCP library for channel management
google/protobuf v3.18.0 proto library for PHP
google/recaptcha 1.2.4 Client library for reCAPTCHA, a free service that protects websites from spam and abuse.
grpc/grpc 1.39.0 gRPC library for PHP
gushphp/to-inline-style-email-bundle 1.5.2 A Symfony2 bundle for using the CssToInlineStyles translator by tijsverkoyen
guzzlehttp/guzzle 6.5.5 Guzzle is a PHP HTTP client library
guzzlehttp/oauth-subscriber 0.3.0 Guzzle OAuth 1.0 subscriber
guzzlehttp/promises 1.4.1 Guzzle promises library
guzzlehttp/psr7 1.8.2 PSR-7 message implementation that also provides common utility methods
haydenpierce/class-finder 0.4.3 A library that can provide of a list of classes in a given namespace
http-interop/http-factory-guzzle 1.2.0 An HTTP Factory using Guzzle PSR7
jakeasmith/http_build_url 1.0.1 Provides functionality for http_build_url() to environments without pecl_http.
jdorn/sql-formatter v1.2.17 a PHP SQL highlighting library
jms/metadata 1.7.0 Class/method/property metadata management in PHP
jms/parser-lib 1.0.0 A library for easily creating recursive-descent parsers.
jms/serializer 1.14.1 Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML.
jms/serializer-bundle 2.4.4 Allows you to easily serialize, and deserialize data of any complexity
jms/translation-bundle 1.6.0 Puts the Symfony Translation Component on steroids
ju1ius/webpack-assets-bundle dev-master 67bd033 Integrates Webpack into Symfony
justinrainbow/json-schema 5.2.11 A library to validate a json schema.
knplabs/gaufrette dev-master 60ab171 PHP library that provides a filesystem abstraction layer
knplabs/knp-gaufrette-bundle dev-master cdfae2c Allows to easily use the Gaufrette library in a Symfony project
knpuniversity/oauth2-client-bundle v1.34.0 Integration with league/oauth2-client to provide services
kraken-io/kraken-php 1.6 Official Kraken.io SDK
larsnieuwenhuizen/trustpilot dev-master 070b9d7 PHP library for communication with the Trustpilot API
lcobucci/jwt 3.4.5 A simple library to work with JSON Web Token and JSON Web Signature
league/iso3166 3.0.0 ISO 3166-1 PHP Library
league/oauth2-client 2.6.0 OAuth 2.0 Client Library
league/oauth2-google 4.0.0 Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client
liip/test-fixtures-bundle 1.12.0 This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony a...
maennchen/zipstream-php 2.1.0 ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the...
markbaker/complex 2.0.3 PHP Class for working with complex numbers
markbaker/matrix 2.1.3 PHP Class for working with matrices
mention-me/emarsys dev-master c2bdc8e Emarsys RestFull API client
mention-me/liform v0.14.0 Library to transform Symfony Forms into Json Schema. Extends Limenius/liform.
mention-me/liform-bundle v0.14.0 Bundle for Liform: Transform Symfony Forms into Json Schema. Extends Limenius/liform-bundle.
mention-me/riverline-dynamodb 3.0.0 Fork of mlarose/dynamodb
monolog/monolog 1.26.1 Sends your logs to files, sockets, inboxes, databases and various web services
mopa/bootstrap-bundle dev-v2.3.x-symfony4.4 c19678e Easy integration of twitters bootstrap into symfony2
mopa/composer-bridge v1.3.1 Symfony2 Composer Bridge
mtdowling/jmespath.php 2.6.1 Declaratively specify how to extract elements from a JSON document
myclabs/deep-copy 1.10.2 Create deep copies (clones) of your objects
myclabs/php-enum 1.8.3 PHP Enum implementation
nelmio/alice v3.8.2 Expressive fixtures generator
nelmio/api-doc-bundle v3.9.1 Generates documentation for your REST API from annotations
nelmio/cors-bundle 1.5.6 Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony2 application
nelmio/security-bundle v2.10.3 Extra security-related features for Symfony: signed/encrypted cookies, HTTPS/SSL/HSTS handling, co...
nesbot/carbon 2.53.1 An API extension for DateTime that supports 281 different languages.
netresearch/jsonmapper v4.0.0 Map nested JSON structures onto PHP classes
nikic/php-parser v4.12.0 A PHP parser written in PHP
notfloran/mjml-bundle v3.5.1 Symfony bundle for MJML
ocramius/proxy-manager 2.2.3 A library providing utilities to generate, instantiate and generally operate with Object Proxies
odolbeau/phone-number-bundle v3.4.2 Integrates libphonenumber into your Symfony application
onurb/excel-bundle 1.0.0 Symfony Bundle to read or write Excel file (including pdf, xlsx, odt), using phpoffice/phpspreadsh...
openlss/lib-array2xml 1.0.0 Array2XML conversion library credit to lalit.org
opis/json-schema 1.1.0 Json Schema Validator
overblog/graphql-bundle v0.12.11 This bundle provides tools to build a GraphQL server in your Symfony App.
pagerfanta/pagerfanta v2.7.2 Pagination for PHP
paragonie/constant_time_encoding v2.4.0 Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)
paragonie/random_compat v2.0.20 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phar-io/manifest 2.0.3 Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version 3.1.0 Library for handling version information and constraints
php-http/client-common 2.4.0 Common HTTP Client implementations and tools for HTTPlug
php-http/discovery 1.14.1 Finds installed HTTPlug implementations and PSR-7 message factories
php-http/guzzle6-adapter v2.0.2 Guzzle 6 HTTP Adapter
php-http/httplug 2.2.0 HTTPlug, the HTTP client abstraction for PHP
php-http/message 1.12.0 HTTP Message related tools
php-http/message-factory v1.0.2 Factory interfaces for PSR-7 HTTP Message
php-http/promise 1.1.0 Promise used for asynchronous HTTP requests
php-parallel-lint/php-console-color v0.3
php-parallel-lint/php-console-highlighter v0.5 Highlight PHP code in terminal
php-parallel-lint/php-parallel-lint v1.3.1 This tool check syntax of PHP files about 20x faster than serial check.
phpcollection/phpcollection 0.5.0 General-Purpose Collection Library for PHP
phpdocumentor/reflection-common 2.2.0 Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock 5.2.2 With this component, a library can provide support for annotations via DocBlocks or otherwise retr...
phpdocumentor/type-resolver 1.4.0 A PSR-5 based resolver of Class names, Types and Structural Element Names
phpoffice/phpspreadsheet 1.18.0 PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
phpoption/phpoption 1.7.5 Option Type for PHP
phpseclib/phpseclib 3.0.10 PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
phpspec/prophecy 1.13.0 Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage 9.2.6 Library that provides collection, processing, and rendering functionality for PHP code coverage in...
phpunit/php-file-iterator 3.0.5 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker 3.1.1 Invoke callables with a timeout
phpunit/php-text-template 2.0.4 Simple template engine.
phpunit/php-timer 5.0.3 Utility class for timing
phpunit/phpunit 9.5.9 The PHP Unit Testing framework.
pixel418/markdownify dev-master d576715 The HTML to Markdown converter for PHP
posthog/posthog-php 2.0.5 PostHog PHP Library
psalm/plugin-phpunit 0.16.1 Psalm plugin for PHPUnit
psalm/plugin-symfony v3.0.0 Psalm Plugin for Symfony
psr/cache 1.0.1 Common interface for caching libraries
psr/container 1.1.1 Common Container Interface (PHP FIG PSR-11)
psr/http-client 1.0.1 Common interface for HTTP clients
psr/http-factory 1.0.1 Common interfaces for PSR-7 HTTP message factories
psr/http-message 1.0.1 Common interface for HTTP messages
psr/link 1.0.0 Common interfaces for HTTP links
psr/log 1.1.4 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.
ramsey/collection 1.2.1 A PHP library for representing and manipulating collections.
ramsey/uuid 4.2.1 A PHP library for generating and working with universally unique identifiers (UUIDs).
redcode/currency-rate 0.2.4 Useful library for fetching currency rates from cbr and ecb providers
redcode/currency-rate-bundle 0.2.3 Symfony2 currency rate bundle, allows convert currencies and load rates via cbr or ecb provider
rize/uri-template 0.3.3 PHP URI Template (RFC 6570) supports both expansion & extraction
ruflin/elastica 2.3.3 Elasticsearch Client
sailthru/sailthru-php5-client 1.2.4 Sailthru PHP5 Client
sebastian/cli-parser 1.0.1 Library for parsing CLI options
sebastian/code-unit 1.0.8 Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup 2.0.3 Looks up which function or method a line of code belongs to
sebastian/comparator 4.0.6 Provides the functionality to compare PHP values for equality
sebastian/complexity 2.0.2 Library for calculating the complexity of PHP code units
sebastian/diff 4.0.4 Diff implementation
sebastian/environment 5.1.3 Provides functionality to handle HHVM/PHP environments
sebastian/exporter 4.0.3 Provides the functionality to export PHP variables for visualization
sebastian/global-state 5.0.3 Snapshotting of global state
sebastian/lines-of-code 1.0.3 Library for counting the lines of code in PHP source code
sebastian/object-enumerator 4.0.4 Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector 2.0.4 Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context 4.0.4 Provides functionality to recursively process PHP variables
sebastian/resource-operations 3.0.3 Provides a list of PHP built-in functions that operate on resources
sebastian/type 2.3.4 Collection of value objects that represent the types of the PHP type system
sebastian/version 3.0.2 Library that helps with managing the version number of Git-hosted PHP projects
sensio/framework-extra-bundle v5.4.1 This bundle provides a way to configure your controllers with annotations
simshaun/recurr v5.0.0 PHP library for working with recurrence rules
sonata-project/google-authenticator 2.3.1 Library to integrate Google Authenticator into a PHP project
spatie/macroable 1.0.1 A trait to dynamically add methods to a class
spatie/ssl-certificate 1.21.0 A class to easily query the properties of an ssl certificate
squizlabs/php_codesniffer 3.6.0 PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of...
staabm/annotate-pull-request-from-checkstyle 1.6.0
stof/doctrine-extensions-bundle v1.3.0 Integration of the gedmo/doctrine-extensions with Symfony2
swiftmailer/swiftmailer v6.2.7 Swiftmailer, free feature-rich PHP mailer
symfony/deprecation-contracts v2.4.0 A generic function and convention to trigger deprecation notices
symfony/monolog-bundle v3.6.0 Symfony MonologBundle
symfony/phpunit-bridge v5.3.7 Provides utilities for PHPUnit, especially user deprecation notices management
symfony/polyfill-apcu v1.23.0 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-ctype v1.23.0 Symfony polyfill for ctype functions
symfony/polyfill-iconv v1.23.0 Symfony polyfill for the Iconv extension
symfony/polyfill-intl-icu v1.23.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn v1.23.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer v1.23.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring v1.23.1 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56 v1.20.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70 v1.20.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72 v1.23.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php80 v1.23.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81 v1.23.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/service-contracts v2.4.0 Generic abstractions related to writing services
symfony/swiftmailer-bundle v3.3.1 Symfony SwiftmailerBundle
symfony/symfony v3.4.49 The Symfony PHP framework
symfony/translation-contracts v2.4.0 Generic abstractions related to translation
theofidry/alice-data-fixtures 1.4.0 Nelmio alice extension to persist the loaded fixtures.
theseer/tokenizer 1.2.1 A small library for converting tokenized PHP source code into XML and potentially other formats
tijsverkoyen/css-to-inline-styles 2.2.3 CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files wi...
twbs/bootstrap v2.3.2 Sleek, intuitive, and powerful front-end framework for faster and easier web development.
twig/extensions v1.5.4 Common additional features for Twig that do not directly belong in core
twig/twig v2.14.7 Twig, the flexible, fast, and secure template language for PHP
ua-parser/uap-php v3.9.14 A multi-language port of Browserscope's user agent parser.
vich/uploader-bundle 1.8.8 Ease file uploads attached to entities
vimeo/psalm 4.10.0 A static analysis tool for finding errors in PHP applications
webmozart/assert 1.10.0 Assertions to validate method input/output with nice error messages.
webmozart/path-util 2.3.0 A robust cross-platform utility for normalizing, comparing and modifying file paths.
webonyx/graphql-php v0.13.9 A PHP port of GraphQL reference implementation
weirdan/doctrine-psalm-plugin 1.1.0 Stubs to let Psalm understand Doctrine better
willdurand/jsonp-callback-validator v1.1.0 JSONP callback validator.
willdurand/negotiation 3.0.0 Content Negotiation tools for PHP provided as a standalone library.
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
zircote/swagger-php 2.1.0 Swagger-PHP - Generate interactive documentation for your RESTful API using phpdoc annotations
Summary
assertStringNotContainsString doesn't behave as expected and the result is confusing since it changes the actual compared strings in the case where certain keywords exist.
Current behavior
If you use
assertStringNotContainsString
in a test case to try to assert that a needle is not contained within a haystack and that needle (and the haystack) contains the word 'contains' (and possibly other words in thenegate
method of theLogicalNot
class) then the assertion fails AND the failure message is confusing.In the test scenario shown below, the result is:
The failure message contains the original string with
contains
replaced bydoes not contain
which makes debugging what's wrong rather confusing.How to reproduce
Run this test and see the current behaviour above.
Expected behavior
Test passes (because the assertion should return true). In a failure case, the error response should contain the ACTUAL content - not content which has had specific words modified.
Composer output: