phpunit
phpunit copied to clipboard
Can't run SINGLE test files with namespace in class name
Q | A |
---|---|
PHPUnit version | 9.5.9 |
PHP version | 7.4.23 |
Installation Method | Composer |
Summary
Our app has a mix of real namespaces and an older way of namespacing using underscores.
Example, the path to this file is tests/Thing/ThingTest.php
<?php
class Thing_ThingTest extends PHPUnit\Framework\TestCase
{
public function testThisThing()
{
$this->assertTrue(true);
}
}
Current behavior
In phpunit
9.5.9
this happens when trying to run this test by its path.
deploy/vendor/bin/phpunit ./tests/Thing/ThingTest.php
Class 'ThingTest' could not be found in '/home/me/project_folder/deploy/tests/Thing/ThingTest.php'.
But in phpunit
8.5.22
it works
deploy/vendor/bin/phpunit ./tests/Thing/ThingTest.php
PHPUnit 8.5.22 by Sebastian Bergmann and contributors.
Runtime: PHP 7.4.23 with Xdebug 3.0.3
Configuration: /home/me/project_folder/phpunit.xml.dist
. 1 / 1 (100%)
Time: 740 ms, Memory: 32.00 MB
OK (1 test, 1 assertion)
How to reproduce
mkdir phpunit_test
cd phpunit_test
composer require phpunit/phpunit:^9.5 --dev
mkdir Thing
Edit composer.json
to look like this
{
"autoload-dev": {
"psr-0": {
"": "./"
}
},
"require-dev": {
"phpunit/phpunit": "^9.5"
}
}
Create Thing/ThingTest.php
<?php
class Thing_ThingTest extends PHPUnit\Framework\TestCase
{
public function testThisThing()
{
$this->assertTrue(true);
}
}
Run the test
vendor/bin/phpunit Thing/ThingTest.php
Class 'ThingTest' could not be found in '/Users/jtowe/Documents/Projects/phpunit_test/Thing/ThingTest.php'.
Revert back to 8.5 and see that it works
composer require phpunit/phpunit:^8.5 --dev -W
vendor/bin/phpunit Thing/ThingTest.php
PHPUnit 8.5.22 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 14 ms, Memory: 4.00 MB
OK (1 test, 1 assertion)
NOTE: This only seems to happen when I try to run the test by itself. If I make a phpunit.xml
of
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="./vendor/autoload.php"
>
<testsuites>
<testsuite name="Test Suite">
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>
And run all the tests vendor/bin/phpunit
it works
PHPUnit 9.5.11 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 00:00.001, Memory: 6.00 MB
OK (1 test, 1 assertion)
Expected behavior
I'm not sure what's happening but there's a high chance i'm just doing something wrong. We have LOTS of tests namespaced using underscores so if the answer is to namespace them all using Namespace
I may have to revert back to 8.5
for now. I think i'd just like to understand what's changed to make this happen so I can revert or fix it.
composer info | sort
composer info | sort 1 ✘ 12:55:47 PM
doctrine/instantiator 1.4.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
myclabs/deep-copy 1.10.2 Create deep copies (clones) of your objects
nikic/php-parser v4.13.2 A PHP parser written in PHP
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
phpdocumentor/reflection-common 2.2.0 Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock 5.3.0 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that ...
phpdocumentor/type-resolver 1.6.0 A PSR-5 based resolver of Class names, Types and Structural Element Names
phpspec/prophecy v1.15.0 Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage 9.2.10 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.5.11 The PHP Unit Testing framework.
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.4 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
symfony/polyfill-ctype v1.24.0 Symfony polyfill for ctype functions
theseer/tokenizer 1.2.1 A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert 1.10.0 Assertions to validate method input/output with nice error messages.
Tested again in 9.5.20 and it still happens.
Tested in 9.5.21 and it still happens.
This should have been fixed by #5021.