Repository navigation
Test reported as being useless when only verifying mock expectations #6671
Description
What are you trying to achieve?
In my tests I'm verifying that the unit under test calls another service. I mocked the service and added the expectations for the method which needs to be called. The test does not contain any other assertions beside the expectation of calling the service This works as expected, but the test keep saying that it has useless tests with the message "This test did not perform any assertions".
When I disable the setting report_useless_tests the message is (obviously) gone, but that is not what I want.
The report_useless_tests setting enables the same functionality as PHPUnit does with it useless tests. The example with Mockery works as expected when running from plain PHPUnit.
I already created a fix for this, will create a PR in some minutes.
What do you get instead?
Console output
Codeception PHP Testing Framework v5.0.10 https://helpukrainewin.org
[Seed] 1147290330
Tests.Unit Tests (2) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Mockery
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
U CalculatorTest: Replace last result using mockery(0.02s)
U CalculatorTest: Replace last result using codeception make(0.01s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 00:00.068, Memory: 6.00 MB
There were 2 useless tests:
1) CalculatorTest: Replace last result using mockery
Test tests/Unit/Service/CalculatorTest.php:testReplaceLastResultUsingMockery
This test did not perform any assertions
2) CalculatorTest: Replace last result using codeception make
Test tests/Unit/Service/CalculatorTest.php:testReplaceLastResultUsingCodeceptionMake
This test did not perform any assertions
OK, but incomplete, skipped, or useless tests!
Tests: 2, Assertions: 0, Useless: 2.Test source code
<?php
declare(strict_types=1);
namespace Tests\Unit\Service;
use App\Service\Calculator;
use App\Service\Memory\MemoryInterface;
use Codeception\MockeryModule\Test;
use Codeception\Stub\Expected;
use Mockery;
class CalculatorTest extends Test
{
public function testReplaceLastResultUsingMockery(): void
{
$memory = Mockery::mock(MemoryInterface::class);
$memory->shouldReceive('overwriteLastResult')
->once()
->with(12);
$calculator = new Calculator($memory);
$calculator->replaceLastResult(12);
}
public function testReplaceLastResultUsingCodeceptionMake(): void
{
$memory = $this->makeEmpty(
MemoryInterface::class,
[
'overwriteLastResult' => Expected::once('12'),
]
);
$calculator = new Calculator($memory);
$calculator->replaceLastResult(12);
}
}Details
- Codeception version:
- PHP Version: 8.1.16
- Operating System: Debian 11 (Bullseye)
- Installation type: Composer
- List of installed packages (
composer show)-
Expand to view
behat/gherkin v4.9.0 Gherkin DSL parser for PHP brick/math 0.11.0 Arbitrary-precision arithmetic library codeception/codeception 5.0.10 BDD-style testing framework codeception/lib-asserts 2.1.0 Assertion methods used by Codeception core and Asserts module codeception/lib-innerbrowser 3.1.3 Parent library for all Codeception framework modules and PhpBrowser codeception/lib-web 1.0.2 Library containing files used by module-webdriver and lib-innerbrowser or module-phpbrowser codeception/mockery-module 0.5.0 Mockery Module for Codeception codeception/module-asserts 3.0.0 Codeception module containing various assertions codeception/module-laravel 3.1.1 Codeception module for Laravel framework codeception/module-phpbrowser 3.0.0 Codeception module for testing web application over HTTP codeception/stub 4.1.0 Flexible Stub wrapper for PHPUnit's Mock Builder dflydev/dot-access-data v3.0.2 Given a deep data structure, access data by dot notation. doctrine/inflector 2.0.6 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words. doctrine/instantiator 2.0.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer 3.0.0 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers. dragonmantank/cron-expression v3.3.2 CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due egulias/email-validator 4.0.1 A library for validating emails against several RFCs fakerphp/faker v1.22.0 Faker is a PHP library that generates fake data for you. filp/whoops 2.15.2 php error handling for cool kids fruitcake/php-cors v1.2.0 Cross-origin resource sharing library for the Symfony HttpFoundation graham-campbell/result-type v1.1.1 An Implementation Of The Result Type guzzlehttp/guzzle 7.7.0 Guzzle is a PHP HTTP client library guzzlehttp/promises 2.0.0 Guzzle promises library guzzlehttp/psr7 2.5.0 PSR-7 message implementation that also provides common utility methods guzzlehttp/uri-template v1.0.1 A polyfill class for uri_template of PHP hamcrest/hamcrest-php v2.0.1 This is the PHP port of Hamcrest Matchers laravel/framework v9.52.7 The Laravel Framework. laravel/pint v1.10.0 An opinionated code formatter for PHP. laravel/sail v1.22.0 Docker files for running a basic Laravel application. laravel/sanctum v3.2.5 Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs. laravel/serializable-closure v1.3.0 Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP. laravel/tinker v2.8.1 Powerful REPL for the Laravel framework. league/commonmark 2.4.0 Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM) league/config v1.2.0 Define configuration arrays with strict schemas and access values with dot notation league/flysystem 3.15.1 File storage abstraction for PHP league/flysystem-local 3.15.0 Local filesystem adapter for Flysystem. league/mime-type-detection 1.11.0 Mime-type detection for Flysystem masterminds/html5 2.8.0 An HTML5 parser and serializer. mockery/mockery 1.5.1 Mockery is a simple yet flexible PHP mock object framework monolog/monolog 2.9.1 Sends your logs to files, sockets, inboxes, databases and various web services myclabs/deep-copy 1.11.1 Create deep copies (clones) of your objects nesbot/carbon 2.66.0 An API extension for DateTime that supports 281 different languages. nette/schema v1.2.3 📐 Nette Schema: validating data structures against a given Schema. nette/utils v4.0.0 🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc. nikic/php-parser v4.15.5 A PHP parser written in PHP nunomaduro/collision v6.4.0 Cli error handling for console/command-line PHP applications. nunomaduro/termwind v1.15.1 Its like Tailwind CSS, but for the console. phar-io/manifest 2.0.3 Component for reading phar.io manifest information from a PHP Archive (PHAR) phar-io/version 3.2.1 Library for handling version information and constraints phpoption/phpoption 1.9.1 Option Type for PHP phpunit/php-code-coverage 9.2.26 Library that provides collection, processing, and rendering functionality for PHP code coverage information. phpunit/php-file-iterator 3.0.6 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.6.8 The PHP Unit Testing framework. psr/container 2.0.2 Common Container Interface (PHP FIG PSR-11) psr/event-dispatcher 1.0.0 Standard interfaces for event handling. psr/http-client 1.0.2 Common interface for HTTP clients psr/http-factory 1.0.2 Common interfaces for PSR-7 HTTP message factories psr/http-message 2.0 Common interface for HTTP messages psr/log 3.0.0 Common interface for logging libraries psr/simple-cache 3.0.0 Common interfaces for simple caching psy/psysh v0.11.18 An interactive shell for modern PHP. ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. ramsey/collection 2.0.0 A PHP library for representing and manipulating collections. ramsey/uuid 4.7.4 A PHP library for generating and working with universally unique identifiers (UUIDs). 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.8 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.5 Diff implementation sebastian/environment 5.1.5 Provides functionality to handle HHVM/PHP environments sebastian/exporter 4.0.5 Provides the functionality to export PHP variables for visualization sebastian/global-state 5.0.5 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.5 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 3.2.1 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 spatie/backtrace 1.4.0 A better backtrace spatie/flare-client-php 1.3.6 Send PHP errors to Flare spatie/ignition 1.7.0 A beautiful error page for PHP applications. spatie/laravel-ignition 1.6.4 A beautiful error page for Laravel applications. symfony/browser-kit v6.2.7 Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically symfony/console v6.2.10 Eases the creation of beautiful and testable command line interfaces symfony/css-selector v6.2.7 Converts CSS selectors to XPath expressions symfony/deprecation-contracts v3.2.1 A generic function and convention to trigger deprecation notices symfony/dom-crawler v6.2.9 Eases DOM navigation for HTML and XML documents symfony/error-handler v6.2.10 Provides tools to manage errors and ease debugging PHP code symfony/event-dispatcher v6.2.8 Provides tools that allow your application components to communicate with each other by dispatching events and listening to them symfony/event-dispatcher-contracts v3.2.1 Generic abstractions related to dispatching event symfony/finder v6.2.7 Finds files and directories via an intuitive fluent interface symfony/http-foundation v6.2.10 Defines an object-oriented layer for the HTTP specification symfony/http-kernel v6.2.10 Provides a structured process for converting a Request into a Response symfony/mailer v6.2.8 Helps sending emails symfony/mime v6.2.10 Allows manipulating MIME messages symfony/polyfill-ctype v1.27.0 Symfony polyfill for ctype functions symfony/polyfill-intl-grapheme v1.27.0 Symfony polyfill for intl's grapheme_* functions symfony/polyfill-intl-idn v1.27.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-intl-normalizer v1.27.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.27.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php72 v1.27.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions symfony/polyfill-php80 v1.27.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions symfony/polyfill-uuid v1.27.0 Symfony polyfill for uuid functions symfony/process v6.2.10 Executes commands in sub-processes symfony/routing v6.2.8 Maps an HTTP request to a set of configuration variables symfony/service-contracts v3.2.1 Generic abstractions related to writing services symfony/string v6.2.8 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way symfony/translation v6.2.8 Provides tools to internationalize your application symfony/translation-contracts v3.2.1 Generic abstractions related to translation symfony/uid v6.2.7 Provides an object-oriented API to generate and represent UIDs symfony/var-dumper v6.2.10 Provides mechanisms for walking through any arbitrary PHP variable symfony/yaml v6.2.10 Loads and dumps YAML files 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.6 CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails. vlucas/phpdotenv v5.5.0 Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically. voku/portable-ascii 2.0.1 Portable ASCII library - performance optimized (ascii) string functions for php. webmozart/assert 1.11.0 Assertions to validate method input/output with nice error messages.
-
- Suite configuration:
actor: UnitTester
suite_namespace: Tests\Unit
modules:
enabled:
- Mockery- Codeception configuration:
namespace: Tests
support_namespace: Support
paths:
tests: tests
output: tests/_output
support: tests/Support
data: tests/Support/Data
settings:
shuffle: true
lint: true
report_useless_tests: true
Activity